king-of-the-hill java
ToYour objective is to conquer the ants of the world ... or have the biggest army of ants. To do this, you start with a single queen. The queen can create worker ants by using food gathered by itself or other worker ants. Your worker ants can kill other ants by attacking them. In addition, a large enough group of worker ants can kill a queen ant thereby making that colony extinct. You win if you have the only queen left, or if the time is up[5] and you have the biggest army of ants.
The board will be a square with wraparound borders. The sizelength of each edge will beis determined by sqrt(1000*n)
[1]1 where n
is the number of competitors or starting queens. Before the game fierce battle for domination starts, 100*n
[2] pieces of food will be distributed randomlysemi-randomly on the board at the beginning of the game. n
queens, `1 for each player, will also randomly be randomly distributed on the board. Every cell on
1: n is the board will have a 24-bit pheromone which can be changed by your ants. A cell can contain multiple ants.number of starting players
Sight and Smell
Every antAnts are usually near-sighted and have somewhat short antenna. Because of this, ants in this simulation can only see ants and smell ants, food, and pheromonespheromone in its 3 by 3 neighborhood. They do not havecan also tell the ability to see outdifference between ants of this areadifferent species.
EveryBecause of limited brain space, every ant has a memory of up to 5 characters long. The starting memory for queens is null5 spaces.
Every ant is oriented in the same direction throughout the entire gamethat it last moved.[3] Queens start out oriented in a random direction.
Each worker ants can carry up to 1 unit of food. A queen ant can carry an unlimited amount (so that's what her body is for). Every ant picks up as much food on its current square as possible. A queen ant takes all the food from all adjacent squares including that carried by workers of any player.
Every turn, every ant is given a view of the local surroundings and then choses adecides to move. After every ant has made their choice, the movesAnts are then executedgiven priority in a randomtheir movement with those that are oldest moving first. The initial order for the starting queens is random.
Every square has a defensive value and an attacking value. Every queen adds 8 defensive value to the cell it is in. Every worker adds 2 defensive valueAn ant attacks by attempting to the cell it is inmove onto another ant. At the beginning of a turn, theWorker ants require two ants attacking value for each cell is resetthem in order to 0be killed. Every time an attack move is executed, the cell that is being attacked'sQueen ants require eight ants attacking value is incremented. If, after it is incremented, the attacking value is greater than the defensive value, allin order to be killed. Queen ants on that cell are eliminatedcannot attack. EveryAn ant after being killed drops 1all food and whatever it wasis carrying on deathand one additional unit of food.
An ant can move to any of the 8 surrounding squares. This does not changechanges the orientation of the ant to the direction it is moving.[3] If it tries to move to a square with an ant already on it, it is assumed to be attacking that ant, no matter if friendly or not.
An ant can drop a 24-bit pheromone on any ofoptionally increase the 8 surrounding squares orvalue of 4 different pheromones on the current onecell it is on, 1 of which can only be seen by ants of that particular colony. Pheromone has a value of a double-precision float and decreases by 1% every game tick. An ant can increase pheromone by up to 10.
A queen ant may create a worker and spawn it in any of the surrounding cells ... or its own cell. The queen ant also chooses the memory of the new worker.
To play this game, you mustYou can implement a bot inprogram or a java class that takes in an ant input and gives an ant output for that ant. Alternatively
Input:
Input contains your player id, I will provide a wrapper class which will allow your bot to play using stdin
ant's memory, if your ant is a queen, and stdout
then the contents of the cells surrounding it. You can findThe cells are given from the controller [here](linktop left to controller).
Your bot must implementthe top right in this interfaceorder:
package ants;
import controller.*;
public0 abstract| class1 Player| {2
public abstract String3 getName();| //Your4 bot's| name.5
public abstract Action moveAnt(Ant ant, Cell[] surroundings, String memory); //Applied to6 each| of7 your| ants.
}8
Your bot may not save state between each invocation of moveAnt
. If it does, the bot will be disqualified. To create an action you can call one of the following functionsInput is format thus:
Actionplayer_id;ant_memory;is_queen;cell_0_info;cell_1_info.move(String newMemory, int destCell);
Action.attack(String newMemory, int destCell);
Action.createWorker(String newMemory
Cell info is formated like this:
pheromone_0, int destCellpheromone_1, String workerMem);
Action.dropPheromone(String newMemorypheromone_2, int destCellpheromone_3, int pheromone); //pheromone will be truncated to 24 bits.
Action.doNothing(String newMemory);ant_type,ant_owner
surroundingsplayer_id
and ant_owner
are positive integers.
ant_memory
is a 15-D arraycharacter long string.
is_queen
is one of Celltrue
s representing the surrounding 3 by 3 area or false
. The cells in each index of the array
The pheromones are given indouble-precision (64-bit) floats.
ant_type
is one of W
(for worker ants) and Q
(for queen ants).
If there is no ant on a cell, ant_type
and ant_owner
will be omitted from the following configuration:input.
0 1 2
3 4 5
6 7 8
Output:
When you specify a destinationYou have to output the cell foryou want to move to, the pheromone you wish to add to your actioncurrent cell, and whether the ant would like to create an ant instead of moving (only works for queens :P).
It should be formatted thus:
next_memory;cell;pheromone_0;pheromone_1;pheromone_2;pheromone_3;create_ant;created_ants_memory
The controller is rather flexible and should be able to understand what you must alsowrite if you use different delimiters or leave out some of the same configurationinformation. Make sure that next_memory
comes first in your programs output and that it is exactly 5 characters long. If creating an ant, created_ants_memory
needs to be the last 5 characters in the input.
Every Cellcell
object has to be an integer in the following functions thatrange [0, 8] (defaults to 4
).
pheromone_n
has to be a positive float (defaults to 0
).
create_ant
needs to be one of: true
, false
, yes
, no
, 1
, or 0
(defaults to false
).
How to create a bot:
You have 3 options for this. You can:
- Implement the
Ant
interface with a java class. (Very fast)
- Communicate to the controller via I/O streams. (Fast (I think))
- Be called via command arguments and output via STDOUT (Slow depending on OS and programming language)
Note: Your bot must be completely deterministic. Given the same input, your bot should always return properties of the cellsame output.
Method 1:
Ant interface:
publicinterface intAnt getColor();{
public List<Ant> getAnts(); //Returns list of ants on current cell.
public intString getFoodmove(String input); //Returns the amount of food on the current cell.
}
Implement this interface for your ants :)
Method 2:
Every ant hastime it is one of your ants' turns, your program will receive a line of input through STDIN followed by a newline. After receiving the following properties:input, your program is expected to output a line through STDOUT followed by a newline.
public String getOwner(); //Returns your name if you are the owner ... otherwise someone elses.
public boolean isQueen();
public int getFood(); //How much food this ant is carrying.
Method 3:
Your program will be executed with the input line as its first argument. Your program is expected to output through STDOUT.
Each time the moveAnt
functionyour program is called, it should return within 5[4] milliseconds. Since the time limit may be exceeded due to fluctuations outside the ant function'syour control, an average will be calculated. If at any point the average is above 5[4] milliseconds and the total time taken by that particular ant functionyour program across all calls so far is more than 10 seconds, the relevant player will be disqualified. This means they will not be eligible to win and, their ant function will not be called again during that game, and all ants of that player will instantaneously perish.
- Should I make the board smaller or bigger than this? This gives each player an average of 1000 cells. Is this too much ... or too small?
- Is this too much food? This much food would be enough for each player to create an average of 1000 ants. Is this too many ants?
- Should ants stay in the same orientation throughout the game or:
- Should they change to a random orientation every turn?
- Change orientation so that the direction they last moved is now forward?
- Same as last but randomly rotate it 45 degrees clockwise or counterclockwise.
- Same as last but 90 degrees instead of 45 degrees.
- Should I make the time limit:
- The same?
- Shorter? If so, how much shorter?
- Longer? If so, how much longer?
- How many turns should a game go before it is ended prematurely? Or should it be a time limit (for example, 5 minutes)? If so, how long should the time limit be?
- How can I improve this to look prettier?
- Any typos or formatting issues?
- Any other ways I can improve this challenge?