teaching machines

CS 145: Lab 12 – Splatbot

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.)

Constructor

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:

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

Main

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.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *