这个山中之王的游戏是一个战略游戏,在这个游戏中,你必须抛出一个水球,避免被水溅到水里。目标是获得最多的分数。你将得到一张田野地图和水球的位置。您可以返回您想要击中水球(如果您足够近)在一个特定的方向,或您想要移动到一个特定的方向。
具体来说:水球将在(0, 0) 30单位的高度开始下降。如果水球落地,玩家会被随机选择丢4分,更多的重量给那些离气球更近的人。此外,最后一次击中气球的球员将获得3分。因此,如果你直接击中气球,你很可能会损失1分。
您将编写一个扩展Player的类。您需要实现构造函数。构造函数如下所示:
public Player1() {
super(/* Some numbers */ 3, 3, 4)
}这些数字是doubles。第一个数字代表球员的速度,第二个代表力量,第三个代表运气。数字加起来必须等于或小于10,任何数字不得小于或等于零。
其次,必须实现move方法。这是一个示例move方法:
@Override
protected Action move(Map<Player, Point2D> map, Balloon b) {
// Get my own location
Point2D myself = map.get(this);
// If I'm close enough to the balloon
// then hit the balloon
if (myself.distanceSq(b.getLocation()) <= 16) {
double d = (r.nextDouble() - 0.5) * 3;
// Random y direction, z direction is what's left
return new Hit(0, d, Math.sqrt(9 - d*d));
} else {
double diffX = b.getLocation().getX() - myself.getX(),
diffY = b.getLocation().getY() - myself.getY();
// Move towards the balloon
return new Movement(Math.signum(diffX)*3/Math.sqrt(2), Math.signum(diffY)*3/Math.sqrt(2));
}
}这里有很多重要的事情。首先,注意字段是作为Map<Player, Point2D>传递的。场是无限的--你能走多远是没有限制的。它不是二维数组或类似的东西。此外,这意味着您将有非整数坐标作为您的位置.这完全没问题。
另一个后果是,球员和气球可能重叠。事实上,两个玩家可能在完全相同的位置!
气球有一定的速度和方向。一般来说,它将以3单位/步的速度下降。它还向x方向和y方向移动。当您返回一个Hit时,您将传递您正在推动气球的x、y和z方向。如果气球的高度大于10,或者距离你的距离(仅在二维上)大于4,那么你就不能撞上气球。此外,如果x^2 + y^2 + z^2 > s^2 s是你的力量,x、y和z是你击中的方向,那么你的动作就被抛弃了。0和luck之间的随机数放大了你的命中力(这意味着如果运气不好,它可能会下降)。
类似地,您可以返回一个Movement,其中包含移动的x和y坐标(请注意,您不能跳到空中)。如果x^2 + y^2 > s^2中s是您的速度,则您的操作将被丢弃。
如果水球击中地面,那么随机选择一个玩家,给那些最接近的人更多的重量--但对那些运气更好的人来说,更少的重量。被选中的球员损失4分。
控制器:https://github.com/prakol16/water-balloon-wars/tree/master
游戏持续1000步。最后,将有一个名为log.out的文件。将数据复制并粘贴到这个小提琴中,以查看游戏:https://jsfiddle.net/prankol57/s2x776dt/embedded/result/
或者更好的是,在3D中查看它:http://www.brianmacintosh.com/waterballoonwars (感谢BMac)
得分最高的玩家在100场比赛之后(可能更多,但不是更少)获胜。
如果您希望提交解决方案,您可能希望在https://github.com/prakol16/water-balloon-wars/tree/master上阅读真正具体的详细信息。
这些是现在的最后分数(1000次迭代,不包括玩家1和2)。如果你编辑你的帖子,你可以评论,我会重做分数:
{
class players.BackAndForth=-75.343,
class players.Hydrophobe=-0.800,
class players.KeepAway=-53.064,
class players.Weakling=39.432,
class players.Repeller=21.238,
class players.LuckyLoser=-30.055,
class players.AngryPenguin=-49.310
}获胜者是Weakling,平均得分39分。第二名是Repeller,得分为21分。
发布于 2015-02-27 08:49:02
这个机器人试图靠近气球,直到它的高度太低,并试图逃跑。
package players;
import java.awt.geom.Point2D;
import java.util.Map;
import balloon.Action;
import balloon.Balloon;
import balloon.Player;
import balloon.Action.Hit;
import balloon.Action.Movement;
public class BackAndForth extends Player {
static int round = 0;
static int speed = 3;
static int strength = 1;
static boolean hit = false;
static double previousHeight = 30.0;
public BackAndForth() {
super(speed, strength, 10 - speed - strength);
}
@Override
protected Action move(Map<Player, Point2D> map, Balloon b) {
round++;
Point2D me = map.get(this);
Point2D balloon = b.getLocation();
double distanceX = balloon.getX() - me.getX();
double distanceY = balloon.getY() - me.getY();
double distance = Math.sqrt(Math.pow(distanceX, 2) + Math.pow(distanceY, 2));
double maxX = speed * distanceX / distance;
double maxY = speed * distanceY / distance;
if (previousHeight < b.getHeight())
hit = false;
if (hit || b.getHeight() < 3) {
previousHeight = b.getHeight();
return new Movement(-maxX, -maxY);
} else {
if (distance < 4 && b.getHeight() < 10) {
hit = true;
return new Hit(0, 0, strength);
} else {
if (Math.pow(distance, 2) <= Math.pow(speed, 2)) {
return new Movement(distanceX, distanceY);
} else {
return new Movement(maxX, maxY);
}
}
}
}
}发布于 2015-02-28 08:48:44
我希望这是可以的,因为它实际上不是一个条目。我真的很喜欢视觉模拟器的想法,我想要创建自己的,这将使它更容易看到所有东西一次(完整的3D)。
2/28 9:06AM PST:使用以下控件更新
3/4 8:47 a PST:使用滑块进行更新以提高模拟速度,并使新游戏在不刷新页面的情况下实际工作(使用Ctrl-F5重新加载缓存脚本)
在线ThreeJS可视化器

