RatBots XV Instructions and Rules Overview – What is a RatBot? A RatBot is a computer program placed in a computer-generated arena trying to find a way to achieve the goals of the game. You will write the functions that control your RatBots, and then test them to see how well you have programmed them. Will your RatBot succeed or will it get lost in the maze?

The goal of this project is to challenge students to solve problems that have dynamic solutions. Students will be encouraged to apply all of the Java programming skills and problem solving techniques to design (and redesign, and redesign…) a RatBot that can achieve the goal of acquiring cheese within a maze as efficiently as possible. Competitions against other RatBots.

There will be many different competitions and methods of judging the RatBots, and thus some may be designed to win a certain type of competition and some to win others. A few super-RatBots may be able to sweep the competitions! You may enter up to three different RatBots into the competitions. If you choose to submit multiple entries, please make sure that they are substantially different from each other. Each of your entries will compete in all of the ‘events’.

LIST OF EVENTS:

1. The RatBot League – Each RatBot will compete against each of the other RatBots in a head to head competition of 100 rounds. The RatBot that wins the most rounds will win the match. The RatBot with the best overall win-loss record will win the competition. In the event of ties, total rounds won will be the only tiebreaker.

2. The Battle Royale – By random draw, the RatBots in groups of up to nine will be placed in the maze for 100 round competitions. The top three or four RatBots in rounds won in each match will advance to the next matches. Once the field has been narrowed to nine or fewer finalists, a 100 round live computer-cast final will decide the winner! (The exact structure of this competition will be decided once the number of entrants is known.)

3. The Singles Competition – Each RatBot will be individually placed in the maze for 100 rounds. The RatBot that acquires the highest total score will win this competition.

4. The following awards will be awarded via judging. Most Efficient (success with small code size) solution, and the Most Entertaining solution.

Extra rules which apply to all events: Each round will end when 500 moves are completed. The RatBot with the highest score wins. In a competition, the order that the RatBots are selected to act is random each move. In a competition, if multiple rats have the same high score when the round ends, each will be awarded a round win. If your RatBot function crashes at any time, it will be eliminated from the competition. If your chooseAction function takes too long to run (an average of over 10ms/move on a classroom computer or as determined by the committee) it could be disqualified from competitions. Please remove ALL System.out.print type statements from your submitted RatBots!

Deadlines for submissions will be posted on the website. Please check the website for updates and clarifications. The Arena (also known as the maze.)

 The arena is a 21 by 21 grid. The top left corner has a Location of (0,0).  Approximately 8% of all locations that there could be a wall there will be a wall. These are randomly selected each round.  In the center of the maze, there is a 5 by 5 area called the Starting Room (shown in gray). Each RatBot will be started at a random location within the Starting Room. This begins any match on fairly even ground. The Starting room will always be free of walls when a round begins. It will be separated from the rest of the maze by walls except for one doorway on each side.

There are three important types of objects in the maze:

 Throughout the maze there are approximately 60 Material objects each round. The Materials each have a type number 1-4. The upper left quadrant will contain mostly type-1 Material, the upper right quadrant will contain mostly type-2 Material. The lower right quadrant will contain mostly type-3 Material and finally the lower left quadrant will contain mostly type-4 Material. If you move onto a space containing a Material, you pick that Material up and also score one point.  Throughout the maze there are approximately 20 Destination objects each round. Each Destination has a list of required Materials and a point value. Destinations that require more Materials tend to have higher point values. You may only move onto a Destination if you are carrying the required Materials. Once you do so, you score the point value of the Destination.  Your RatBot uses power to move around the maze. You start with the maximum power level of 1000, and it decreases by 1 each time you move. It decreases by an additional one for each Material you are carrying. The StartingRoom and each corner of the maze are power-up stations. Your power level will increase by 150 each turn you are on one of these areas. If your power level ever reaches zero you are done moving for that round. How to write a RatBot function Each RatBot will be a Java class that extends the RatBot class.

You must override the chooseAction( ) and optionally the initforRound( ) methods. public void initForRound() Whenever a new round begins, the RatBots engine will call your RatBot’s initforRound( ) method. Use this method to initialize any variables that need to be reset at the start of a round. public int chooseAction() The RatBots engine will call your RatBot’s chooseAction( ) method whenever it is your turn to move. Your RatBot’s chooseAction( ) method will return an integer value that corresponds to the next move your RatBot will make. There are only many possible moves you may choose from:

MOVE – if you return a value between 0 and 7, your RatBot will attempt to move in that direction. (0=NORTH, 1=NE, 2=EAST, 3=SE, 4=SOUTH, 5=SW, 6=WEST, 7=NW.) If a wall or another RatBot or a Destination that you do not have the Materials for blocks your path to move as requested, the RatBot will not move this turn.

BUILD WALL – if you return a value between 8 and 11, your RatBot will attempt to build a wall in that direction. (8=NORTH, 9=EAST, 10=SOUTH, 11=WEST.) If a wall already exists in that location, then nothing will be changed.

