CITS1001 PROJECT 2 Board Game - Tigers & Goats

CITS1001 PROJECT 2 Board Game - Tigers & Goats

Board Game - Tigers & Goats



In this Java project, you will implement a very basic board game that allows a human player to play

against the computer. You will use SimpleCanvas to display the board as the game progresses. To complete

the project, first read and understand the problem specification in the next section. Then study the

specification of project classes to understand how your implementation is to be structured.

A video of the game play (from the project solution) is provided on LMS.

3 Problem Description

Tigers & Goats is a simple game where one player controls 12 goats to trap 3 tigers to win i.e. the tigers

are unable make a valid move. The second player controls tigers to make simple moves or to jump over a

goat to eat it and reduce their numbers. Tigers win when the number of goats becomes less than 6, since

this is the minimum number required to trap all tigers. However, as the number of goats reduce from 12,

their chances of wining diminish rapidly. Figure 1 shows a snapshot of game play in stage 2. The circles

represent goats and the squares represent tigers. One of the goats has been eaten and hence there are

11 goats. Goats and tigers can move to an adjacent location connected by a straight line (red or white,

1

colour is only for cosmetic reasons). Valid locations (where a goat or tiger can be placed) are the corners

or intersection of lines.

A tiger can jump over a goat in a straight line to the next location and eat the goat in its way. The

destination location must be vacant for this to happen. In Figure 1, tiger 1 can jump over the goat to its

left as shown by the arrow. The goat in the way will be eaten and removed from the board. Tiger 2 is

blocked. It can neither move nor jump over (eat) any goat since there is no destination location to the

left, right or top and the bottom one is occupied by a goat. Goats can move to save themselves or their

fellow goats by occupying a location. Tiger 3 can eat the goat on its right.

The game starts with an empty board. In the first phase, players place their pieces only. Player one

(human) places 4 goats and then player two (computer) places 1 tiger. This process continues until 12

goats and 3 tigers have been placed on the board. Moving a piece is not allowed in this phase. In the

second phase, pieces can be moved only and no more pieces can be added to the board. Players take

one turn at a time from now on. Goats try to block the tigers and tigers try to avoid being blocked and

eat goats. You are required to complete the Java classes so that a human player can play against the

computer. The game should allow a human player to control the goats and should not allow the human to

make an illegal move. The game should automatically control the tigers implementing a simple strategy

to win. This is not that difficult since the computer controls more powerful pieces i.e. the tigers. All it

has to do is to not miss any chance of eating a goat.

4 Specification of Project Classes

In Figure 3, I have made a simple 2-D coordinate system for the board using a fixed block size. Each

corner or intersection of lines (called a location) is where a piece can be placed or moved to. Note that

not all coordinates are valide locations e.g. there is no 1,2 or 1,3 location on the board to place a piece.

There are 24 valid locations ([0] to [23]) that have been arranged in a 1-D array that start from the top

left and spirals inwards anti-clockwise. The 2-D coordinate system simplifies drawing of the board and

pieces. The 1-D array representation of the board simplifies maintaining the location of pieces (tigers and

goats), deciding which moves are legal and which jumps (eats) by tigers are legal.

The project is divided into 5 classes. One of them is SimpleCanvas which is provided to you. You do not

need to edit this class.

1. GameViewer: This class controls the drawing of the board and game play. It implements a mouse

listener to allow to human player to place goats and then to move them. It also checks that the

game rules a followed with the help of the GameRules class. It uses the Board class to maintain the

status of the board and the AIplayer class to make the tiger moves. GameViewer also declares the

winner of the game.

2. Board: This class maintains and updates the status of the board i.e. the locations of the tigers and

goats using a simple 1-D array of size 24 representing the valid locations of the board. This class

has accessor and mutator methods to query or alter the board at a specific location.

3. GameRules: This class maintains the game rules (legal or illegal moves), turns (goats turn or tigers

turn) and game stage (placement or movement of pieces). It also computes the nearest valid location

to a mouse click.

