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

This class represents the game's minimax player. More...

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

Public Member Functions

Constructors
 MinMaxPlayer (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...
 
 MinMaxPlayer (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, Board board)
 Utility to get the distance of a possible supply in some direction. More...
 
int opponetInDirection (int currentPos, int direction, Board board)
 Utility to get the distance of a possible opponent in some direction. More...
 
double evaluate (int currentPos, int direction, Board board)
 This is the main move evaluation function. More...
 
Node chooseMinMaxMove (Node node)
 Executes the minimax algorithm and return a reference to selected move. More...
 
int [] getNextMove (int currentPos)
 Selects the best possible move to return. More...
 
int [] move (int id)
 MinMaxPlayer'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

Minimax algorithm related part
int prevDirection (Node parent)
 Get the previous direction of the player. More...
 
int [] dryMove (Board board, int currentPos, int dir, boolean champion)
 A simulated move in a copy of the bard. More...
 
void createMySubtree (int currentPos, int oppCurrentPos, Node parent, int depth)
 One of the 2 recursive functions for creating the minimax tree. More...
 
void createOppSubtree (int currentPos, int oppCurrentPos, Node parent, int depth)
 One of the 2 recursive functions for creating the minimax tree. More...
 
double maxValue (Node node)
 The Minimax recursive function for the maximizing part. More...
 
double minValue (Node node)
 The Minimax recursive function for the minimizing part. 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 minimax player.

Definition at line 19 of file MinMaxPlayer.java.

Constructor & Destructor Documentation

◆ MinMaxPlayer() [1/2]

host.labyrinth.MinMaxPlayer.MinMaxPlayer ( 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 MinMaxPlayer.java.

◆ MinMaxPlayer() [2/2]

host.labyrinth.MinMaxPlayer.MinMaxPlayer ( 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 MinMaxPlayer.java.

Member Function Documentation

◆ chooseMinMaxMove()

Node host.labyrinth.MinMaxPlayer.chooseMinMaxMove ( Node  node)
package

Executes the minimax algorithm and return a reference to selected move.

Parameters
nodeThe root node to start
Returns
Reference to the selected move

Definition at line 122 of file MinMaxPlayer.java.

◆ createMySubtree()

void host.labyrinth.MinMaxPlayer.createMySubtree ( int  currentPos,
int  oppCurrentPos,
Node  parent,
int  depth 
)
private

One of the 2 recursive functions for creating the minimax tree.

This one creates children for the MinMax player.

Parameters
parentThe parent Node
depthThe current depth for the children
currentPosThe tile of MinMax player
oppCurrentPosThe tile of the opponent
Note
Even though unnecessary we calculate the evaluation for every node and not only for the leafs. This follows the exercise instructions. We could also rely on lazy evaluation of "evaluation()" and use AB pruning but the depth of the tree is not worth the try.

Definition at line 281 of file MinMaxPlayer.java.

◆ createOppSubtree()

void host.labyrinth.MinMaxPlayer.createOppSubtree ( int  currentPos,
int  oppCurrentPos,
Node  parent,
int  depth 
)
private

One of the 2 recursive functions for creating the minimax tree.

This one creates children for the opponent player.

Parameters
parentThe parent Node
depthThe current depth for the children
currentPosThe tile of MinMax player
oppCurrentPosThe tile of the opponent
Note
Even though unnecessary we calculate the evaluation for every node and not only for the leafs. This follows the exercise instructions. We could also rely on lazy evaluation of "evaluation()" and use AB pruning but the depth of the tree is not worth the try.

Definition at line 313 of file MinMaxPlayer.java.

◆ dryMove()

int [] host.labyrinth.MinMaxPlayer.dryMove ( Board  board,
int  currentPos,
int  dir,
boolean  champion 
)
private

A simulated move in a copy of the bard.

Parameters
boardThe board on witch we simulate the move
currentPosThe current position of the player to the board
dirThe direction of the move
championFlag to indicate if the player is champion or not
Returns
The move array

Definition at line 255 of file MinMaxPlayer.java.

◆ evaluate()

double host.labyrinth.MinMaxPlayer.evaluate ( int  currentPos,
int  direction,
Board  board 
)
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
boardReference to the Board object to use
Returns
A signed real number. The higher the output, the higher the evaluation.

Definition at line 103 of file MinMaxPlayer.java.

◆ final_statistics()

void host.labyrinth.MinMaxPlayer.final_statistics ( )
package

Prints final statistics for the player.

Definition at line 220 of file MinMaxPlayer.java.

◆ getNextMove()

int [] host.labyrinth.MinMaxPlayer.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 135 of file MinMaxPlayer.java.

◆ maxValue()

double host.labyrinth.MinMaxPlayer.maxValue ( Node  node)
private

The Minimax recursive function for the maximizing part.

Parameters
nodeThe current Node
Returns
The selected Node

Definition at line 344 of file MinMaxPlayer.java.

◆ minValue()

double host.labyrinth.MinMaxPlayer.minValue ( Node  node)
private

The Minimax recursive function for the minimizing part.

Parameters
nodeThe current Node
Returns
The selected Node

Definition at line 368 of file MinMaxPlayer.java.

◆ move()

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

MinMaxPlayer'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 162 of file MinMaxPlayer.java.

◆ opponetInDirection()

int host.labyrinth.MinMaxPlayer.opponetInDirection ( int  currentPos,
int  direction,
Board  board 
)
package

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

Parameters
currentPosThe current position of the player
directionThe direction to check
boardReference to the Board object to use
Returns
The distance or Const.noView

Definition at line 80 of file MinMaxPlayer.java.

◆ prevDirection()

int host.labyrinth.MinMaxPlayer.prevDirection ( Node  parent)
private

Get the previous direction of the player.

Parameters
parentReference to previous nNode
Returns
The previous direction if exist, else return Direction.NONE

Definition at line 240 of file MinMaxPlayer.java.

◆ statistics()

void host.labyrinth.MinMaxPlayer.statistics ( )
package

Prints round information for the player.

Definition at line 198 of file MinMaxPlayer.java.

◆ supplyInDirection()

int host.labyrinth.MinMaxPlayer.supplyInDirection ( int  currentPos,
int  direction,
Board  board 
)
package

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

Parameters
currentPosThe current position of the player
directionThe direction to check
boardReference to the Board object to use
Returns
The distance or Const.noView

Definition at line 58 of file MinMaxPlayer.java.


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