by Memetix » Thu Dec 08, 2011 4:00 pm
If you want to try a simple, single pass approach to combat that produces good results with low CPU usage, the following has worked well for me. On my 3 yr old laptop, the Java code runs in 3-5 milliseconds.
For each ant (ours and the enemies that we know about) we work out which tiles on the map the ant can affect with it's combat zone after 1 move. Store the number of times each tile is affected in an array influence[players][rows][cols]. While doing this, store the total influence in another array total[rows][cols].
This influence map represents the number of ants each player could get to "attack" each tile of the map. It represents the best that can be achieved.
Once this is done we know how many ants each ant could be fighting in each tile of the map.
i.e. enemies = total[row][col] - influence[player][row][col]
We can now work out the best ant in each combat zone, the best ant being the one that is fighting the least number of other ants. Store this in another array fighting[player][rows][cols].
i.e. fighting[0][0][0] would contain the number of enemy ants an ant at (0,0) belonging to player 0 would be fighting.
This can be simply derived from the values in the influence array.
The last step of the process is to work out what could happen to each player if it put an ant in a tile and store this in an array status[players][rows][cols]. We only need to do this for tiles an ant can get to with 1 move.
The values in this array are set to SAFE, KILL or DIE depending on whether the best ant we are fighting in the tile is fighting more, equal to or less ants than us.
That's it. If you want to be safe, never allow a move into a tile with status of KILL or DIE.
If you want to break deadlock situations you can allow entry into KILL tiles and expect to get a 1:1 swap.
You can also check to see if an enemy ants' move towards you would result in its death, if so it is probably safe to advance towards that tile. At the moment I'm not doing this, but it could be useful information and produce better results.
To see this strategy in action check out CombatAnt on fluxid
Many thanks to A1kon for starting the ball rolling ... I've had many good fights with his ants which use is very different approach.
The results seem broadly comparable.