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

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

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

Protected Attributes

Class data
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...
 

Package Functions

Constructors
 Player (String name, boolean champion, Board board, int row, int column)
 Create a new player and put him at the row-column coordinates. More...
 
 Player (String name, boolean champion, Board board, int tileId)
 Create a new player and put him at the row-column coordinates. More...
 
Player main application interface
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...
 

Accessor/Mutator interface

Note
Please consider not to use mutator interface. Its the abstraction killer :( We have added a bit of logic however, in order to make it a bit more safe.
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)
 

Detailed Description

This class represents the game's player.

Definition at line 21 of file Player.java.

Constructor & Destructor Documentation

◆ Player() [1/2]

host.labyrinth.Player.Player ( String  name,
boolean  champion,
Board  board,
int  row,
int  column 
)
package

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 33 of file Player.java.

◆ Player() [2/2]

host.labyrinth.Player.Player ( String  name,
boolean  champion,
Board  board,
int  tileId 
)
package

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 56 of file Player.java.

Member Function Documentation

◆ final_statistics()

void host.labyrinth.Player.final_statistics ( )
package

Prints final statistics for the player.

Note
We add this final_statistics() wrapper in order to provide polymorphism to Player class hierarchy and to be sure that we are not braking the Liskov substitution principle
See also
https://en.wikipedia.org/wiki/Liskov_substitution_principle

Definition at line 153 of file Player.java.

◆ getBoard()

Board host.labyrinth.Player.getBoard ( )
package

Definition at line 172 of file Player.java.

◆ getChampion()

boolean host.labyrinth.Player.getChampion ( )
package

Definition at line 176 of file Player.java.

◆ getDirCounter()

int [] host.labyrinth.Player.getDirCounter ( )
package

Definition at line 177 of file Player.java.

◆ getName()

String host.labyrinth.Player.getName ( )
package

Definition at line 171 of file Player.java.

◆ getPath()

ArrayList<Integer[]> host.labyrinth.Player.getPath ( )
package

Definition at line 178 of file Player.java.

◆ getPlayerId()

int host.labyrinth.Player.getPlayerId ( )
package

Definition at line 170 of file Player.java.

◆ getScore()

int host.labyrinth.Player.getScore ( )
package

Definition at line 173 of file Player.java.

◆ getX()

int host.labyrinth.Player.getX ( )
package

Definition at line 174 of file Player.java.

◆ getY()

int host.labyrinth.Player.getY ( )
package

Definition at line 175 of file Player.java.

◆ move()

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

Player's move.

A player first throws a dice to get a random direction. Then checks if the direction is walkable. If it is, then goes to that tile and update player's data. 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[1]: The supplyId in case player picked one (Const.noSupply otherwise).

Definition at line 93 of file Player.java.

◆ playerCol()

int host.labyrinth.Player.playerCol ( )
package

Utility to access player's column position (column coordinate)

Definition at line 160 of file Player.java.

◆ playerRow()

int host.labyrinth.Player.playerRow ( )
package

Utility to access player's row position (row coordinate)

Definition at line 158 of file Player.java.

◆ playerTileId()

int host.labyrinth.Player.playerTileId ( )
package

Utility to access player's tileID.

Definition at line 156 of file Player.java.

◆ setBoard()

void host.labyrinth.Player.setBoard ( Board  board)
package

Definition at line 185 of file Player.java.

◆ setChampion()

void host.labyrinth.Player.setChampion ( boolean  champion)
package

Definition at line 195 of file Player.java.

◆ setDirCounter()

void host.labyrinth.Player.setDirCounter ( int []  dirCounter)

Definition at line 198 of file Player.java.

◆ setName()

void host.labyrinth.Player.setName ( String  name)
package

Definition at line 184 of file Player.java.

◆ setPath()

void host.labyrinth.Player.setPath ( ArrayList< Integer[]>  path)

Definition at line 202 of file Player.java.

◆ setPlayerId()

void host.labyrinth.Player.setPlayerId ( int  id)
package

Definition at line 183 of file Player.java.

◆ setScore()

void host.labyrinth.Player.setScore ( int  score)
package

Definition at line 186 of file Player.java.

◆ setX()

void host.labyrinth.Player.setX ( int  x)
package

Definition at line 187 of file Player.java.

◆ setY()

void host.labyrinth.Player.setY ( int  y)
package

Definition at line 191 of file Player.java.

◆ statistics()

void host.labyrinth.Player.statistics ( )
package

Prints round information for the player.

Definition at line 131 of file Player.java.

Member Data Documentation

◆ board

Board host.labyrinth.Player.board
protected

Reference to the session's boards.

Definition at line 211 of file Player.java.

◆ champion

boolean host.labyrinth.Player.champion
protected

Champion indicate a player who plays against the Minotaur.

Definition at line 215 of file Player.java.

◆ dirCounter

int host.labyrinth.Player.dirCounter[]
protected

Definition at line 216 of file Player.java.

◆ name

String host.labyrinth.Player.name
protected

The name of the player.

Definition at line 210 of file Player.java.

◆ path

ArrayList<Integer[]> host.labyrinth.Player.path
protected

our history.

The integer[] format is:

  • Integer[0]: tileId - The tile id we choose for the move
  • Integer[1]: dice - The dice (a.k.a direction) of move
  • Integer[2]: moveStatus - True if it was successful (we can move in that direction)
  • Integer[3]: tookSupply - True if we took supply
  • Integer[4]: upCounter - Accumulator to count all the up moves
  • Integer[5]: righrCounter - Accumulator to count all the right moves
  • Integer[6]: downCounter - Accumulator to count all the down moves
  • Integer[7]: leftCounter - Accumulator to count all the left moves
  • Integer[8]: SupDistance - The distance of the nearest supply (only for heuristic players)
  • Integer[9]: OppDistance - The distance of the nearest opponent (only for heuristic players)

}

Definition at line 217 of file Player.java.

◆ playerId

int host.labyrinth.Player.playerId
protected

The unique identifier of the player.

Definition at line 209 of file Player.java.

◆ score

int host.labyrinth.Player.score
protected

The current score of the player.

Definition at line 212 of file Player.java.

◆ x

int host.labyrinth.Player.x
protected

The column coordinate of the player on the board.

Definition at line 213 of file Player.java.

◆ y

int host.labyrinth.Player.y
protected

The row coordinate of the player on the board.

Definition at line 214 of file Player.java.


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