game

Class TestBoard

Implemented Interfaces:
Comparable, Comparator, Transport

public class TestBoard
extends java.lang.Object
implements Transport, Comparator, Comparable

Defines the board for the game. The main workhorse of the game.
Version:
2.4 (19-APR-2010)
Author:
Shashi Mittal

Fields inherited from interface game.Transport

BLACK, BUS, FERRY, INF, NONE, TAXI, UG

Method Summary

void
changeDetectivePosition(int i, Move move)
This method is used to change the position of a detective
int
compare(Object b1, Object b2)
This method compares two objects of this class depending on the score of the boards
int
compareTo(Object o)
This method compares this board to another board o
boolean
equal(TestBoard b1, TestBoard b2)
This method checks whether two boards are equal
int
getCurrentMoves()
This method returns the currentMoves of this object.
TreeSet
getDetectivePossibleMoves(int i)
This method returns all the possible moves for a given detective
Detective[]
getDetectives()
This method is used to get the detectives of this board.
Fugitive
getMrX()
This method is used to get the MrX of this object.
static int
getNumberOfDetectives()
Point
getPoint(int nodeIndex)
Returns the pixel coordinates of the specified node on the map.
boolean
isCheckPoint()
This method checks if Mr.
boolean
isCheckPoint(int move)
This method checks if Mr.
boolean
isMachineWin()
Checks whether the machine has won
boolean
isUserWin()
Checks if the user has won
Move
moveMrX()
This method computes a move for Mr.
void
printBoard()
This method prints the board i.e what are the nodes what are the links.
void
printPossibleDetectiveMoves()
Prints all the possible detective moves for the current board positions of the detectives, together with the corresponding scores for each new positions of the detectives.
void
setDepth(int d)
This method changes the difficulty level for the game
void
test()
Prints the shortest distance matrix
String
toString()
String representation of this board.

Method Details

changeDetectivePosition

public void changeDetectivePosition(int i,
                                    Move move)
This method is used to change the position of a detective
Parameters:
i - the index of the detective whose position we want to change
move - the new move for this detective

compare

public int compare(Object b1,
                   Object b2)
This method compares two objects of this class depending on the score of the boards
Parameters:
b1 - the first board
b2 - the second board
Returns:
negative if score of b1 less then score of b2 positive otherwise

compareTo

public int compareTo(Object o)
This method compares this board to another board o
Parameters:
o - the board with which this is to be compared
Returns:
similar to the compare() method

equal

public boolean equal(TestBoard b1,
                     TestBoard b2)
This method checks whether two boards are equal
Parameters:
b1 - the first board
b2 - the second board
Returns:
true if the boards are equal,false otherwise

getCurrentMoves

public int getCurrentMoves()
This method returns the currentMoves of this object.
Returns:
the currentMoves of this object

getDetectivePossibleMoves

public TreeSet getDetectivePossibleMoves(int i)
This method returns all the possible moves for a given detective
Parameters:
i - the detective index of the detective whose possible moves we want
Returns:
the possible moves of this detective in a TreeSet. If this detective cannot move, it returns null.

getDetectives

public Detective[] getDetectives()
This method is used to get the detectives of this board.
Returns:
the array containing the detectives of the current game.

getMrX

public Fugitive getMrX()
This method is used to get the MrX of this object.
Returns:
the MrX of this object.

getNumberOfDetectives

public static int getNumberOfDetectives()

getPoint

public Point getPoint(int nodeIndex)
Returns the pixel coordinates of the specified node on the map.

isCheckPoint

public boolean isCheckPoint()
This method checks if Mr. X has to reveal his position at this move or not.
Returns:
true if Mr. X has to reveal himself at this move, false otherwise.

isCheckPoint

public boolean isCheckPoint(int move)
This method checks if Mr. X has to reveal his position at a given move or not
Parameters:
move - the index of the move for which we want to check if it is a checkpoint
Returns:
true if move is a checkpoint, false otherwise

isMachineWin

public boolean isMachineWin()
Checks whether the machine has won
Returns:
true if machine has won,otherwise false

isUserWin

public boolean isUserWin()
Checks if the user has won
Returns:
true if the user has won, otherwise false

moveMrX

public Move moveMrX()
This method computes a move for Mr. X and returns that move.
Returns:
The move computed for Mr. X.

printBoard

public void printBoard()
This method prints the board i.e what are the nodes what are the links. It is useful for testing if the map which has been entered is correct or not

printPossibleDetectiveMoves

public void printPossibleDetectiveMoves()
Prints all the possible detective moves for the current board positions of the detectives, together with the corresponding scores for each new positions of the detectives.

setDepth

public void setDepth(int d)
This method changes the difficulty level for the game
Parameters:
d - the required difficulty level

test

public void test()
Prints the shortest distance matrix

toString

public String toString()
String representation of this board.
Returns:
the score of this board in String form.