commit 76063a3b54aa799a493c61ba824c53e182970fe4 Author: Christos Houtouridis Date: Wed Jan 10 19:28:29 2018 +0200 Init commit: The code from eTHMMY diff --git a/.classpath b/.classpath new file mode 100755 index 0000000..a876c4a --- /dev/null +++ b/.classpath @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ + diff --git a/.project b/.project new file mode 100755 index 0000000..65382e8 --- /dev/null +++ b/.project @@ -0,0 +1,17 @@ + + + Pacman Part C + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100755 index 0000000..3a21537 --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/GameLog.txt b/GameLog.txt new file mode 100755 index 0000000..6250f3a --- /dev/null +++ b/GameLog.txt @@ -0,0 +1,5 @@ +Team 0.00 Mine 0 Team 0.00 Mine 1 4 +Team 0.00 Mine 0 Team 0.00 Mine 1 4 +Team 0.00 Mine 0 Team 0.00 Mine 1 25 +Team 0.00 Mine 0 Team 0.00 Mine 1 25 +Team 0.00 Mine 0 Team 0.00 Mine 1 11 diff --git a/bin/gr/auth/ee/dsproject/node/Node.class b/bin/gr/auth/ee/dsproject/node/Node.class new file mode 100755 index 0000000..fbfa939 Binary files /dev/null and b/bin/gr/auth/ee/dsproject/node/Node.class differ diff --git a/bin/gr/auth/ee/dsproject/pacman/Creature.class b/bin/gr/auth/ee/dsproject/pacman/Creature.class new file mode 100755 index 0000000..5e2700a Binary files /dev/null and b/bin/gr/auth/ee/dsproject/pacman/Creature.class differ diff --git a/ghosts.gif b/ghosts.gif new file mode 100755 index 0000000..010ec99 Binary files /dev/null and b/ghosts.gif differ diff --git a/lib/pacman.jar b/lib/pacman.jar new file mode 100755 index 0000000..533ec81 Binary files /dev/null and b/lib/pacman.jar differ diff --git a/pacman.gif b/pacman.gif new file mode 100755 index 0000000..ed128f3 Binary files /dev/null and b/pacman.gif differ diff --git a/src/gr/auth/ee/dsproject/node/Node.java b/src/gr/auth/ee/dsproject/node/Node.java new file mode 100755 index 0000000..f415e8c --- /dev/null +++ b/src/gr/auth/ee/dsproject/node/Node.java @@ -0,0 +1,52 @@ +package gr.auth.ee.dsproject.node; + +import gr.auth.ee.dsproject.pacman.Room; + +import java.util.ArrayList; + +public class Node +{ + + int nodeX; + int nodeY; + int depth; + int nodeMove; + double nodeEvaluation; + int[][] currentGhostPos; + int[][] flagPos; + boolean[] currentFlagStatus; + + Node parent; + ArrayList children = new ArrayList(); + + // Constructor + public Node () + { + // TODO Fill This + } + + private int[][] findGhosts (Room[][] Maze) + { + // TODO Fill This + } + + private int[][] findFlags (Room[][] Maze) + { + // TODO Fill This + } + + private boolean[] checkFlags (Room[][] Maze) + { + + // TODO Fill This + } + + private double evaluate () + { + + double evaluation = (200 * Math.random()) - 100; + return evaluation; + + } + +} diff --git a/src/gr/auth/ee/dsproject/pacman/Creature.java b/src/gr/auth/ee/dsproject/pacman/Creature.java new file mode 100755 index 0000000..b31979e --- /dev/null +++ b/src/gr/auth/ee/dsproject/pacman/Creature.java @@ -0,0 +1,289 @@ +package gr.auth.ee.dsproject.pacman; + +import gr.auth.ee.dsproject.node.Node; + +/** + *

+ * Title: DataStructures2011 + *

+ * + *

+ * Description: Data Structures project: year 2011-2012 + *

+ * + *

+ * Copyright: Copyright (c) 2011 + *

+ * + *

+ * Company: A.U.Th. + *

+ * + * @author Michael T. Tsapanos + * @version 1.0 + */ + +public class Creature implements gr.auth.ee.dsproject.pacman.AbstractCreature +{ + + public String getName () + { + return "Mine"; + } + + private int step = 1; + private boolean amPrey; + + public Creature (boolean isPrey) + { + amPrey = isPrey; + + } + + public int calculateNextPacmanPosition (Room[][] Maze, int[] currPosition) + { + // TODO Fill This + + return 0; + } + + void createSubTreePacman (int depth, Node parent, Room[][] Maze, int[] currPacmanPosition) + { + + // TODO Fill This + + } + + void createSubTreeGhosts (int depth, Node parent, Room[][] Maze, int[][] currGhostsPosition) + { + // TODO Fill This + } + + public int[] getPacPos (Room[][] Maze) + { + int[] pacmanPos = new int[2]; + for (int i = 0; i < PacmanUtilities.numberOfRows; i++) { + for (int j = 0; j < PacmanUtilities.numberOfColumns; j++) { + if (Maze[i][j].isPacman()) { + pacmanPos[0] = i; + pacmanPos[1] = j; + return pacmanPos; + } + } + } + return pacmanPos; + } + + public boolean[] comAvPos (Room[][] Maze, int[][] currentPos, int[] moves, int currentGhost) + { + + boolean[] availablePositions = { true, true, true, true }; + + int[][] newPos = new int[4][2]; + + for (int i = 0; i < 4; i++) { + + if (Maze[currentPos[currentGhost][0]][currentPos[currentGhost][1]].walls[i] == 0) { + availablePositions[i] = false; + continue; + } + + if (PacmanUtilities.flagColision(Maze, currentPos[currentGhost], i)) { + availablePositions[i] = false; + } + + else if (currentGhost == 0) + continue; + + else { + switch (i) { + case Room.WEST: + newPos[currentGhost][0] = currentPos[currentGhost][0]; + newPos[currentGhost][1] = currentPos[currentGhost][1] - 1; + break; + case Room.SOUTH: + newPos[currentGhost][0] = currentPos[currentGhost][0] + 1; + newPos[currentGhost][1] = currentPos[currentGhost][1]; + break; + case Room.EAST: + newPos[currentGhost][0] = currentPos[currentGhost][0]; + newPos[currentGhost][1] = currentPos[currentGhost][1] + 1; + break; + case Room.NORTH: + newPos[currentGhost][0] = currentPos[currentGhost][0] - 1; + newPos[currentGhost][1] = currentPos[currentGhost][1]; + + } + + for (int j = (currentGhost - 1); j > -1; j--) { + switch (moves[j]) { + case Room.WEST: + newPos[j][0] = currentPos[j][0]; + newPos[j][1] = currentPos[j][1] - 1; + break; + case Room.SOUTH: + newPos[j][0] = currentPos[j][0] + 1; + newPos[j][1] = currentPos[j][1]; + break; + case Room.EAST: + newPos[j][0] = currentPos[j][0]; + newPos[j][1] = currentPos[j][1] + 1; + break; + case Room.NORTH: + newPos[j][0] = currentPos[j][0] - 1; + newPos[j][1] = currentPos[j][1]; + // break; + } + + if ((newPos[currentGhost][0] == newPos[j][0]) && (newPos[currentGhost][1] == newPos[j][1])) { + + availablePositions[i] = false; + continue; + } + + if ((newPos[currentGhost][0] == currentPos[j][0]) && (newPos[currentGhost][1] == currentPos[j][1]) && (newPos[j][0] == currentPos[currentGhost][0]) + && (newPos[j][1] == currentPos[currentGhost][1])) { + + availablePositions[i] = false; + + } + } + } + } + + return availablePositions; + } + + public int comBestPos (boolean[] availablePositions, int[] pacmanPosition, int[] currentPos) + { + + int[] newVerticalDifference = new int[2]; + for (int i = 0; i < 2; i++) + newVerticalDifference[i] = currentPos[i] - pacmanPosition[i]; + + int[] distanceSquared = new int[4]; + + for (int i = 0; i < 4; i++) { + if (availablePositions[i] == true) { + + switch (i) { + case Room.WEST: + newVerticalDifference[1]--; + break; + case Room.SOUTH: + newVerticalDifference[0]++; + break; + case Room.EAST: + newVerticalDifference[1]++; + break; + case Room.NORTH: + newVerticalDifference[0]--; + break; + } + distanceSquared[i] = newVerticalDifference[0] * newVerticalDifference[0] + newVerticalDifference[1] * newVerticalDifference[1]; + } else + distanceSquared[i] = PacmanUtilities.numberOfRows * PacmanUtilities.numberOfRows + PacmanUtilities.numberOfColumns * PacmanUtilities.numberOfColumns + 1; + } + + int minDistance = distanceSquared[0]; + int minPosition = 0; + + for (int i = 1; i < 4; i++) { + if (minDistance > distanceSquared[i]) { + minDistance = distanceSquared[i]; + minPosition = i; + } + + } + + return minPosition; + } + + public int[] calculateNextGhostPosition (Room[][] Maze, int[][] currentPos) + { + + int[] moves = new int[PacmanUtilities.numberOfGhosts]; + + int[] pacmanPosition = new int[2]; + + pacmanPosition = getPacPos(Maze); + for (int i = 0; i < PacmanUtilities.numberOfGhosts; i++) { + moves[i] = comBestPos(comAvPos(Maze, currentPos, moves, i), pacmanPosition, currentPos[i]); + } + + return moves; + + } + + public boolean[] checkCollision (int[] moves, int[][] currentPos) + { + boolean[] collision = new boolean[PacmanUtilities.numberOfGhosts]; + + int[][] newPos = new int[4][2]; + + for (int i = 0; i < moves.length; i++) { + + if (moves[i] == 0) { + if (currentPos[i][1] > 0) { + newPos[i][0] = currentPos[i][0]; + newPos[i][1] = currentPos[i][1] - 1; + } else { + newPos[i][0] = currentPos[i][0]; + newPos[i][1] = PacmanUtilities.numberOfColumns - 1; + } + + } else if (moves[i] == 1) { + if (currentPos[i][0] < PacmanUtilities.numberOfRows - 1) { + newPos[i][0] = currentPos[i][0] + 1; + newPos[i][1] = currentPos[i][1]; + } else { + newPos[i][0] = 0; + newPos[i][1] = currentPos[i][1]; + } + } else if (moves[i] == 2) { + if (currentPos[i][1] < PacmanUtilities.numberOfColumns - 1) { + newPos[i][0] = currentPos[i][0]; + newPos[i][1] = currentPos[i][1] + 1; + } else { + newPos[i][0] = currentPos[i][0]; + newPos[i][1] = 0; + + } + } else { + if (currentPos[i][0] > 0) { + newPos[i][0] = currentPos[i][0] - 1; + newPos[i][1] = currentPos[i][1]; + } else { + + newPos[i][0] = PacmanUtilities.numberOfRows - 1; + newPos[i][1] = currentPos[i][1]; + + } + } + + collision[i] = false; + } + + for (int k = 0; k < moves.length; k++) { + + } + + for (int i = 0; i < moves.length; i++) { + for (int j = i + 1; j < moves.length; j++) { + if (newPos[i][0] == newPos[j][0] && newPos[i][1] == newPos[j][1]) { + + collision[j] = true; + } + + if (newPos[i][0] == currentPos[j][0] && newPos[i][1] == currentPos[j][1] && newPos[j][0] == currentPos[i][0] && newPos[j][1] == currentPos[i][1]) { + + collision[j] = true; + } + + } + + } + return collision; + } + +}