teaching machines

CS 145: Lab 12 – Splatbot

December 5, 2017 by . Filed under cs1, cs145, fall 2017, labs.

Welcome to lab 12!

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 so 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 speccheckers/splatbot.jar. Pull this JAR file down using Team / Pull…, as explained in homework 0, part 2.

You will need to submit your robot via your Bitbucket repository. Create a lab12 package. Create class SplatBot. (You can create others with different names after you get SplatBot working.)


In your class, add a constructor that accepts a SplatBotColor as a parameter. This is the color that has been assigned to your bot. It will be one of these two values:


You may ignore the parameter or use it in your strategy.


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 Cells, describing the three tiles to the robot’s left, in front of the robot, and to the robot’s right, respectively. Each Cell parameter will have 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.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.


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 accepts a 2D array of Cells as its only parameter.


Run a game of SplatBot with a snippet like this in a main method:

int delayMillis = 100;
int nTurns = 500;
new Splatter(splatbot.RobotRandom.class, lab12.SplatBot.class, delayMillis, nTurns);

Checkpoint 1

Write a robot that beats splatbot.RobotRandom. Once you are confident that your robot can do so, commit and push it, and let your instructor know.

The victory must happen on your instructor’s computer. That means there must be enough time left in lab for the competition to take place. Other pairs will also be submitting their robots. No battles will take place once lab has ended. To ensure successful completion of this lab, you are encouraged to complete the work before the scheduled lab period.

Checkpoint 2

Write a robot that beats splatbot.RobotLefty. The same time restrictions apply.