13 package host.labyrinth;
168 int supplyFlag =0, moveFlag =1;
182 if (s < smin) smin = s;
183 if (o < omin) omin = o;
199 if (!
path.isEmpty()) {
200 Integer[] last =
path.get(
path.size()-1);
201 String who = String.format(
"%12s",
name);
202 System.out.print(who +
": score[" +
score +
"]" +
", dice =" + last[1] +
", tileId =" + last[0] +
" (" +
Position.
toRow(last[0]) +
", " +
Position.
toCol(last[0]) +
")");
204 System.out.println(
" *Can not move.");
205 else if (last[3] != 0)
206 System.out.println(
" *Found a supply.");
208 System.out.println(
"");
210 if (last[8] !=
Const.
noView) System.out.println(
" supply =" + last[8]);
211 else System.out.println(
" supply = blind");
212 if (last[9] !=
Const.
noView) System.out.println(
" opponent =" + last[9]);
213 else System.out.println(
" opponent = blind");
221 String who = String.format(
"%12s",
name);
222 System.out.println();
223 System.out.println(who +
": score[" +
score +
"]");
241 if (parent != null && parent.
getParent() != null)
285 for (
int dir = dirs.
get() ; dir !=
Const.
EOR ; dir = dirs.
get()) {
289 double eval =
evaluate (currentPos, dir, nodeBoard);
290 nodeMove =
dryMove (nodeBoard, currentPos, dir,
true);
292 Node child =
new Node (parent, depth, nodeMove, nodeBoard, eval);
317 for (
int dir = dirs.
get() ; dir !=
Const.
EOR ; dir = dirs.
get()) {
321 nodeMove =
dryMove (nodeBoard, oppCurrentPos, dir,
false);
329 Node child =
new Node (parent, depth, nodeMove, nodeBoard, eval);
350 double M = Double.NEGATIVE_INFINITY;
353 if (M < n.getNodeEvaluation()) {
354 M = n.getNodeEvaluation();
374 double m = Double.POSITIVE_INFINITY;
377 if (m > n.getNodeEvaluation()) {
378 m = n.getNodeEvaluation();
static final int RIGHT
East direction.
static final int MOVE_DICE
The index of dice information.
This class is the representation of the games's board.
Class to hold constant values for entire application.
static final double preMoveFactor
pre move distances factor
void setPath(Node path)
set path
int getOpponentId(int playerId)
Boards utility to give access to other player Id.
ArrayList< Node > getChildren()
get children
This class represents the game's minimax player.
Helper C++-like enumerator class to hold direction.
boolean champion
Champion indicate a player who plays against the Minotaur.
static final int End
Iterator style end of range direction (one place after the last)
int [] getNextMove(int currentPos)
Selects the best possible move to return.
int x
The column coordinate of the player on the board.
static final int minimaxTreeDepth
The maximum depth of the minimax tree.
static final int Step
Step for iterator style direction.
int [] dryMove(Board board, int currentPos, int dir, boolean champion)
A simulated move in a copy of the bard.
static final int MOVE_TILE_ID
Index of the tileId information of the move.
This class represents the game's player.
Board board
Reference to the session's boards.
int [] getNodeMove()
get nodeMove
void statistics()
Prints round information for the player.
Node chooseMinMaxMove(Node node)
Executes the minimax algorithm and return a reference to selected move.
int getNodeDepth()
get nodeDepth
static final double postMoveFactor
post move distances factor
static final double opponentFactor
Parameters to control move evaluation.
double getNodeEvaluation()
get nodeEvluation
static final int MOVE_DATA_SIZE
Helper variables to keep track of the move() return values.
static final double supplyFactor
supply distance factor
Helper C++ like enumerator class for direction ranged loops.
void createOppSubtree(int currentPos, int oppCurrentPos, Node parent, int depth)
One of the 2 recursive functions for creating the minimax tree.
int getId()
Read access to id coordinate.
double maxValue(Node node)
The Minimax recursive function for the maximizing part.
static final int MOVE_ROW
The index of row information.
static final int viewDistance
The max distance of the Heuristic player's ability to see.
double minValue(Node node)
The Minimax recursive function for the minimizing part.
int getRow()
Read access to virtual row coordinate.
int y
The row coordinate of the player on the board.
int getCol()
Read access to virtual column coordinate.
static int toRow(int id)
Takes Id coordinate and return the corresponding row coordinate.
int score
The current score of the player.
double evaluate(int currentPos, int direction, Board board)
This is the main move evaluation function.
void setNodeEvaluation(double nodeEvaluation)
set nodeEvaluation
static final int EOR
Number to indicate the End Of Range.
static int toCol(int id)
Takes Id coordinate and return the corresponding column coordinate.
Node object for minimax tree.
int supplyInDirection(int currentPos, int direction, Board board)
Utility to get the distance of a possible supply in some direction.
An Application wide board position implementation holding just the id coordinate. ...
int opponetInDirection(int currentPos, int direction, Board board)
Utility to get the distance of a possible opponent in some direction.
int [] move(int id)
MinMaxPlayer's move.
static final int NONE
No direction.
void createMySubtree(int currentPos, int oppCurrentPos, Node parent, int depth)
One of the 2 recursive functions for creating the minimax tree.
static final int noSupply
Number to indicate the absent of supply.
MinMaxPlayer(String name, boolean champion, Board board, int tileId)
Create a new player and put him at the row-column coordinates.
boolean hasSupply(int tileId)
Utility function to check if there is a supply on the tile or not.
boolean isWalkable(int tileId, int direction)
Predicate to check if a direction is Walkable.
static final int LEFT
West direction.
void final_statistics()
Prints final statistics for the player.
static final int UP
North direction.
void updateMove(int[] m, int playerId)
Utility to update the moves of each player.
String name
The name of the player.
static int opposite(int direction)
Utility to get the opposite direction.
MinMaxPlayer(String name, boolean champion, Board board, int row, int column)
Create a new player and put him at the row-column coordinates.
static final int DOWN
South direction.
int prevDirection(Node parent)
Get the previous direction of the player.
static final int Begin
Iterator style begin of range direction (starting north)
static final int MOVE_COLUMN
The index of column information.
boolean addChild(Node child)
Add a child to the tree.
ArrayList< Integer[]> path
our history.
Node getParent()
Get parent.
int [] getOpponentMove(int playerId)
Boards utility to give access to other player moves.
int tryPickSupply(int tileId)
Try to pick supply from a tile.
int playerId
The unique identifier of the player.
Class to create shuffled ranges of numbers.
Board getNodeBoard()
get nodeBoard
int get()
Extract and return the first item from the range.