DROP ONE ITEM – if you return 1000, your RatBot will attempt to drop one Material into an adjacent space. The first item you picked up will be the one dropped.

DESTROY ONE ITEM – if you return 2000, your RatBot will destroy the first item you picked up.

REST – if you return any number not specified above, your RatBot will not move this turn.

The following constants are defined in the RatBot class for convenience. public static final int REST = -1; public static final int NORTH = 0; public static final int NORTHEAST = 1; public static final int EAST = 2; public static final int SOUTHEAST = 3; public static final int SOUTH = 4; public static final int SOUTHWEST = 5; public static final int WEST = 6; public static final int NORTHWEST = 7; public static final int BUILD_WALL_NORTH = 8; public static final int BUILD_WALL_EAST = 9; public static final int BUILD_WALL_SOUTH = 10; public static final int BUILD_WALL_WEST = 11; public static final int DROP_ONE_ITEM = 1000; public static final int DESTROY_ONE_ITEM = 2000;

Each RatBot, by extending the RatBot class, has access to many ‘sensing’ methods that will tell you what your rat is ‘seeing’ in the maze. A summary of these methods is given on the next page. Please look at the demo RatBots (included with the code) to get an idea of where to start coding. Summary of methods in the RatBot class

Modifier and Type Method and Description getCol() int Gets the x coordinate within the maze of this RatBot. getRow() int Gets the y coordinate within the maze of this RatBot. getMyMaterialList() ArrayList Gets the list of Materials this RatBot is carrying. getDestinations() ArrayList Gets the entire list of Destinations throughout the arena. getListOfVisibleMaterials() ArrayList Gets a list of Materials that this RatBot can see right now. getListOfVisibleRats() ArrayList Gets a list of other Rats that this RatBot can see right now. getListOfVisibleDestinations() ArrayList Gets a list of Destinations that this RatBot can see right now. getOpenDistance(int dir) int Gets the number of spaces this RatBot could move in the given direction. getScore() int Gets the current score in this round for this RatBot. getBestScore() int Gets the current best score in this round among all Rats in this match getEnergyLevel() int Returns the current energy level of this RatBot (0-1000). getRoundsWon() int Gets the number of rounds won in the match by this RatBot. getMoveNumber() int Gets the current move number within this round. getRoundNumber() int Gets the current round number within this match. canMove(int dir) boolean Determines if this RatBot canMove in the specified direction. getDirectionToward(int c, int r) int Gets the closest direction (0-7) towards a given location (c,r). getDirectionToward(RatBotActor a) int Gets the closest direction (0-7) towards a given object (a.) The object may be a Rat, Material or Destination.

getName() java.lang.String Gets the name of this RatBot. setName(java.lang.String in) void Sets the name of this RatBot. getPreferredColor () java.awt.Color Sets the name of this RatBot. setPreferredColor(java.awt.Color in) void Sets the preferred color of this RatBot.

These methods are provided in the Material class.

Modifier and Type Method and Description

getCol() int Gets the column (x coordinate) within the maze of this Material. getRow() int Gets the row (y coordinate) within the maze of this Material. getType() int Gets the type of this Material (1-4). toString() java.lang.String Creates a string that describes this Material.

These methods are provided in the Destination class.

Modifier and Type Method and Description

getCol() int Gets the column (x coordinate) within the maze of this Destination. getRow() int Gets the row (y coordinate) within the maze of this Destination. getPointValue() int Gets the point value of this Destination. ArrayList Gets the list of Materials required by this Destination. areRequirementsMet(ArrayList) boolean Determines whether the given list of Materials contains the required Materials for this Destination. toString() java.lang.String Creates a string that describes this Destination.

These methods are provided in the Rat class.

Modifier and Type Method and Description

getCol() int Gets the column (x coordinate) within the maze of this Rat. getRow() int Gets the row (y coordinate) within the maze of this Rat. getScore() int Gets the score of this Rat. toString() java.lang.String Creates a string that describes this Rat. How to use the RatBots programs

There are two primary ways that you can enter your RatBot into the maze.

1. If you place your RatBot’s code into the ratbot package within the project it will automatically be loaded into the menu when you run the project. You can select to add your RatBot from the Add RatBots menu. 2. You can directly load a RatBot into the maze by changing the RatBotsRunner file. Instructions are given in the comments of that file.

Troubleshooting a RatBot – suggestions Once you get the maze program running, if your RatBot doesn’t move, it’s probably your fault. Check your algorithms. (However, please let us know of any bugs you find.) Start simple and test your RatBot after each improvement you make. Some ‘improvements’ end up negatively. Watch many trials of your RatBot to get a feel for where it gets stuck, and how you could fix that.

Other notes about creating RatBots:

You may write sub-functions that get called by your RatBot function. Your RatBot will NOT have a main function. The main function you will use is within the RatBots14 project. RatBot names should be creative, descriptive, appropriate and less than 15 characters long. Each RatBot should have its own .java file. You don’t have to write any graphics functions. They are all taken care of in the RatBots14 project. There are many RatBot examples provided with the code. These will give you a starting point for designing your RatBots. Feel free to use any of the code found in the examples, however you should give credit for any ideas you get from these in your comments.

