CS 145 Lab 11 – SplatBot
Welcome to lab 11!
If you have checkpoints from the last lab to show your instructor or TA, do so immediately. No credit will be given if you have not already completed the work, nor will credit be given after the first 10 minutes of this lab.
In this lab you will create a robot or robots who will compete with others in a game of SplatBot. Each robot is assigned a color—either red or blue. On each action, the tile underneath a robot is painted the robot’s current color. If a robot is hit by an enemy’s splat, that robot begins painting tiles the opponent’s color and does for 10 turns. The game is won by whichever robot has more tiles painted after 500 turns.
The code for the game is available in the template repository, in readonly/splatbot.jar
. Pull this JAR file down using Team / Pull…, as explained in homework 0, part 2. Right-click on it and add it to Eclipse’s Build Path.
You will need to submit your robot via your Bitbucket repository. Create a lab11
package. Create class SplatBot
. (You can create others with different names after you get SplatBot
working.)
Constructor
In your class, add a constructor that accepts a SplatBotColor
as a parameter. It will be one of these two values:
SplatBotColor.RED SplatBotColor.BLUE
You may ignore the parameter or use it in your strategy.
getAction
On each turn of the game, the game calls your robot’s getAction
method to decide what Action
it will take. This method accepts as parameters three Cell
s, describing the three tiles to the robot’s left, in front of the robot, and to the robot’s right. Each Cell
parameter will be one of these values:
Cell.RED // cell has been painted red Cell.BLUE // cell has been painted blue Cell.NEUTRAL // cell has not been painted Cell.ROCK // cell is covered by impenetrable rock Cell.RED_ROBOT // cell is occupied by red robot Cell.BLUE_ROBOT // cell is occupied by blue robot Cell.WALL // cell is off the game board
Have your method return one of these choices:
Action.TURN_LEFT Action.TURN_RIGHT Action.MOVE_FORWARD Action.MOVE_BACKWARD Action.PASS // skips a turn Action.SPLAT // fires a splat in the robot's line of sight Action.SURVEY // request a view of the game board
Pick one these actions using a strategy of your choice. Add any instance variables you want. Just don’t cheat by taking screenshots, prompting for user interaction, or deferring all calls to one of the provided robots.
You may fire a splat or request a survey one out of every 5 turns. More frequent requests will be ignored, effectively forfeiting your turn.
survey
Have getAction
return Action.SURVEY
to get a 10×10 2D array describing the current state of the game board. The board will be delivered to the robot via a method named survey
, which returns nothing but accepts a 2D array of Cell
s.
Main
Run a game of SplatBot with a snippet like this in a main
method:
int delay = 100; int nTurns = 500; new Splatter(splatbot.RobotRandom.class, lab11.SplatBot.class, delay, nTurns);
Checkpoint 1
Write a robot that beats splatbot.RobotRandom
. The victory must happen on your instructor’s computer. Once you are confident in your robot, commit and push it, and let your instructor know.
Checkpoint 2
Write a robot that beats splatbot.RobotLefty
. The victory must happen on your instructor’s computer. Once you are confident in your robot, commit and push it, and let your instructor know.