Training for the 420 Game

Overview | The Game | The Interface | The Deliverables |   Download the Code | Installation Instructions


There are many planes of existence to comprehend, and so little time. However, you have shown us some ability to comprehend the world of the game, and for this we are excited that you have agreed to help in our adventure.

Sometimes you can peform a task without really understanding it. To truly see beyond your experiences, you need to thoroughly understand everything you do. To help train you to do this, we have one additional assignment for you, based on the video game that you successfully played in your application process. Your task is to build an agent that will play the game and finish as quickly as possible, using available information about the state of the world.  The agent should do well playing against other agents. We are supplying you with an interface for coding such an agent. 

Please note that this assignment is optional as we realize you must perform other tasks as you prepare for your adventure.  However, this experience is highly recommended, and the aptitude of your agent will help us in determining your team's qualifications.

The Game

The game is very similar to the one you played in order to apply for the 4/20 adventure.  However, there are some significant differences.  This game can be played by any number of players, all of which can decide on their next move based on the state of the world.  Players have all the same restrictions as before, and additionally they cannot move into or through other players.  In this game, all clues are present at the beginning of the game, but they only become visible to a particular player when that player has solved the previous clue.  Only then does moving over the clue's location result in finding the clue.  The board will only show clues that are visible to at least one player.  Clues that have been found by all players disappear from the board.  To avoid players sitting on a clue to block other players, any player who tries to move onto the square containing the clue but currently occupied by another player, also finds the clue.  To avoid blocking tactics in general, all players who have sent a "no move" command for over 10 turns will be moved randomly by the simulator the next turn.

The board begins with a certain number of each bonus item, and that number remains fixed, i.e. if a player drinks a red bull, another one will show up somewhere in the world.  The same is true for cops, all of which are now the supercops from the video game.  That is, the game begins with a certain number of cops, who remain on the board the entire game.  No new cops will enter the world, and no cops disappear. The board you will be testing your agent on contains 4 red bulls, 4 marijuana leaves, at least 4 doughnuts (players dropping doughnuts can increase the number of doughnuts on the board), and 5 cops.

Energy and inspiration are gained and lost in the same way as before, with the drain occurring every 15 minutes.  Also, there is a new way to gain energy.  If you pick up a doughnut dropped by another team (called scooping your neighbor’s doughnut), you immediately gain 5 energy points in addition to upping your doughnut count.  In this game, doughnuts dropped by a team are orange to make it more obvious. The player can accumulate any number of doughnuts, but energy and inspiration bottom out at 40 and cannot exceed 100.

Time passes a bit more quickly, with 1 minute elapsing at every turn, i.e. every time a player sends an action.  4:20 is still a time for inspiration (5 points), and sunrise (6am) still adds energy (15 points).  At night (10pm to 6am), players still lose 2 energy points every 15 minutes.

As before, less energy translates to slower movement.  At every turn, the chance of the movement command being accepted is equivalent to the amount of energy out of 100, or the percentage determined by the amount of energy.  So, a player with 76 energy points has a 76% chance of his movement command being accepted each turn.  Inspiration now works in the following way.  The amount of inspiration at the time of finding the clue determines exactly how long the player will think before solving the clue and seeing the next clue site.  The amount of time is equal to 15 minutes plus 100 minus the inspiration level.  So, a player with 80 inspiration points when he finds clue 4 will solve the clue in 35 minutes. There is no reason to stay near a clue when solving it.

A player who ends up adjacent (not diagonal) to a cop who isn't already questioning a player and who isn't chasing a doughnut will be held for 30 minutes, during which time he can drop and eat doughnuts but cannot move.  The cop, of course, does not move either during the questioning.  The clue solving clock keeps running when you are caught by a cop. In order to lure away cops, doughnuts can be dropped if the player has a positive doughnut count.  Cops can see objects when they are within a 9x9 square centered around them.  So, if a doughnut is at most 4 squares away in a horizontal direction and at most 4 squares away in a vertical direction, it is visible to the cop.  A cop who sees a doughnut will ignore everything else.  If the cop reaches the doughnut, he will be immobilized for 30 minutes while eating.

The game displays information while it is running.  To the right of the maze, it will show the time, incremented every minute, and underneath, a list of all the players in ranked order from top to bottom.  The information includes the player's logo, the number of clues solved, the energy, the inspiration, and the doughnut count.  The text is color coded based on what's happening.  If nothing special is happening, the color is blue.  If the player is thinking, i.e. in the process of solving a clue, the color is a lighter blue.  If the player is being held by a cop, the color is red, and when the player has finished, the color is green.

