From 27ad8b6f4045e09f747d8becfb4240bfda0712d2 Mon Sep 17 00:00:00 2001 From: Christos Houtouridis Date: Tue, 16 Jan 2018 15:48:29 +0200 Subject: [PATCH] DEV: A first semi-working version with tree --- .classpath | 0 .project | 0 .settings/org.eclipse.jdt.core.prefs | 0 GameLog.txt | 28 +++ bin/.gitignore | 0 .../auth/ee/dsproject/pacman/Creature.class | Bin 6430 -> 6515 bytes ghosts.gif | Bin lib/pacman.jar | Bin pacman.gif | Bin src/gr/auth/ee/dsproject/node/Globals.java | 4 +- src/gr/auth/ee/dsproject/node/MinMaxTree.java | 115 ---------- .../auth/ee/dsproject/node/Node89978445.java | 201 +++++++----------- src/gr/auth/ee/dsproject/node/Queue2D.java | 0 src/gr/auth/ee/dsproject/node/Tree.java | 100 +++++++++ src/gr/auth/ee/dsproject/pacman/Creature.java | 71 ++++--- 15 files changed, 251 insertions(+), 268 deletions(-) mode change 100755 => 100644 .classpath mode change 100755 => 100644 .project mode change 100755 => 100644 .settings/org.eclipse.jdt.core.prefs mode change 100755 => 100644 GameLog.txt mode change 100644 => 100755 bin/.gitignore mode change 100644 => 100755 bin/gr/auth/ee/dsproject/pacman/Creature.class mode change 100755 => 100644 ghosts.gif mode change 100755 => 100644 lib/pacman.jar mode change 100755 => 100644 pacman.gif mode change 100755 => 100644 src/gr/auth/ee/dsproject/node/Globals.java delete mode 100755 src/gr/auth/ee/dsproject/node/MinMaxTree.java mode change 100755 => 100644 src/gr/auth/ee/dsproject/node/Node89978445.java mode change 100755 => 100644 src/gr/auth/ee/dsproject/node/Queue2D.java create mode 100644 src/gr/auth/ee/dsproject/node/Tree.java mode change 100755 => 100644 src/gr/auth/ee/dsproject/pacman/Creature.java diff --git a/.classpath b/.classpath old mode 100755 new mode 100644 diff --git a/.project b/.project old mode 100755 new mode 100644 diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs old mode 100755 new mode 100644 diff --git a/GameLog.txt b/GameLog.txt old mode 100755 new mode 100644 index 1ce915b..d6fd94f --- a/GameLog.txt +++ b/GameLog.txt @@ -80,3 +80,31 @@ Team 0.00 Mine 1 Team 0.00 Mine 0 77 Team 0.00 Mine 1 Team 0.00 Mine 0 77 Team 0.00 Mine 1 Team 0.00 Mine 0 94 Team 0.00 Mine 1 Team 0.00 Mine 0 94 +Team 0.00 Mine 0 Team 0.00 Mine 1 61 +Team 0.00 Mine 0 Team 0.00 Mine 1 14 +Team 0.00 Mine 0 Team 0.00 Mine 1 4 +Team 0.00 Mine 0 Team 0.00 Mine 1 12 +Team 0.00 Mine 1 Team 0.00 Mine 0 97 +Team 0.00 Mine 1 Team 0.00 Mine 0 97 +Team 0.00 Mine 0 Team 0.00 Mine 1 22 +Team 0.00 Mine 0 Team 0.00 Mine 1 22 +Team 0.00 Mine 1 Team 0.00 Mine 0 104 +Team 0.00 Mine 0 Team 0.00 Mine 1 7 +Team 0.00 Mine 0 Team 0.00 Mine 1 7 +Team 0.00 Mine 1 Team 0.00 Mine 0 64 +Team 0.00 Mine 1 Team 0.00 Mine 0 64 +Team 0.00 Mine 1 Team 0.00 Mine 0 67 +Team 0.00 Mine 1 Team 0.00 Mine 0 67 +Team 0.00 Mine 1 Team 0.00 Mine 0 63 +Team 0.00 Mine 1 Team 0.00 Mine 0 63 +Team 0.00 Mine 1 Team 0.00 Mine 0 65 +Team 0.00 Mine 1 Team 0.00 Mine 0 65 +Team 0.00 Mine 1 Team 0.00 Mine 0 79 +Team 0.00 Mine 1 Team 0.00 Mine 0 79 +Team 0.00 Mine 1 Team 0.00 Mine 0 61 +Team 0.00 Mine 1 Team 0.00 Mine 0 61 +Team 0.00 Mine 1 Team 0.00 Mine 0 80 +Team 0.00 Mine 1 Team 0.00 Mine 0 80 +Team 0.00 Mine 1 Team 0.00 Mine 0 78 +Team 0.00 Mine 1 Team 0.00 Mine 0 71 +Team 0.00 Mine 1 Team 0.00 Mine 0 71 diff --git a/bin/.gitignore b/bin/.gitignore old mode 100644 new mode 100755 diff --git a/bin/gr/auth/ee/dsproject/pacman/Creature.class b/bin/gr/auth/ee/dsproject/pacman/Creature.class old mode 100644 new mode 100755 index e53c04b11537d007f69247d04a7de25948d08558..fc58a20bb87b4cd144c487a262024550ff6f0485 GIT binary patch delta 2702 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 max) { - max = ev; - node = parent.children.get (i); - } - } - return node; - } - - -} diff --git a/src/gr/auth/ee/dsproject/node/Node89978445.java b/src/gr/auth/ee/dsproject/node/Node89978445.java old mode 100755 new mode 100644 index 3579b83..4f56728 --- a/src/gr/auth/ee/dsproject/node/Node89978445.java +++ b/src/gr/auth/ee/dsproject/node/Node89978445.java @@ -25,18 +25,16 @@ import gr.auth.ee.dsproject.pacman.Room; */ public class Node89978445 { - double nodeEvaluation; /**< - * Pacman's current move evaluation - * This is used also as the "return status" of the object - */ - int[] nodeXY; // Pacman's current x,y coordinate - int[][] currentGhostPos; // Array holding the Ghost (x,y) pairs + double nodeEvaluation; /*< + * Pacman's current move evaluation + * This is used also as the "return status" of the object + */ + int[] nodeXY; // Pacman's current x,y coordinate + int[][] curGhostPos; // Array holding the Ghost (x,y) pairs - - - int[][] flagPos; // Array holding the flag (x,y) pairs - boolean[] currentFlagStatus; // Array holding the flag capture status - Room[][] Maze; // copy of the current Maze + int[][] flagPos; // Array holding the flag (x,y) pairs + boolean[] curFlagStatus; // Array holding the flag capture status + Room[][] Maze; // copy of the current Maze /* * Tree navigation references. These variables are handled by @@ -65,10 +63,10 @@ public class Node89978445 parent = null; // allocate objects - currentGhostPos = new int [PacmanUtilities.numberOfGhosts][2]; - flagPos = new int [PacmanUtilities.numberOfFlags][2]; - currentFlagStatus = new boolean[PacmanUtilities.numberOfFlags]; - children = new ArrayList (); + curGhostPos = new int [PacmanUtilities.numberOfGhosts][2]; + flagPos = new int [PacmanUtilities.numberOfFlags][2]; + curFlagStatus = new boolean[PacmanUtilities.numberOfFlags]; + children = new ArrayList (); } /** @@ -85,10 +83,18 @@ public class Node89978445 parent = null; // allocate objects - currentGhostPos = new int [PacmanUtilities.numberOfGhosts][2]; - flagPos = new int [PacmanUtilities.numberOfFlags][2]; - currentFlagStatus = new boolean[PacmanUtilities.numberOfFlags]; - children = new ArrayList (); + curGhostPos = new int [PacmanUtilities.numberOfGhosts][2]; + flagPos = new int [PacmanUtilities.numberOfFlags][2]; + curFlagStatus = new boolean[PacmanUtilities.numberOfFlags]; + children = new ArrayList (); + + // calculate helper arrays + curGhostPos = findGhosts (); + flagPos = findFlags (); + curFlagStatus = checkFlags (); + + //Evaluate the position + nodeEvaluation = evaluate (); } /* @@ -123,10 +129,15 @@ public class Node89978445 { // If already evaluated do not re-evaluate the move if (nodeEvaluation == Globals.NO_EVAL) { + // Safety filters + if (Maze == null) + return Globals.NO_EVAL; + if (nodeXY == Globals.FALSE_POS) + return Globals.NO_EVAL; // calculate helper arrays - currentGhostPos = findGhosts (); + curGhostPos = findGhosts (); flagPos = findFlags (); - currentFlagStatus = checkFlags (); + curFlagStatus = checkFlags (); return nodeEvaluation = evaluate (); } @@ -134,16 +145,30 @@ public class Node89978445 return nodeEvaluation; } - public int[] getCurentPacmanPos () { + public int[] getCurrentPacmanPos () { return nodeXY; } public int[][] getCurrentGhostPos () { - return currentGhostPos; + return curGhostPos; + } + public int getDepth () { + return depth; } /* * ============= Helper API ============ */ + public static int moveConv (int[] nextPos, int[] curPos) + { + int dx = nextPos[0] - curPos[0]; + int dy = nextPos[1] - curPos[1]; + + if (dx < 0) return Room.NORTH; + else if (dx > 0) return Room.SOUTH; + else if (dy < 0) return Room.WEST; + else return Room.EAST; + } + /** * @param creature creature's (x,y) * @return @@ -273,9 +298,17 @@ public class Node89978445 } /* - * ============ evaluation helper methods ============== + * ============ private evaluation helper methods ============== */ + + private enum Creature { + GHOST, PACMAN + } + /** + * @brief + * Check if the requested ghost move is valid + */ private int[] ghostValidMove (int[] ghost, int move) { int[] newPos = new int[2]; @@ -299,7 +332,7 @@ public class Node89978445 /** * @brief - * Check if the requested move is valid + * Check if the requested pacman move is valid */ private int[] pacmanValidMove (int[] pacman, int move) { @@ -328,12 +361,14 @@ public class Node89978445 /** * @brief * A Breadth-first search to find the shortest path distance - * from a ghost to a point in the maze - * @param ghost Ghost (x, y) - * @param xy The x, y coordinate in Maze - * @return + * from an origin point to another point in the maze as if a + * a creature could walk through + * @param origin origin (x, y) + * @param xy The x, y coordinate in Maze + * @param creature The type of creature for whom the path is for + * @return The number of steps from origin to xy */ - private int ghostMoveDist (int[] ghost, int[] xy) + private int moveDist (int[] origin, int[] xy, Creature creature) { int move; int steps, qStepItems; // distance and group counters @@ -342,10 +377,10 @@ public class Node89978445 int c = PacmanUtilities.numberOfColumns; // helper for shorting names int[] xyItem = new int [2]; // Coordinates of the current position of the algo int[] xyNext = new int [2]; // Coordinates of the next valid position of the algo - Queue2D q = new Queue2D (r+c - 1); // Queue to feed with possible position + Queue2D q = new Queue2D (Globals.MAX_DISTANCE - 1); // Queue to feed with possible position int [][] dist = new int [r][c]; /*< - * 2D array holding all the distances from the ghost to each square of the maze + * 2D array holding all the distances from the origin to each square of the maze */ // If target square is inside a box abort with max distance @@ -362,8 +397,8 @@ public class Node89978445 } } // loop data - dist [ghost[0]][ghost[1]] = 0; //starting point is the ghost position - q.insert (ghost); // feed first loop data + dist [origin[0]][origin[1]] = 0; //starting point is the origin position + q.insert (origin); // feed first loop data qStepItems = 1; // init counters steps = 1; /* @@ -380,94 +415,12 @@ public class Node89978445 --qStepItems; // mark the removal of the item for (move=0 ; move<4 ; ++move) { // loop every valid next position for the current position - if ((xyNext = ghostValidMove (xyItem, move)) != Globals.FALSE_POS) { - if (dist[xyNext[0]][xyNext[1]] == -1) { - // If we haven't been there - dist[xyNext[0]][xyNext[1]] = steps; // mark the distance - if ((xyNext[0] == xy[0]) && (xyNext[1] == xy[1])) { - /* - * first match: - * The first time we reach destination we have count the - * distance. No need any other try - */ - done = true; - break; - } - else { - // If we are not there yet, feed queue with another position - q.insert (xyNext); - } - } + switch (creature) { + case GHOST: xyNext = ghostValidMove (xyItem, move); break; + case PACMAN: xyNext = pacmanValidMove (xyItem, move); break; + default: xyNext = Globals.FALSE_POS; } - } - } - else { - // We are done with group, mark how many are for the next one - if ((qStepItems = q.size()) <= 0) - return dist[xy[0]][xy[1]]; // fail safe return - ++steps; // Update distance counter - } - } - return dist[xy[0]][xy[1]]; - } - - /** - * @brief - * A Breadth-first search to find the shortest path distance - * from the pacman to a point in the maze. The point will normaly - * represent a flag - * @param pacman Pacman's (x, y) - * @param xy The x, y coordinate in Maze - * @return - */ - private int pacmanMoveDist (int[] pacman, int[] xy) - { - int move; - int steps, qStepItems; // distance and group counters - boolean done = false; // algo ending flag - int r = PacmanUtilities.numberOfRows; // helper for shorting names - int c = PacmanUtilities.numberOfColumns; // helper for shorting names - int[] xyItem = new int [2]; // Coordinates of the current position of the algo - int[] xyNext = new int [2]; // Coordinates of the next valid position of the algo - Queue2D q = new Queue2D (r+c - 1); // Queue to feed with possible position - int [][] dist = new int [r][c]; - /* - * 2D array holding all the distances from pacman to each square of the maze - */ - - // If target square is inside a box abort with max distance - if (isInsideBox (xy)) - return Globals.MAX_DISTANCE; - - /* - * init data for algorithm - */ - for (int i=0 ; i0) { // Have we any item on the current group? - xyItem = q.remove (); //load an item of the current group - --qStepItems; // mark the removal of the item - for (move=0 ; move<4 ; ++move) { - // loop every valid next position for the current position - if ((xyNext = pacmanValidMove (xyItem, move)) != Globals.FALSE_POS) { + if (xyNext != Globals.FALSE_POS) { if (dist[xyNext[0]][xyNext[1]] == -1) { // If we haven't been there dist[xyNext[0]][xyNext[1]] = steps; // mark the distance @@ -515,7 +468,7 @@ public class Node89978445 // Find ghost distances, min and average for (i=0, averGhostDist=0 ; i ghostDist[i]) minGhostDist = ghostDist[i]; @@ -528,8 +481,8 @@ public class Node89978445 // Find flag distances and min for (i=0 ; i flagDist[i]) minFlagDist = flagDist[i]; } diff --git a/src/gr/auth/ee/dsproject/node/Queue2D.java b/src/gr/auth/ee/dsproject/node/Queue2D.java old mode 100755 new mode 100644 diff --git a/src/gr/auth/ee/dsproject/node/Tree.java b/src/gr/auth/ee/dsproject/node/Tree.java new file mode 100644 index 0000000..975b974 --- /dev/null +++ b/src/gr/auth/ee/dsproject/node/Tree.java @@ -0,0 +1,100 @@ +/** + * @file MinMaxTree.java + * @brief + * File containing the Pacman Min-Max Tree class. + * + * @author Christos Choutouridis 8997 cchoutou@ece.auth.gr + * @author Konstantina Tsechelidou 8445 konstsec@ece.auth.gr + */ +package gr.auth.ee.dsproject.node; + + +/** + * @brief + * A tree-like data structure containing move nodes to apply the min-max + * algorithm. + * @note + * This is NOT a real tree. We do not insert node based on a key etc... + */ +public class Tree +{ + /* + * ============ Constructor ============== + */ + /** + * @brief + * The simple constructor. Do nothing (this is a static class) + */ + public Tree () { } + + /* + * ========== private helpers ============== + */ + private static double min (double x, double y) { + return (x < y) ? x : y; + } + private static double max (double x, double y) { + return (x > y) ? x : y; + } + + /* + * ========== Tree-like public methods ============= + */ + /** + * @brief + * Insert a node to a parent directly. + * This is NOT a real tree. We do not insert node based on a key + * @param node Node to insert + * @param parent The parent in witch to insert + * @return Reference to inserted node + * If insert fail, returns null + */ + public static Node89978445 grow (Node89978445 node, Node89978445 parent) { + if (parent.children.add (node)) { + node.parent = parent; + node.depth = parent.depth + 1; + return node; + } + else + return null; + } + + public static Node89978445 minmaxAB (Node89978445 node, int depth, double a, double b, boolean maxingPlayer) + { + double v, ev; + Node89978445 vNode = null; + + if ((depth == 0) || (node.children.isEmpty())) + return node; + + if (maxingPlayer) { + v = Globals.EVAL_MIN - 1; + for (int i=0 ; i v) { + v = ev; + vNode = node.children.get (i); + } + a = max (v, a); + if (b <= a) + break; + } + return vNode; + } + else { + v = Globals.EVAL_MAX + 1; + for (int i=0 ; i Globals.MINMAXTREE_MAX_DEPTH) + if (depth >= Globals.MINMAXTREE_MAX_DEPTH-1) + /*< + * As the depth starts from 0 and MINMAXTREE_MAX_DEPTH + * is strictly even, with this comparison we accept that there + * is no need for a max-depth layer of ghosts-evaluation based nodes. + * As soon as we accept the depth-1 layers max evaluated node. + */ return; else { Node89978445 newNode; @@ -76,23 +85,31 @@ public class Creature implements gr.auth.ee.dsproject.pacman.AbstractCreature 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); + PacmanUtilities.movePacman (newMaze, parent.getCurrentPacmanPos(), 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 + Tree.grow (newNode, parent); // add node to the min-max tree // call the recursive ranch creator - createSubTreeGhosts (depth, newNode, newMaze, newNode.getCurrentGhostPos()); + createSubTreeGhosts (newNode.getDepth (), newNode, newMaze, newNode.getCurrentGhostPos()); } } } } + /** + * + */ void createSubTreeGhosts (int depth, Node89978445 parent, Room[][] Maze, int[][] currGhostsPosition) { - if (++depth > Globals.MINMAXTREE_MAX_DEPTH) + if (depth >= Globals.MINMAXTREE_MAX_DEPTH-1) + /*< + * As the depth starts from 0 and MINMAXTREE_MAX_DEPTH + * is strictly even, with this comparison we accept that there + * is no need for a max-depth layer of ghosts-evaluation based nodes. + * As soon as we accept the depth-1 layers max evaluated node. + */ return; else { Node89978445 newNode; @@ -103,19 +120,17 @@ public class Creature implements gr.auth.ee.dsproject.pacman.AbstractCreature ghostMoves = PacmanUtilities.allGhostMoves(Maze, currGhostsPosition); // loop all ghost moves - int s = ghostMoves.size(); - for (int i=0 ; i