You are to write an artificial intelligence for a game called Sugargame.
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. Neither player should assume
anything about the initial positions of the other player's agents.
* The top row's cells are numbered (0,0), (1,0) ... (4,0) and the bottom row's
cells are numbered (0,4), (1,4) ... (4,4).
* 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!
* Some cells will contain sugar, others won't. The amounts of sugar will vary
across cells, and will change during the game. One objective of the game is
to "grab" as much sugar as possible. The total amount of sugar grabbed
by a player's agents will be included in the score for a game.
* When an agent belonging to one player is "surrounded" by by agents
from the other player, the agent is removed from the game ("killed").
We will define "surrounded" as follows: the four neighboring cells
contain two or more agents from the opposing team. Therefore, another objective
of the game is minimize your losses while inflicting as much loss as possible
on the opponent.
* If an agent of yours is killed, you may not attempt to move that agent again.
It's up to you to discover when your agent gets killed. You will lose the game
if you try to move a "killed" player.
* One interesting situation arises when it's your turn and you move an agent
so that an opposing agent is between two of yours. Suppose it so happens that
the move you did places your newly moved agent between two opposing agents,
then do both agents (yours and the opposing one) get killed? The rule here is,
if it's your turn, you have the "element of surprise" and your agent,
the one that just moved, does not get killed even if it moves to a position
where it's surrounded by opposing agents. However, it could get killed in the
next turn, so you do need to careful.
* The score for a player is computed as follows. One point for each unit of
sugar acquired, 50 points for each opposing agent killed. You lose 50 points
for each agent from your side that is killed.
* 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.
* 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 or "house" (casino terminology) implementations
of Player 1 and Player 2, named after my TA's. 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.
To get started:
1. Download the following jar file and "save to
file". If you are not familiar with jar files you download
this zip file.
2. Unpack the jar/zip file.
3. Before you implement anything, you can run the Game Simulator to see what
it looks like, and to play one TA against the other. To run:
java SugarGameSimulator
Note that you can run this on any Unix machine in Tompkins 405, but not on
hobbes. To run this on a T411 machine, you will need to bring up a DOS prompt
and run it from there.
4. Most of what you need is in the second menu, called "Simulation".
If you drop this down, you can pick a combination of TA vs. TA in the second
set of menu items. Once you pick one, come back to the menu and click on "Start"
to start the game.
5. You can also set the animation speed and number of time steps.
6. 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 "beavis" without the quotes (if your username
is beavis.)
7. 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.
8. 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.
9. Important: your player classes must implement the interface Player provided
to you in the file Player.java.
10. 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.
11. 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.
12. 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 an AgentPosition
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.
13. Note: the class AgentPosition extends Position so that all you need to work
with is the AgentPosition class. You will need to return a fresh instance of
this class each time your move() method is called by the simulator.
14. If you discover you cannot move, you should return null.
15. Important: Any illegal move will cost you the game.
16. All the Java documentation you need is provided here:
* The Player interface.
* The AgentPosition class.
* The Position class.
* The SugarGame class.
17. To discover positions of agents on the board (which is maintained by the
simulator), call the static getAgentID() method of the class SugarGame. Do NOT
create an instance of SugarGame.
18. Similarly, you can discover the amount of sugar in a cell by called the
static getSugarAmount() method in SugarGame.
19. You can tell whether an agent is alive by calling the static isStillAlive()
method of SugarGame.
20. When you've implemented your Player1 and Player 2 strategies, you can can
run the simulator to run your players against the House. This can be done in
the first section of the "Simulation" menu.
21. OK, now implement your players!
Deliverables:
1. You must submit a design for your player 1 and 2 (it can be the same design with just different starting positions). This design must be thorough to the level as discussed of your last two labs. This is the part will be graded up to 8/10 lab points and must be implemented.
2. You must submit a zip file containing your source and class files named as mentioned above username1 for player one, username2 for player 2 , any additional classes would be usernameClass name. Your implementation must follow your design (If you change your initial design let me know in your lab report!)
The remaining 2 points will be assigned as follows:
In addition to setting your player up against your class mates you will be playing
against:
Rizwan - my old TA
Justin - my old TA
Me -....your TA's code from 3 years ago
Mike Huneke - the winner from my class when I did this project
Last Place: 0 Points
Bottom 25% .5 Points
Bottom 50% 1 Point
Bottom 75% 1.5 Points
Bottom 99% 1.75 Points
Winner: 2 Points
Don't let 3 year old code beat yours!!!