Running the game is slightly different as well.  When you run the game, the animation does not start right away.  The maze and players are drawn, but they do not move right away.  To start, press the escape key.  The same key will pause the game and restart it at any time.  You can slow down or speed up the game by pressing the left arrow and right arrow, respectively.  In addition, you can increment a paused game one step by pressing 'i'. Lastly, you can restart the game by pressing 'r'.  Again, the animation will not run after you restart until you press the escape key.

The Interface

We are supplying you with the code that runs the game.  There is an interface which allows you to write your own players, and a class that you can set up to use the appropriate players in the running of a game.  The important class is PlayerActor, which you must subclass.  The function that you need to write is PlayerActor.act(), which determines the action of the player at each turn.  The PlayerActor has a PlayerInterface object, which contains all the functions that the actor can call to find out the state of the environment and to affect the action of the player. 

When you turn in your class, it will be a subclass of PlayerActor called <TeamNameNoSpaces>Actor.  For example, The Bogus Team would turn in a class called TheBogusTeamActor.  This class will have its own act() function, which makes only calls to the PlayerInterface functions and any functions you write yourself.  The actor is not allowed to call any functions or access any variables in any other classes.  We have included ExampleActor as an example of a fairly stupid player.  You can use this as a basis of your own actor.  If you break any of the above rules, we will default your actor to the ExampleActor.

For those of you who are less skilled in the art of writing code, we plan to allow you to turn in a text file containing values for the constants defined in the ExampleActor. Stay tuned for more information on how to do this. In the meantime, it is still useful to look at the documentation, especially the comments in the ExampleActor which describe what the constants do.

Note that your actor must be reasonably efficient.  It should take less than 30 milliseconds on average to call your act() function on a 800 Mhz PentiumIII.  If you don't do anything too crazy, it shouldn't be hard at all to stay within this limit, but we will be happy to run speed tests on your actor code prior to 4/20 if you wish. 

You are welcome to look at the core code, but do not change anything other than your own class and the PlayerInitializer class, which is explained below and is used to determine how many and which players will play in a game.  We will have the original version of the code to plug your actor into, and if you've changed the core code, your actor may not work at all and likely will not play as you would like.

To test your players, we are allowing you to change the functions of a class called PlayerInitializer.  These are:

int getNumPlayers() - returns the number of players
int getActor(PlayerInterface pi, int id) - returns the actor to use for player id
int getImageFileName(int id) - returns the image file to use for player id
String getName(int id) - returns the name to use for this player id

So, if you want to test the game, pitting 5 players using your best actor against 5 players using the ExampleActor, you can change these functions to do the right thing.  Obviously, getNumPlayers in this case would return 10, getActor would return the ExampleActor for 5 of the id's and your own actor for the others, and getImageFileName would return the appropriate image file names for the players, so that you'll be able to distinguish them.

We are including image files p1.gif through p20.gif, which are simply blue numbers from 1 to 20.  You can feel free to use these or create your own to uniquely identify each player.

For further questions about the PlayerActor, PlayerInterface , and PlayerInitializer classes, look at the documentation. You should write your player for the simulation you've been give.


On April 20, you will be asked to turn in your agent.  You will have written a class called <TeamNameNoSpaces>Actor, and you will save it to a file called <TeamNameNoSpaces>  Those only changing constants can create an actor that uses the desired constants or can turn in a text file called <TeamNameNoSpaces>Constants.txt. Pu the file on a diskette and await instructions on how to deliver it to us.

In addition, we would like you to create a logo for your team.  Please send a 32x32 logo that uniquely identifies your team to by Friday, April 6.

Download the code

Press here to get a zip file with the required java files.

Note: There is an update of the file. Download it by pressing here.

Installation instructions

First, the java SDK should be installed on your system.  This is available from  Sun.   You should install this and set the appropriate path variables on your system so that you can compile and run java programs.   

Next, use the links above to get the code.  Extract it into a new directory, and place this directory into your classpath.  You should then compile all the code (javac *.java) and then run the code (java GamePlayer).  Note that your version of java must support the swing extension.

Good Luck. Mail any questions to

For additional information, press here to go to the training section of the information page.