teaching machines

CS 145 Lab 12 – SplatBot

December 6, 2019 by . Filed under cs1, cs145, fall 2019, 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.

To receive credit for this lab, you must paint more tiles than the instructor’s bots. 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.


Person A types.

Some helper code for the game has been added to the template repository. Pull from the template remote to grab it. Then expand the speccheckers folder and locate splatbot.jar. Menu-click on it and choose Add as Library. Leave Name as splatbot and Level as Project Library. For the Add to Module setting, choose your the module you’ve used for all of your homework. This was named cs1_2019c_template by default, but it may have been changed to your username, or something else altogether.

You will need to submit your robot via your GitLab repository. Create a labs.lab12 package. This must be spelled exactly as described, including case.

Create class SplatBot. You can create other bots 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, labs.lab12.SplatBot.class, delayMillis, nTurns);

Checkpoint 1

Person B types.

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.

Checkpoint 2

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