A brief history of RatBots

2000-01 – First RatBots competition. The code was written using a graphics library created by student Danny Wilhelm. The goal was simple – escape the maze as quickly as possible. 2002 – Still coding with C++. Rules changed to make the game an acquisition of territory game. 2003 – First year with Java! 2004-2011 – Many different variations of the game over the years including: Capture the flag, playing in teams, power-ups, managing energy levels, stunning your opponents, chasing down (or avoiding) computer created robots, paintballs, teleportation, variations on acquiring territory, and mazes full of cheese. 2012 – Began using the Grid World platform for the game. 2013 – The goal was trying to have the longest tail. Class loader code added by student Patrick Angle. 2014 – Last year’s goal was based on finding the cheese, with bonus points for aged cheese and cheese outside the maze. Some teleportation was involved! 2015 – RatBots 15 – inspired by logistics within warehouses and factories. Will you be the winner? Project Requirements: There are five challenges to complete before beginning work on the official RatBots competition. Each phase must be completed in succession.

Challenge #1 – Find a Material.

For this challenge, the arena will have no interior walls. One material (worth 100 points) will be placed in the maze. You need to create a RatBot that will get the Material 100% of the time.

Challenge #2 – Complete one order.

For this challenge, the arena will have no interior walls. Many Materials will be placed in the arena, but only in their proper quadrants. One Destination that requires one Material will be present. The point value of the Destination will be 1000 points. You need to create a RatBot that will average over 1000 points over the course of 100 rounds.

Challenge #3 – Compete one complex order.

For this challenge, the arena will have no interior walls. Many Materials will be placed in the arena, but only in their proper quadrants. One Destination that requires four Materials will be present. The point value of the Destination will be 1000 points. You need to create a RatBot that will average over 1000 points over the course of 100 rounds.

Challenge #4 – Find a Material in the Maze

For this challenge there will be interior walls in the arena. One material (worth 100 points) will be placed in the maze. You need to create a RatBot that will get the Material at least 80% of the time.

Challenge #5 – Complete one order in the Maze

For this challenge there will be interior walls in the arena. Many Materials will be placed in the arena, but only in their proper quadrants. One Destination that requires one Material will be present. The point value of the Destination will be 1000 points. You need to create a RatBot that will average over 500 points over the course of 100 rounds.

Final Challenge – RatBots15 (Normal Mode)

Once you have completed the five challenges above, you will be ready to create a RatBot for the official RatBots competition. The challenges will help you understand how to write a RatBot that will succeed.

To set the maze up for these challenges you can use the Arena menu or the function keys. F1 for challenge #1, F2 for challenge #2… The game starts up in Normal Mode (which can also be selected with F6). Scoring Rubric for the RatBots project

Challenge #1 10 points upon completion Challenge #2 10 points upon completion Challenge #3 10 points upon completion Challenge #4 10 points upon completion Challenge #5 10 points upon completion Average Points per Round in Normal Mode 30 points possible – rubric below Thought Journal 20 points possible – rubric below. 100 points total

Normal Mode performance rubric Average points per round Points earned 0 0 / 30 200 10 / 30 300 15 / 30 500 20 / 30 800 25 / 30 1200 30 / 30

points RUBRIC for RatBot documentation (Thinking journals) The solution is logical and well designed. 0-5 Journal entries explain why a certain technique is beneficial and how the idea came about.

Trials and errors and improvements that were made are all documented. 0-5 Detailed explanations of the thought process, not only the final product.

Code is documented throughout, and is organized in an easy to read manner. 0-5 Variable names help to make the code easy to understand.

At least three entries are made into journal on different days each week. 0-5 The journal is up to date throughout the process (no retro entries.)

Competition against other RatBots. (This phase is entirely extra credit!!)

Useful shortcut keys in RatBots

F1 Switch Arena to Challenge #1 mode. F2 Switch Arena to Challenge #2 mode. F3 Switch Arena to Challenge #3 mode. F4 Switch Arena to Challenge #4 mode. F5 Switch Arena to Challenge #5 mode. F6 Switch Arena to Normal mode. F7 Display last move chosen for each RatBot F8 Change color scheme F9 Toggle Grid Lines F10 Start running in console mode F11 Stop F12 Start running at top speed SPACE Step or toggle console 1 Load the first RatBot in the menu 2 Load the second RatBot in the menu 3 Load the third RatBot in the menu 4 Load the fourth RatBot in the menu 5 Load the fifth RatBot in the menu T Change the length of the tails shown. Q Close the program ESCAPE Close the program

While the game is stopped, you can:

 Hover the mouse over a space to get info on what is in that space.  Right click on an object to get a list of methods for that object.  Right click on an empty space to add an object to the maze.

You can run the game three ways:

 Step-by-step using the step key – this advance the game on move each time.  Run at various speeds. – Look for trends in how your RatBot is doing.  Console mode – runs many rounds very quickly. See your average score!

(We always run at least 100 rounds to get a good average measure of performance because some mazes are more difficult than others due to random chance.)