|
|
@@ -47,58 +47,78 @@ public class Creature implements gr.auth.ee.dsproject.pacman.AbstractCreature |
|
|
|
/**
|
|
|
|
* @brief
|
|
|
|
* Create node for each one of the possible moves (0, 1, 2, 3) and
|
|
|
|
* evaluate these moves. After that feeds the valid ones to an ArrayList
|
|
|
|
* and select the best of them to return
|
|
|
|
* evaluate these moves.
|
|
|
|
*/
|
|
|
|
// public int calculateNextPacmanPosition (Room[][] Maze, int[] currPosition)
|
|
|
|
// {
|
|
|
|
// Node89978445 node = new Node89978445 (); // make a dummy node
|
|
|
|
// MinMaxTree rt = new MinMaxTree (node); /*<
|
|
|
|
// * Plant a tree with dummy root
|
|
|
|
// * Null parent and no evaluation
|
|
|
|
// */
|
|
|
|
//
|
|
|
|
// createSubTreePacman (0,node, Maze, currPosition);
|
|
|
|
// return 0;
|
|
|
|
// }
|
|
|
|
public int calculateNextPacmanPosition (Room[][] Maze, int[] currPosition)
|
|
|
|
{
|
|
|
|
Node89978445 cur = new Node89978445 (Maze, currPosition);
|
|
|
|
Node89978445 moveNode;
|
|
|
|
//ArrayList<Node89978445> moveNodes = new ArrayList<Node89978445> ();
|
|
|
|
double ev, max = Globals.NO_EVAL;
|
|
|
|
int decision = -1;
|
|
|
|
|
|
|
|
int[] nextPosition = {-1, -1};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* loop the possible moves and fill them to list
|
|
|
|
* mark the move with the maximum evaluation value
|
|
|
|
*/
|
|
|
|
for (int i=0 ; i<4 ; ++i) {
|
|
|
|
if ((nextPosition = Node89978445.pacmanValidMove(cur, i)) != Globals.FALSE_POS) {
|
|
|
|
moveNode = new Node89978445 (Maze, nextPosition);
|
|
|
|
ev = moveNode.getEvaluation();
|
|
|
|
if (ev > max) {
|
|
|
|
max = ev;
|
|
|
|
decision = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return decision;
|
|
|
|
}
|
|
|
|
|
|
|
|
void createSubTreePacman (int depth, Node89978445 parent, Room[][] Maze, int[] currPacmanPosition)
|
|
|
|
{
|
|
|
|
|
|
|
|
// TODO Fill This
|
|
|
|
|
|
|
|
}
|
|
|
|
public int calculateNextPacmanPosition (Room[][] Maze, int[] currPosition)
|
|
|
|
{
|
|
|
|
Node89978445 cur = new Node89978445 (Maze, currPosition);
|
|
|
|
MinMaxTree mmTree = new MinMaxTree (cur); /*<
|
|
|
|
* Plant a tree with dummy root
|
|
|
|
* Null parent and no evaluation
|
|
|
|
*/
|
|
|
|
|
|
|
|
createSubTreePacman (0, cur, Maze, currPosition); //make the tree
|
|
|
|
// min-max
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void createSubTreePacman (int depth, Node89978445 parent, Room[][] Maze, int[] curPacmanPosition)
|
|
|
|
{
|
|
|
|
if (++depth > Globals.MINMAXTREE_MAX_DEPTH)
|
|
|
|
return;
|
|
|
|
else {
|
|
|
|
Node89978445 newNode;
|
|
|
|
Room[][] newMaze;
|
|
|
|
int[] nextPosition = {-1, -1};
|
|
|
|
|
|
|
|
// scan possible valid moves
|
|
|
|
for (int move=0 ; move<4 ; ++move) {
|
|
|
|
if ((nextPosition = Node89978445.pacmanValidMove (parent, move)) != Globals.FALSE_POS) {
|
|
|
|
// Make a copy of the maze in order to simulate next move and move Pacman
|
|
|
|
newMaze = PacmanUtilities.copy (Maze);
|
|
|
|
PacmanUtilities.movePacman (newMaze, parent.getCurentPacmanPos(), nextPosition);
|
|
|
|
|
|
|
|
// Create a node for the move in the new stated game maze
|
|
|
|
newNode = new Node89978445 (newMaze, nextPosition);
|
|
|
|
newNode.getEvaluation();
|
|
|
|
MinMaxTree.insert (newNode, parent); // add node to the min-max tree
|
|
|
|
|
|
|
|
// call the recursive ranch creator
|
|
|
|
createSubTreeGhosts (depth, newNode, newMaze, newNode.getCurrentGhostPos());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void createSubTreeGhosts (int depth, Node89978445 parent, Room[][] Maze, int[][] currGhostsPosition)
|
|
|
|
{
|
|
|
|
// TODO Fill This
|
|
|
|
}
|
|
|
|
void createSubTreeGhosts (int depth, Node89978445 parent, Room[][] Maze, int[][] currGhostsPosition)
|
|
|
|
{
|
|
|
|
if (++depth > Globals.MINMAXTREE_MAX_DEPTH)
|
|
|
|
return;
|
|
|
|
else {
|
|
|
|
Node89978445 newNode;
|
|
|
|
Room[][] newMaze;
|
|
|
|
ArrayList<int[][]> ghostMoves;
|
|
|
|
|
|
|
|
// Get all possible ghost moves
|
|
|
|
ghostMoves = PacmanUtilities.allGhostMoves(Maze, currGhostsPosition);
|
|
|
|
|
|
|
|
// loop all ghost moves
|
|
|
|
int s = ghostMoves.size();
|
|
|
|
for (int i=0 ; i<s ; ++i) {
|
|
|
|
// Make a copy of the maze in order to simulate next move and move ghosts
|
|
|
|
newMaze = PacmanUtilities.copy (Maze);
|
|
|
|
PacmanUtilities.moveGhosts(newMaze, currGhostsPosition, ghostMoves.get(i));
|
|
|
|
|
|
|
|
// Create a node for the move in the new stated game maze
|
|
|
|
newNode = new Node89978445 (newMaze, parent.getCurentPacmanPos());
|
|
|
|
newNode.getEvaluation();
|
|
|
|
MinMaxTree.insert (newNode, parent); // add node to the min-max tree
|
|
|
|
|
|
|
|
//recursive call for the rest of the tree
|
|
|
|
//createSubTreePacman (depth, newNode, newMaze, parent.getCurentPacmanPos());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public int[] getPacPos (Room[][] Maze)
|
|
|
|
{
|
|
|
|