Your task here is to write an AI for a simple robot battle. The class to be implemented is provided at the bottom of this post, and source of the controller can be found here.
Requirements
- Write a class which implements the abstract Bot class, provided at the bottom of this post
- You must provide a 0-argument constructor, this must change the value of the Name field, but may not change any other inherited fields
- Outside of the constructor, you may not change any of the inherited fields in any way
- Your action method should, when called (it will be called once per turn cycle, with a copy of the 64 by 64 map as its argument), return one of the Action enum fields:
UP to move up (towards y=0) DOWN to move down LEFT to move left (towards x=0) RIGHT to move right MINE to plant a mine and then move a random direction PASS to pass
- Within the passed map, 0 represents an empty cell, -1 represents a mined cell, and anything else denotes a cell occupied by a bot (each bot will be represented by its unique bot_id, you can get your bot's id by calling this.id())
- A bot is eliminated in any of the following situations:
- It moves out of the map
- It moves into a cell occupied by a mine
- Another bot moves into the cell it currently occupies
- Its action method takes more than 50ms to respond
- Its action method throws any exception that is not caught within its own bounds
To win
Have your bot be the last bot standing!
Additional Rules
The round is not allowed to last more than 1,000 turn cycles. If, after the 1,000th turn cycle, more than one bot is still standing, all of the surviving bots are considered to have tied that round.
Each time a new bot is submitted, it will, as soon as possible, be pitted in two two-bot, three three-bot, and three-four bot rounds; each time against randomly selected opponents.
Scoring
total score=1000*(wins+(1/3) ties - (1/12) losses)/roundsPlayed
The exceptions to this are that any bot that has played at least one round that it didn't lose is guaranteed at least one point, and no bot may have a negative score.
The class to be implemented:
import java.util.*; public abstract class Bot { public static enum Action{ UP,DOWN,LEFT,RIGHT,MINE,PASS; } public static final class Position{ public int x; public int y; public String toString(){ return "("+x+","+y+")"; } public double distance(Position p){ int dx=p.x-this.x; int dy=p.y-this.y; return Math.sqrt(dx*dx+dy*dy); } public Position(int x,int y){ this.x=x; this.y=y; } } public String toString(){return name;} public Position p; public String name=""; public abstract Action action(int[][] map); private int bot_id; public final int id(){return bot_id;} public final void register(List<Bot> a){ a.add(this); bot_id=a.size(); } }
Leaderboard
The full match log may be read here
ProtectiveBot (6 wins, 6 ties, 1 loss)- 609 points Albert (2 wins, 8 ties, 0 losses)- 467 points Frozen (1 win, 8 ties, 0 losses)- 407 points Cocoon (1 win, 3 ties, 3 losses)-250 points Wanderlust (0 wins, 3 ties, 5 losses)- 73 points MineThenBoom (0 wins, 2 ties, 11 losses)- 1 point PatientBot (0 wins, 0 ties, 13 losses)- 0 points
Sample Bots
Simple Pathfinder: http://pastebin.com/raw.php?i=aNBf00VU
RandomBot: http://pastebin.com/raw.php?i=VD8iGaHC
Minelayer: http://pastebin.com/raw.php?i=sMN1zSa0
UDLRMP
for up, down, left, right, mine, pass) and accepting that output as input to the controller. Only the first byte is read, and anything other than one of those six commands is counted as pass. (Just an idea, personally, I've never coded a KOTH controller.) \$\endgroup\$