4. AIplayer: This class controls the tigers aiming to eat a goat whenever possible. Otherwise, it makes

a simple legal move or declares that it is unable to move any tiger.

2

Figure 1: Snaptshot of game play in the second stage where pieces can be moved only. Note that tiger 1

and 3 can eat a goat as shown by the arrow and tiger 2 is blocked.

You can choose your own colour scheme for the board, lines, pieces and text as long as they are visible.

Further details on the functionality of the classes and their methods can be found the skeleton code provided

as a zip file.

No JUnit test classes will be provided as you can test your code visually by playing the game. For example,

the goats should be placed so that they are exactly centred on the valid locations as long as the click was

in the vicinity of the location, it should not be possible to place a piece on top of another, the turns should

follow the game rules, the movement of goats/tigers should follow the game rules and so on.

4.1 Creativity

It is best to implement the required functionality first. If you have time and wish to extend your knowledge

of Java, then you are encouraged to extend this project. A few suggested extensions are below:

? Blink the goat a few times before it disappears from the board after being eaten.

? Make the placement of the tigers more strategic rather than random.

? Animate the movement of goats and tigers instead of sudden disappear and reappear.

? Allow the human to choose and play tigers instead of goats. Implement an automatic player class

that places the goats and then moves them strategically to block the tigers and avoid being eaten.

3

Figure 2: Snaptshot of game play where the goats have won by blocking all tigers. The tiger can neither

move nor eat any goat.

You can also identify and complete additional functionality as you wish. There are 30 marks for additional

functionality. These are not easy to get marks. If you implement all of the above and the goats can beat

a casual human player, you will get all 30 marks. However, these marks can only make up for marks that

you have lost in this project or elsewhere. You cannot get over 100 marks in this unit.

5 Project Management Tips

Before starting the project, students are expected to have

? studied the lectures and the relevant chapters of the text,

? completed the assigned labs during Weeks 2-9,

? read and understood the whole of this project description,

? read and understood all relevant UWA policies.

The Game of Life lecture and the Fifteen Puzzle lab will be helpful.

It is recommended that you tackle the project tasks in the order indicated; that you compile frequently;

and that you test and run the code after completing each method, to ensure your code behaves as you

think it ought. If you are stuck on a method, it is often a good idea to look in the lecture material, text

4

Figure 3: The board is represented by a 2D coordinate system using steps of block size. The top left

corner is 0,0 and the bottom right corner is 8,8. Not all coordinate locations are valid. For example, 1,2

is not a valid location to place a piece. There are 24 valid locations on the board.

book or lab solutions.

You can gain good marks even if you do not complete all the methods, so long as the code you have written

compiles and runs correctly. But if you submit a large body of code that does not compile or that crashes,

then few marks can be awarded.

5.1 Help

Timetabled lab sessions will run as usual during the project weeks and facilitators will be available to help

you at any of the lab sessions per week (see the CITS1001 timetable for lab time details). Remember this

project is to be done in pairs. Besides your project partner, you may discuss with the facilitators and

other students the general principles required to understand this project, but the Java code you submit

must be the result of your own effort (the two team members). Suspected academic misconduct will be

referred to the Academic Conduct Advisor for formal review.

Post any questions or requests for clarification to help1001 but do not post any project code on help1001.

5

5.2 Hints and Tips

Hints and tips about the various methods may be uploaded here from time to time. Whenever that happens,

the document version number will be updated.

1. In addition to following the TODO sequence, try to implement one functionality, from game play

point of view, at a time. For example, placement of goat, placement of tiger, movement of goat

(legal or illegal move), make a simple tiger move (legal of illegal), allow only legal moves and test if

all tigers are blocked.

2. You may need to implement a simpler version of a complicated method first and then revisit that

method to add more functionality.

3. The formula for calculating the distance between two points (x1, y1) and (x2, y2) is

d =

q

(x1 ? x2)

2 + (y1 ? y2)

2

发表评论

电子邮件地址不会被公开。 必填项已用*标注