In this assignment, we will take the agent theme to a new and
interesting level by introducing a "game" aspect to the simulation.
Essentially, two players will own agents (pieces) and play a game.
Here are the details of the game:
- The "board" for the game is a 5 x 5 grid.
- There are two players (opponents) in the game, called
Player 1 and Player 2.
- Each player has five agents with which to start the game.
- Player 1's agents are numbered 0, 1, 2, 3 and 4. And Player 2's
agents are numbered 5, 6, 7, 8 and 9.
- Similar to chess, Player 1's agents are initially placed on the top-row
of the grid, and Player 2's agents are initially placed on the bottom-row of
the grid. You can decide the order of agents on the row.
- As before, an agent can move from its current cell to any of
the four neighboring cells (except when on the border of the grid,
in which case, there are fewer neighboring cells).
- An agent may not move into a cell occupied by another agent,
whether their own or the opponent's. An attempt to do so will
result in losing the game immediately!
- When an agent of Player1 moves to any cell in the bottom-row,
it is immediately and irretrievably removed from the game.
Similarly, when any agent of Player 2
moves to any cell in the top-row, the agent is immediately and
irretrievably removed from the game. Note that an agent can start
in column 2 and reach the opposite end-row in column 3 and be
removed - this is allowed.
- One objective of the game is to get as many your agents removed
from the game (by going to the row opposite to where you started).
Thus, Player 1 will try to get as many of her agents to the
bottom-row as possible, whereas Player 2 will try to get as many of
his agents to the top-row as possible.
- Each player scores 2 points for every agent removed.
- Now, of the five agents, one agent is designated to be a "Gladiator
agent" or Gladiagent.
- For Player 1, agent 0 will always be Player 1's gladiagent.
For Player 2, agent 5 will always be Player 1's gladiagent.
- A gladiagent can "eat" any non-gladiagent agent from the
opposing team. Once an ordinary agent (pawn agent) is eaten, it
disappears from the game.
- The gladiagents cannot eat each other or occupy the same cell.
- Eating can occur when the gladiagent is in a
neighboring cell of the agent to be eaten, and it is the
gladiagent-owning player's turn. Thus, if you've got your
gladiagent next to an opposing player's agent and it's your turn,
you can move your gladiagent into the victim-agent's cell and
eat it. If you move your gladiagent into such an agent's cell,
you will have to eat it (there's no choice).
- Eating an opposing player's agent gets a player 1 point for
every agent eaten. The player losing the agent gets no points.
- The overall goal is to score as many points as possible in
the time that game is played.
- The game will be played for some undetermined number of steps,
possibly 100 or 200 steps (turns). The game might end earlier if
both players are stuck or if all pieces are removed.
- There is a subtle point regarding scores. The game will end
if one of the players has no options in moving. For example,
suppose player 1's gladiagent eats player 2's agents, and player 2's
gladiagent is removed. Then, the game ends, even though player 1
still has agents that can be moved to the end. Thus, there is a
subtle tradeoff between spending your moves "being ravenous and
eating" and "shepherding your agents to the opposite side".
- You are free to write whatever code you want to compute your
next move for a player. However, your code cannot take longer
than 3 seconds to compute a move. We will terminate a move
after 3 seconds and declare the game over. If you are doing simple
things, this should not be a concern at all.
In terms of programming, the following points will help you
get started:
- You will implement both Player 1 and Player 2 separately.
The idea is, your "Player 1" implementation may be selected to
battle someone else's "Player 2" implementation (or the other way
around).
- To test your code, we will provide you with a simulator and GUI
so you can observe the results of your individual effort.
- The simulator has default implementations of Player 1 and
Player 2, called "House" versions (casino terminology).
Thus, you can select to play against the House version of Player 1,
in which case the simulator will upload your Player 2
and run the game. The House versions are named after Hozefa
Sadriwala and Amira Djebbari, former CS students
who helped develop the game.
- Download the following
jar file.
(Remember to use Netscape on Unix, and save to file).
- After you unpack, you will see a number of Java files.
- Most important among these files is the file Player.java.
Notice that this is an interface. Your player's
must implement these interfaces (but can have other methods).
To get started:
- Download the jar-file, unpack it and compile the source files.
- Run GameGui. This will bring up a frame with a menu.
One of these lets you run a "demo" in which you can observe the
default implementations battle it out.
- Now see what happens if you play the house as Player 2 (That
is, you are Player 2, and the house is Player 1). You will get
prompted for the name of your class file, so type "beavis2"
without the quotes (if your username is beavis2.)
- Important: You need to name your Java files carefully.
If your username is beavis then your Player 1 source file
should be called beavis1.java and your Player 2 source
file should be called beavis2.java.
- Next, your player files need to contain public classes by those names
and only one class in each file. Thus, the file
beavis1.java will have a public
class called beavis1 and no other classes. Similarly,
the file beavis2.java will have a public class
called beavis2 and no other classes. So, all your
code needs to be in these player classes.
- Important: your player classes must implement
the interface Player provided to you in the
file Player.java.
- All you really need to do is implement the two methods (with
the exact same signatures!) in the interface.
Via the methods, you will
get a chance to decide where you want to place your agents on the
start row and, when the game proceeds, you get a chance to decide
where to move agents.
- The simulator will call your getInitialPosition()
method repeatedly to ask you where you want the agents initially
placed. It will check to make sure that you use a legal start
position.
- After the game starts, the simulator will call your
move() method and expect to get back three things (all
three of which are returned in a Position instance.
These three things are: (1) which agent are you going to move;
(2) The X value of the desired position; and (3) the Y value of
the desired position. Again, the simulator will check to make sure
the move is legal, i.e., it will check to see if the cell is vacant,
if your agent can actually move there etc.
- If you discover you cannot move, you should return
null.
- Important: Any illegal move will cost you the game.
- All the Java documentation you need is provided here:
- To discover positions of agents on the board (which is
maintained by the simulator), call the static
getAgentID()
method of the class
Game. Do NOT create an
instance of
Game.
- OK, now implement your players!
Deliverables:
- The source code for program. NOTE: FOR CONVENIENCE OF GRADING
PLEASE WRITE ALL YOUR CODE IN THE TWO FILES named in the way
described above. If you write any additional classes, please name
them uniquely by embedding your username in the name of the class.
For example, if you create a "sort" class, call it
BeavisSort.
This way, the simulator will be sure to load only your classes.
- Your code will be graded
on correctness, documentation and game score.
- Important: Include only your two player files in the tar-file.
Submission:
- The name of subdirectory for this exercise should be: your username
followed by _a4.
,
- Follow the
submission instructions carefully as usual.
- Submit a printout (hardcopy) of your code before
the due date in my mailbox.