This king-of-the-hill game is a strategy game in which you must throw around a water balloon and avoid getting splashed by water. The goal is to obtain the most points. You will be given a map of the field and the location of the water balloon. You can either return that you want to hit the water balloon (if you are close enough) in a certain direction or that you want to move in a certain direction.
Specifically:
The water balloon will start at (0, 0)
30 units high and drop. If the water balloon hits the ground, a player will randomly be chosen to lose 4 points, with more weight given to those who are closer to the balloon. In addition, the player who last hit the balloon will earn 3 points. Therefore, if you hit the balloon straight down, you will most likely lose 1 point.
You will write a class that extends Player
. You are required to implement the constructor. The constructor will look like:
public Player1() {
super(/* Some numbers */ 3, 3, 4)
}
These numbers are double
s. The first number represents the player's speed, the second represents strength, and the third represents luck. The numbers must add up to 10 or less and no number may be less than or equal to zero.
Second, you must implement the move
method. This is an example move
method:
@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));
}
}
There are a number of important things here. First, notice that the field is passed as a Map<Player, Point2D>
. The field is infinite - there is no limit to how far you can go. It is not a 2-dimensional array or anything like that. In addition, this means that you will have non-integer coordinates as your location. This is perfectly okay.
Another consequence is that players and the balloon may overlap. In fact, two players may be in the exact same location!
The balloon has a certain velocity and direction. In general, it will fall at a rate of 3 units/step. It also moves in an x
direction and y
direction. When you return a Hit
, you pass the x, y, and z directions that you are pushing the balloon. You cannot hit a balloon whose height is greater than 10 or whose distance from you (only on two dimensions) is greater than 4. In addition, if it is true that x^2 + y^2 + z^2 > s^2
where s
is your strength, and x
, y
, and z
are the directions that you hit, your action is discarded. The force of your hit is amplified by a random number between 0
and luck
(which means it could go down if your luck is low).
Similarly, you can return a Movement
with the x
and y
coordinates that you are moving (note that you cannot jump in the air). If x^2 + y^2 > s^2
where s
is your speed, your action is discarded.
If the water balloon hits the ground then a random player is chosen, with more weight given to those who are closest -- but less weight to those who have more luck. The player that is chosen loses 4 points.
Controller: https://github.com/prakol16/water-balloon-wars/tree/master
The game lasts 1000 steps. At the end, there will be a file called log.out
. Copy and paste the data into this fiddle to view the game: https://jsfiddle.net/prankol57/s2x776dt/embedded/result/
Or even better, view it in 3D: http://www.brianmacintosh.com/waterballoonwars (thanks to BMac)
The player with the highest sum of scores after 100 (may be more, but not less) games wins.
If you wish to submit a solution, you may want to read the really specific details at https://github.com/prakol16/water-balloon-wars/tree/master.
Edit 3/8:
These are the final scores for now (1000 iterations, without including players 1 and 2). If you edit your post, you can comment, and I will redo the scores:
{
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
}
The winner was Weakling
with an average of 39 points. 2nd place was Repeller
with 21 points.
speed
andstrength
in the Player constructor. \$\endgroup\$dirX
,dirY
, anddirZ
(amplified by your luck) are simply added to the velocities of the balloon. If multiple people hit it (somewhat unlikely) then the player who might get three points is decided on luck (see specific details) \$\endgroup\$