发布于 2015-02-27 11:35:43
这只企鹅很生气,因为他不能飞到气球上,所以他试图把气球撞到站在他周围的人的脸上。
package players;
import java.awt.geom.Point2D;
import java.util.Map;
import java.util.Map.Entry;
import balloon.Action;
import balloon.Action.Hit;
import balloon.Action.Movement;
import balloon.Balloon;
import balloon.Player;
public class AngryPenguin extends Player {
private static final double HIT_Z = 3;
public AngryPenguin() {
super(4, 4, 2);
}
@Override
protected Action move(Map<Player, Point2D> map, Balloon balloon) {
Point2D myself = map.get(this);
double distanceX = balloon.getLocation().getX() - myself.getX();
double distanceY = balloon.getLocation().getY() - myself.getY();
double distance = Math.sqrt(Math.pow(distanceX, 2) + Math.pow(distanceY, 2));
if (balloon.getHeight() < 2) {
double[] xy = shrink(distanceX, distanceY, Math.pow(getSpeed(),2));
return new Movement(-xy[0], -xy[1]);
} else if (distance <= 4 && balloon.getHeight() <= 10) {
double lowestDistance = Double.MAX_VALUE;
Point2D nearestPlayerLoc = null;
for (Entry<Player, Point2D> e : map.entrySet()) {
if (e.getKey() != this) {
double d = e.getValue().distanceSq(myself);
if (d < lowestDistance) {
lowestDistance = d;
nearestPlayerLoc = e.getValue();
}
}
}
double dX = nearestPlayerLoc.getX() - myself.getX();
double dY = nearestPlayerLoc.getY() - myself.getY();
double d = Math.pow(getStrength() - HIT_Z, 2);
double[] xy = shrink(dX, dY, d);
return new Hit(xy[0], xy[1], -HIT_Z);
} else {
double[] xy = shrink(distanceX, distanceY, Math.pow(Math.min(getSpeed(), distance), 2));
return new Movement(xy[0], xy[1]);
}
}
private double[] shrink(double x, double y, double totalPow) {
double[] xy = new double[2];
double ratio = y == 0 ? 0 :
x == 0 ? 1 : Math.abs(x) / Math.abs(y);
if (ratio > 1)
ratio = 1/ratio;
xy[1] = totalPow * ratio;
xy[0] = totalPow - xy[1];
xy[0] = x < 0 ? -Math.sqrt(xy[0]) : Math.sqrt(xy[0]);
xy[1] = y < 0 ? -Math.sqrt(xy[1]) : Math.sqrt(xy[1]);
return xy;
}
}https://codegolf.stackexchange.com/questions/47125
复制相似问题