This is a king of the hill challenge for Dots and Boxes (aka Pen the Pig). The game is simple, on your turn just draw a line on an empty fence. Every time you complete a square you get a point. Also, since we are playing by championship rules, if you complete at least one square on your turn you get an extra turn. This is a round robin tournament, where each bot plays each other bot twice 12 times on a 9x9 grid. Check out this match between two heavyweight titans, where ChainCollector makes mince meat of reigning co-champion Asdf:
Rules
- 0.5 second time limit per move.
- No interfering with other bots.
- Use PigPen.random() and PigPen.random(int) for randomness.
- No writing to files.
- Bot and all its persistent data will be reset every time opponent changes (every 12 rounds).
Bots
Every bot extends Player.java:
package pigpen;
public abstract class Player {
public abstract int[] pick(Board board, int id, int round);
}
Board
is the game board, which mainly serves to give you access to Pen
classes, and id
is your playerID (tells you if you're first or second), round
tells you which round your playing against the same opponent (1 or 2). The return value is an int[]
, where the first element is the penID (1-indexed), and the second element is the fenceID (0-indexed). See Pen.pick(int)
for an easy way to generate this return value. See the Github page for example players and JavaDoc. Since we are only using a square grid ignore any functions and fields related to hexagons.
How to Run
- Download Source from Github.
- Write your controller bot (make sure to include
package pigpen.players
) and put it in thesrc/
folder; - Compile with
javac -cp src/* -d . src/*.java
. Run withjava pigpen.Tournament 4 9 9 false
(the last two numbers can be changed to adjust grid size. The last variable should only be set totrue
if you wish to use the pp_record software.)
Scores
- ChainCollector: 72
- Asdf: 57
- Lazybones: 51
- Finisher: 36
- =LinearPlayer: 18
- =BackwardPlayer: 18
- RandomPlayer: 0
See Also:
Note: this game is a competitive challenge and not easily solvable, due to giving players an extra turn for completing a box.
Thanks to Nathan Merrill and Darrel Hoffman for consulting on this challenge!
Updates:
- Added a
moves(int player)
method to the Board class to get a list of every move a player has made.
Indefinite Bounty (100 Rep):
First person to post a solution that wins every round, and uses strategy (adjusting play based on observing how the opponent plays).