Search:
Cookie Monster Game
Updates
#1 6/7/05 Environment class bug fix Environment.java
#2 6/7/05 Additional note:
The property file cookiemonster.properties may NOT be accessed by the Cookie Monsters.
The Cookie Monsters only "know" what they get by their "sensors".

Cookie Monster Game (70)

Introduction
You have to extend a small JAVA application named "The Cookie Monster Game".

The Cookie Monster Game Rules
The screenshots below shows how the game looks like. The board contains a number of cookies .
Two competitor teams consisting of two cookie monsters each and try to eat all cookies.
But attention, there are also toxic fields on the board! A cookie monster will lose its points collected if it steps on such a toxic field.
From time to time, super cookies appear. Super cookies are only available for a short period of time but they double your points!
And if the cookie monster eats a bad (rotten) cookie it will lose half of the points collected so far.

Picture: The cookie monster playground.

The rules:

  • The game ends when all cookies are eaten
  • The team that has eaten more cookies is the winner
  • The teams move by turns
  • Only one of the two cookie monsters is allowed to move at once
  • It is only allowed to move one field - no jumping allowed
  • It can be moved in any direction (horizontally, vertically, diagonally)
  • A cookie will be eaten at the time a cookie monster steps on it
  • Two cookie monsters can not be at the same location at the same time
  • The sensor range of a cookie monster is restricted to its closests neighbor fields
  • The two members of a team are able to communicate to each others, but it is prohibited to gather information about the combatants that has not been intentionally provided.
  • Toxic fields do not smell.
  • Stepping on a toxic field makes a cookie monster lose all its points.
  • Eating a super cookie doubles the current points.
  • Eating a bad cookie make a cookie monster lose half of its points.

How to Install and Run the Cookie Monster Game
Download the Cookie Monster Game JAVA souce CookieMonster.zip and unzip it in an arbitrary directory on your machine. You will find a property file called cookiemonster.properties. You can play around with that file if you want to, but for the tournament the properties will all be fixed back to a default value.

Start it by typing java PerformGame cookiemonster.properties

You will see two cookie monster teams on a random walk as depicted on the picture above.
Additionally a second window opens as shown below. Each of the distributed cookies has a smell and this window shows its distribution. The square on the left shows the absolute values of the smell. The smell is the strongest at the location of the cookie (value 64) and decays against distance. The smell intensity is additive. For more clearness the square on the right shows the same smell distribution as graphical representation. (By the way, the smell distribution shown below corresponds to the distribution of the cookies as seen in the picture above.)

Picture: The cookie smell distribution on the board

The Assignment

Overview
You have to develop a own agent class analogical to the example class RandomWalkAgent.java or CommunicatingAgent.java by using the abstract agent class. You only have to hand in your new agent class that extends this abstract class! Therefore download and examine CookieMonster.zip.
The agents have to be able to communicate to each other and to use the smell of the cookies. Basically the work will be the overriding of the getMoveTo method. By calling this method the test scripts asks an agents about the next move. The two agents of a team have to decide then which one moves and its desired destination. More about the getMoveTo method is mentioned below.
It is important to give a unique name to your agent that it can be destinguished from other agents.

Description of the Application Components
The downloaded source of CookieMonster.zip contains following components:

*.gif

The pictures used by the graphical representation of the game

PerformGame

This is the test script that allows you to run your agents against others. By default PerformGame instances the RandomWalkAgent class in its main method. If you like to change the script to run your own agent class you have to rename RandomWalkAgent to myAgent in this file.

Environment

The task of this class is to manage all data about the cookies and the players.
Do not alter the source of this class. It is prohibited to access this class by your agent to gather more information than provided.

ShowView

This class represents the game board on screen.
Do not alter the source of this class.

ShowSmell

This class represents the smell distribution of the cookies on screen.
Do not alter the source of this class.

AbstractAgent

All agents extend this abstract class. This class provides the isMoveValid method that validates the desired move of an agent. It is strongly recommended to use this class like shown in the sample agent RandomWalkAgent. Additionally, this class forces you to implement the getMoveTo method in the well-defined structure. Do not alter the source of this class.

RandomWalkAgent

This is a very simple agent that may inspire you. It basically does a random walk on the board. It has no communication to its partner agent implemented.

CommunicatingAgent

This class implements a simple communication to its partner agent. It requests the location of the partner agent and writes it down to the console, but this agent does not move. This Agent class may inpires you how to set up the communication between the two partner agents. The communication can be extended to exchange any kind of Object.

AgentAndLocation

This class provides the communication object between the test script PerformGame and the agents. The method getMoveTo gives back this object to the test script. More about this class is mentioned below.

 

Details on the Agent Class

  1. The definition of the coordinate system is shown below. The origin (x, y) = (0. 0) is in the upper left corner.
  2. The test script PerformGame hands over some information about the environment to the agent by calling its getMoveTo(int[] currentLocation, int[] smell, int[] view) method.
    As first argument the agent gets its current location as a int array of lengt 2, representing the (x, y) coordinates on the board.
    The third argument contains the visual information (cookies and other agents) next to the agent. This information is passed by a int array of length 9. The definition of the array structure is shown in the figure below. The array values are defined as follows:
    0 <=> nothing
    1 <=> a cookie
    2 <=> a cookie monster of team A
    3 <=> a cookie monster of team B
    4 <=> a toxic field
    Picture: local coordinate representation
    The second argument passed to the agent is the smell information of the local area next to the agent. This information is passed in a int array of length 9 like seen above. The array values are integer representing the intensity of the smell. The higher the number, the more intense the smell.
  3. The getMoveTo method has to return the information which agent likes to move and the desired destination. This information is passed by an object. This object is an instance of the class AgentAndLocation. This class contains two variables. The first is the int variable agentNumber that represents which agent moves:
    o <=> The agent whose getMoveTo method has been called
    1 <=> The other agent.
    The second variable of the AgentAndLocation class is the desiredLocation int array of length 2 that represents the location as (x, y) tupel where the agent likes to move to. This two variables are accessed like shown in the sample Agent classes by agentAndLocation.agentNumber or agentAndLocation.desiredLocation.
  4. The agent class contains the information about the side length of the board in its variable sideLength.
  5. The agents might have a reference pointing to their partners. This reference is stored in the partnerAgent variable that may has been set at the start of the game by calling the method setPartner(MyAgent agent). This method has to be provided by the agent class. The reference to the partner agent allows communication to the other agent, resulting in more sophisticated move patterns.
    In order to be able to recognize the effectivity of the communication the agent has to be able to act without any reference to its partner agent (i.e. the Agent class has to be able to handle the case of parterAgent==null). The effectivity of communication is proven if the communicating agent team defeats the non-communicating team in the long run.

The Tournament

The tournament has no influence on the grading of the exercise. But there is a price to win for the team that develops the most effective agent team to clear up the cookies from the board.

The rules:

  • Every team will play against every team several times
  • The team that wins most is the winner
  • The size of the board will be changed
  • The number of cookies on the board will be changed
  • The relation toxic fields/cookies will remain unchanged (i.e. 1:5)
  • The range and the intensity of the smell of the cookies remains the same 

A team will be disqualified if:

  • they use functionalities of the package java.lang.reflect
  • they try to obtain information about the combatant objects that have not been intentionally provided
  • they try to cheat in any other way

Have fun!