Labyrinth
A labyrinth game assignment
host.labyrinth.HeuristicPlayer Class Reference

This class represents the game's player who cheats. More...

Inheritance diagram for host.labyrinth.HeuristicPlayer:
host.labyrinth.Player

Public Member Functions

Constructors
 HeuristicPlayer (String name, boolean champion, Board board, int row, int column) throws Exception
 Create a new player and put him at the row-column coordinates. More...
 
 HeuristicPlayer (String name, boolean champion, Board board, int tileId) throws Exception
 Create a new player and put him at the row-column coordinates. More...
 

Package Functions

Board's main application interface
int supplyInDirection (int currentPos, int direction)
 Utility to get the distance of a possible supply in some direction. More...
 
int opponetInDirection (int currentPos, int direction)
 Utility to get the distance of a possible opponent in some direction. More...
 
double evaluate (int currentPos, int direction)
 This is the main move evaluation function. More...
 
int [] getNextMove (int currentPos)
 Selects the best possible move to return. More...
 
int [] move (int id)
 HeuristicPlayer's move. More...
 
void statistics ()
 Prints round information for the player. More...
 
void final_statistics ()
 Prints final statistics for the player. More...
 
- Package Functions inherited from host.labyrinth.Player
 Player (String name, boolean champion, Board board, int row, int column) throws Exception
 Create a new player and put him at the row-column coordinates. More...
 
 Player (String name, boolean champion, Board board, int tileId) throws Exception
 Create a new player and put him at the row-column coordinates. More...
 
int [] move (int id)
 Player's move. More...
 
void statistics ()
 Prints round information for the player. More...
 
void final_statistics ()
 Prints final statistics for the player. More...
 
int playerTileId ()
 Utility to access player's tileID. More...
 
int playerRow ()
 Utility to access player's row position (row coordinate) More...
 
int playerCol ()
 Utility to access player's column position (column coordinate) More...
 
int getPlayerId ()
 
String getName ()
 
Board getBoard ()
 
int getScore ()
 
int getX ()
 
int getY ()
 
boolean getChampion ()
 
int [] getDirCounter ()
 
ArrayList< Integer[]> getPath ()
 
void setPlayerId (int id)
 
void setName (String name)
 
void setBoard (Board board)
 
void setScore (int score)
 
void setX (int x)
 
void setY (int y)
 
void setChampion (boolean champion)
 
void setDirCounter (int[] dirCounter)
 
void setPath (ArrayList< Integer[]> path)
 

Private Member Functions

int directionOfMax (double[] eval, int[] eval_dir, int N)
 A small utility to extract the direction of maximum evaluation result. More...
 
boolean isUnevaluated (double[] eval, int N)
 A small utility to check if there is at least one evaluation result in the eval array. More...
 

Additional Inherited Members

- Protected Attributes inherited from host.labyrinth.Player
int playerId
 The unique identifier of the player. More...
 
String name
 The name of the player. More...
 
Board board
 Reference to the session's boards. More...
 
int score
 The current score of the player. More...
 
int x
 The column coordinate of the player on the board. More...
 
int y
 The row coordinate of the player on the board. More...
 
boolean champion
 Champion indicate a player who plays against the Minotaur. More...
 
int dirCounter []
 
ArrayList< Integer[]> path
 our history. More...
 
- Static Package Attributes inherited from host.labyrinth.Player
static final int MOVE_DATA_SIZE = 4
 Helper variables to keep track of the move() return values. More...
 
static final int MOVE_TILE_ID = 0
 Index of the tileId information of the move. More...
 
static final int MOVE_ROW = 1
 The index of row information. More...
 
static final int MOVE_COLUMN = 2
 The index of column information. More...
 
static final int MOVE_DICE = 3
 The index of dice information. More...
 

Detailed Description

This class represents the game's player who cheats.

Definition at line 19 of file HeuristicPlayer.java.

Constructor & Destructor Documentation

◆ HeuristicPlayer() [1/2]

host.labyrinth.HeuristicPlayer.HeuristicPlayer ( String  name,
boolean  champion,
Board  board,
int  row,
int  column 
) throws Exception

Create a new player and put him at the row-column coordinates.

