Init commit: The code from eTHMMY
This commit is contained in:
commit
76063a3b54
11
.classpath
Executable file
11
.classpath
Executable file
@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<classpath>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="module" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="src" path="src"/>
|
||||||
|
<classpathentry kind="lib" path="lib/pacman.jar"/>
|
||||||
|
<classpathentry kind="output" path="bin"/>
|
||||||
|
</classpath>
|
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
|
17
.project
Executable file
17
.project
Executable file
@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>Pacman Part C</name>
|
||||||
|
<comment></comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
|
</natures>
|
||||||
|
</projectDescription>
|
11
.settings/org.eclipse.jdt.core.prefs
Executable file
11
.settings/org.eclipse.jdt.core.prefs
Executable file
@ -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
|
5
GameLog.txt
Executable file
5
GameLog.txt
Executable file
@ -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
|
BIN
bin/gr/auth/ee/dsproject/node/Node.class
Executable file
BIN
bin/gr/auth/ee/dsproject/node/Node.class
Executable file
Binary file not shown.
BIN
bin/gr/auth/ee/dsproject/pacman/Creature.class
Executable file
BIN
bin/gr/auth/ee/dsproject/pacman/Creature.class
Executable file
Binary file not shown.
BIN
ghosts.gif
Executable file
BIN
ghosts.gif
Executable file
Binary file not shown.
After Width: | Height: | Size: 3.5 KiB |
BIN
lib/pacman.jar
Executable file
BIN
lib/pacman.jar
Executable file
Binary file not shown.
BIN
pacman.gif
Executable file
BIN
pacman.gif
Executable file
Binary file not shown.
After Width: | Height: | Size: 5.2 KiB |
52
src/gr/auth/ee/dsproject/node/Node.java
Executable file
52
src/gr/auth/ee/dsproject/node/Node.java
Executable file
@ -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<Node> children = new ArrayList<Node>();
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
289
src/gr/auth/ee/dsproject/pacman/Creature.java
Executable file
289
src/gr/auth/ee/dsproject/pacman/Creature.java
Executable file
@ -0,0 +1,289 @@
|
|||||||
|
package gr.auth.ee.dsproject.pacman;
|
||||||
|
|
||||||
|
import gr.auth.ee.dsproject.node.Node;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* Title: DataStructures2011
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* Description: Data Structures project: year 2011-2012
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* Copyright: Copyright (c) 2011
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* Company: A.U.Th.
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user