The Board
The Board is a two dimensional array of cells. Cells are populated by Animals. Every day, all Animals on the Board simultaneously make one move. If two or more Animals move to the same cell, they fight until one remains. The possible moves and attacks are as follows:
- Moves - {
Move.UP
,Move.RIGHT
,Move.DOWN
,Move.LEFT
,Move.HOLD
} - Attacks - {
Attack.ROCK
,Attack.PAPER
,Attack.SCISSORS
,Attack.SUICIDE
}
Animals fight by playing Rock-Paper-Scissors. Standard rules apply but with two modifications. First, you may commit suicide at any time. Second, a tie is broken pseudorandomly. If more than two Animals collide, two are pseudorandomly selected to fight until one remains.
The Players
Animal behavior and appearance is as follows.
- Lion
- Represented by the character
L
. MovesDOWN
,RIGHT
, then repeats. Pseudorandomly attacks withPAPER
orSCISSORS
.
- Represented by the character
- Bear
- Represented by the character
B
. MovesDOWN
x 4,RIGHT
x 4,UP
x 4,LEFT
x 4, then repeats. Attacks withPAPER
.
- Represented by the character
- Stone
- Represented by the character
S
. MovesHOLD
. Attacks withROCK
.
- Represented by the character
- Wolf
- Only wolves that are submitted as an answer will be included. Represented by 'W'. Moves with any Move. Attacks with any Attack
You will implement the Wolf by filling in the blanks in the following template. All submissions must be in Java and must be contained in a single file. Alternatively, @ProgrammerDan has written a wrapper class that extends the competition to non-java submissions.
// Optional code here
public class Wolf extends Animal {
// Optional code here
public Wolf() { super('W'); /* Optional code here */ }
public Attack fight(char opponent) { /* Required code here. Must return an Attack. */ }
public Move move() { /* Required code here. Must return a Move. */ }
// Optional code here
}
The submission with the highest average number of living wolves after five trials with 1,000 iterations wins. I will update the winner each time a new answer is posted (but not within the first 24 hours).
Tools
- You are provided with a small map of your immediate surroundings in the following form.
char[][] surroundings
A zero indexed, 3 by 3 matrix of characters that represent nearby animals. Empty tiles are represented by a space character (' '). You are atsurroundings[1][1]
. For example, to your right would besurroundings[1][2]
, and above you issurroundings[0][1]
. Your surroundings are updated just before being asked to move, but may be out of date when asked to fight.
- You may persist data between invocations of your Wolf, Move requests, and Attack requests. You may neither read from nor modify files created by another Wolf class.
- You are provided with the size of the map in the following form
int MAP_SIZE
Assumptions
- All submission will compete on the same board against all other submissions as well as Lions, Bears, and Stones
- The board is a square with sides of length
sqrt(n+3)*20
wheren
is the number of submissions. All sides wrap, so you can safely move in any direction infinitely. - Simulation begins at ~25% board capacity with 100 of each Animal pseudorandomly distributed across the board.
- If an Animal throws an exception when asked to move, that Animal will
HOLD
- If an Animal throws an exception when asked to fight, that Animal will
SUICIDE
- If an Animal has no letter when the controller checks, that Animal will immediately die
Getting Started and Testing Instructions
The tools you need to test your submission can be found here. The following files should be available at that link.
- ExampleRun.gif - A 5-10 second gif of the program running.
- Scoreboard - The latest results of the competition.
- Wild.jar - An executable that you can run to watch the premade Animals run around.
- Wild.zip - The NetBeans project that houses the controller program with a few premade Animals added. Use this to develop your submission.
- WildPopulated.zip - Same as above, but with and about 40 submissions added for you to test against. The GUI has also been removed because of performance issues. The results will simply appear a few moments after you run. The non-Java submissions are commented out because they require extra downloads and effort. Use this to test your submission against the field.
- Wolf.txt - A naive implementation of the Wolf class in Java. You may use and expand that implementation without crediting me.
To test your class:
- Download Wild.zip
- Rename your Wolf.java and Wolf class to something unique
- Add your UniquelyNamedWolf.java file to Wild\src\animals\
- In the Wild class, add your class to
classes
array, like this.Class[] classes = { UniquelyNamedWolf.class, Bear.class, Lion.class, Stone.class, Wolf.class };
- Rebuild and run
I also included another project containing all of the submissions, for testing purposes. I creatively named it "WildPopulated". The three or four non-Java wolves were commented out, because getting them to run requires a lot of extra work and downloads. The one I posted should run with zero extra work. The GUI was also commented out for the sake of speed.
Scoreboard April 22, 2014
The Scoreboard has been moved to Google Drive. View it here. It will be updated on a casual basis (i.e., when I get to it) as new submissions come in.
Side Challenge - NoHOLD
Removed because no (as in zero) participation. It wasn't part of the original challenge anyway.
int MAP_SIZE
" I'm having trouble figuring out how to use this. Netbeans says there's no instance of the stringMAP_SIZE
in any of the files in the project. \$\endgroup\$