Parameters
nameThe name of the player
championFlag to indicate if a player is a champion
boardReference to the board of the game
rowThe row coordinate of initial player position
columnThe column coordinate of initial player's position

Definition at line 32 of file HeuristicPlayer.java.

◆ HeuristicPlayer() [2/2]

host.labyrinth.HeuristicPlayer.HeuristicPlayer ( String  name,
boolean  champion,
Board  board,
int  tileId 
) throws Exception

Create a new player and put him at the row-column coordinates.

Parameters
nameThe name of the player
championFlag to indicate if a player is a champion
boardReference to the board of the game
tileIdThe tileId coordinate of player's initial position

Definition at line 43 of file HeuristicPlayer.java.

Member Function Documentation

◆ directionOfMax()

int host.labyrinth.HeuristicPlayer.directionOfMax ( double []  eval,
int []  eval_dir,
int  N 
)
private

A small utility to extract the direction of maximum evaluation result.

We search into the eval results and find the index of the maximum evaluation. Then we return the direction of eval_dir matrix at the same index we found.

Parameters
evalArray with evaluation results for each direction
eval_dirArray with the matching direction to eval array
NThe size of both arrays
Returns
The direction of maximum evaluation. If eval is empty returns the first item eval[0]
Note
This function should not be called if there is at least one evaluation result in eval

Definition at line 240 of file HeuristicPlayer.java.

◆ evaluate()

double host.labyrinth.HeuristicPlayer.evaluate ( int  currentPos,
int  direction 
)
package

This is the main move evaluation function.

Parameters
currentPosThe current position of the player (before the move to evaluate)
directionThe direction (a.k.a. the move) to evaluate
Returns
A signed real number. The higher the output, the higher the evaluation.

Definition at line 92 of file HeuristicPlayer.java.

◆ final_statistics()

void host.labyrinth.HeuristicPlayer.final_statistics ( )
package

Prints final statistics for the player.

Definition at line 215 of file HeuristicPlayer.java.

◆ getNextMove()

int [] host.labyrinth.HeuristicPlayer.getNextMove ( int  currentPos)
package

Selects the best possible move to return.

Parameters
currentPosPlayer's current position to the board
Returns
The move array
Note
This function always return a new move.

Definition at line 111 of file HeuristicPlayer.java.

◆ isUnevaluated()

boolean host.labyrinth.HeuristicPlayer.isUnevaluated ( double []  eval,
int  N 
)
private

A small utility to check if there is at least one evaluation result in the eval array.

Parameters
evalThe array to check
NThe size of the array
Returns
True if there is none, false otherwise

Definition at line 258 of file HeuristicPlayer.java.

◆ move()

int [] host.labyrinth.HeuristicPlayer.move ( int  id)
package

HeuristicPlayer's move.

A player of this kind cheats. He does not throw a dice to get a direction. In contrary he calculates his next move very carefully. If the player is a champion then he also picks up a possible supply from the tile.

Parameters
idThe id of the starting tile.
Returns
An array containing player's final position and possible supply of that position. The array format is:
  • int[0]: The tileId of the final player's position.
  • int[1]: The row of the final player's position.
  • int[2]: The column of the final player's position.
  • int[3]: The dice/direction of the move.

Definition at line 157 of file HeuristicPlayer.java.

◆ opponetInDirection()

int host.labyrinth.HeuristicPlayer.opponetInDirection ( int  currentPos,
int  direction 
)
package

Utility to get the distance of a possible opponent in some direction.

Parameters
currentPosThe current position of the player
directionThe direction to check
Returns
The distance or Const.noOpponent

Definition at line 74 of file HeuristicPlayer.java.

◆ statistics()

void host.labyrinth.HeuristicPlayer.statistics ( )
package

Prints round information for the player.

Definition at line 193 of file HeuristicPlayer.java.

◆ supplyInDirection()

int host.labyrinth.HeuristicPlayer.supplyInDirection ( int  currentPos,
int  direction 
)
package

Utility to get the distance of a possible supply in some direction.

Parameters
currentPosThe current position of the player
directionThe direction to check
Returns
The distance or Const.noSupply

Definition at line 57 of file HeuristicPlayer.java.


The documentation for this class was generated from the following file: