helpful progress reporting
[IRC.git] / Robust / src / Benchmarks / MMG / Java / Map.java
index 5cf209754d339cfb89ae3faf36a77cd1b8db63f6..33127364e1131cec3e0e782b963e7e4d7da16eb3 100755 (executable)
@@ -2,7 +2,6 @@ public class Map {
     // maze\r
     private int m_nrofblocks;\r
     public int[] m_map;\r
-    public Node[] m_mapNodes;\r
     public Ghost[] m_ghosts;\r
     public Pacman[] m_pacmen;\r
     \r
@@ -11,6 +10,10 @@ public class Map {
     public int[] m_pacMenX;\r
     public int[] m_pacMenY;\r
     public int[] m_directions;\r
+    public int[] m_pacOriX;\r
+    public int[] m_pacOriY;\r
+    public int[] m_leftLives;\r
+    public int[] m_leftLevels;\r
     public int[] m_desX;\r
     public int[] m_desY;\r
     public int m_paccount;\r
@@ -31,12 +34,15 @@ public class Map {
        //System.printString("step 1\n");\r
        this.m_nrofblocks = 15;\r
        this.m_map = new int[this.m_nrofblocks*this.m_nrofblocks];\r
-       this.m_mapNodes = new Node[this.m_nrofblocks*this.m_nrofblocks];\r
        \r
        this.m_nrofpacs = nrofpacs;\r
        this.m_pacMenX = new int[this.m_nrofpacs];\r
        this.m_pacMenY = new int[this.m_nrofpacs];\r
        this.m_directions = new int[this.m_nrofpacs];\r
+       this.m_pacOriX = new int[this.m_nrofpacs];\r
+       this.m_pacOriY = new int[this.m_nrofpacs];\r
+       this.m_leftLives = new int[this.m_nrofpacs];\r
+       this.m_leftLevels = new int[this.m_nrofpacs];\r
        this.m_desX = new int[this.m_nrofpacs];\r
        this.m_desY = new int[this.m_nrofpacs];\r
        this.m_paccount = 0;\r
@@ -56,12 +62,14 @@ public class Map {
        \r
        for(int i = 0; i < this.m_nrofblocks*this.m_nrofblocks; i++) {\r
            this.m_map[i] = -1;\r
-           this.m_mapNodes[i] = new Node(i%this.m_nrofblocks, i/this.m_nrofblocks, i);\r
        }\r
        \r
        //System.printString("step 2\n");\r
        for(int i = 0; i < this.m_nrofpacs; i++) {\r
            this.m_pacMenX[i] = this.m_pacMenY[i] = -1;\r
+           this.m_directions[i] = 0;\r
+           this.m_pacOriX[i] = this.m_pacOriY[i] = -1;\r
+           this.m_leftLives[i] = this.m_leftLevels[i] = 0;\r
            this.m_desX[i] = this.m_desY[i] = -1;\r
            this.m_pacmen[i] = null;\r
        }\r
@@ -92,46 +100,6 @@ public class Map {
        this.m_map[i++]=1;this.m_map[i++]=10;this.m_map[i++]=10;this.m_map[i++]=6;this.m_map[i++]=13;this.m_map[i++]=5;this.m_map[i++]=11;this.m_map[i++]=2;this.m_map[i++]=14;this.m_map[i++]=5;this.m_map[i++]=13;this.m_map[i++]=3;this.m_map[i++]=10;this.m_map[i++]=10;this.m_map[i++]=4;\r
        this.m_map[i++]=5;this.m_map[i++]=11;this.m_map[i++]=14;this.m_map[i++]=1;this.m_map[i++]=10;this.m_map[i++]=8;this.m_map[i++]=6;this.m_map[i++]=13;this.m_map[i++]=3;this.m_map[i++]=8;this.m_map[i++]=10;this.m_map[i++]=4;this.m_map[i++]=11;this.m_map[i++]=14;this.m_map[i++]=5;\r
        this.m_map[i++]=9;this.m_map[i++]=10;this.m_map[i++]=10;this.m_map[i++]=12;this.m_map[i++]=3;this.m_map[i++]=6;this.m_map[i++]=9;this.m_map[i++]=10;this.m_map[i++]=12;this.m_map[i++]=3;this.m_map[i++]=6;this.m_map[i++]=9;this.m_map[i++]=10;this.m_map[i++]=10;this.m_map[i++]=12; // 15*15\r
-       \r
-       // initilize the graph of the maze\r
-       for(i = 0; i < this.m_nrofblocks*this.m_nrofblocks; i++) {\r
-           int tmp = this.m_map[i];\r
-           Node tmpNode = this.m_mapNodes[i];\r
-           int locX = tmpNode.getXLoc();\r
-           int locY = tmpNode.getYLoc();\r
-           if((int)(tmp & 1) == 0) {\r
-               // can go left\r
-               if(locX == 0) {\r
-                   tmpNode.addNeighbour(this.m_mapNodes[locY * this.m_nrofblocks + this.m_nrofblocks - 1]);\r
-               } else {\r
-                   tmpNode.addNeighbour(this.m_mapNodes[i - 1]);\r
-               }\r
-           } \r
-           if((int)(tmp & 2) == 0) {\r
-               // can go up\r
-               if(locY == 0) {\r
-                   tmpNode.addNeighbour(this.m_mapNodes[(this.m_nrofblocks - 1) * this.m_nrofblocks + locX]);\r
-               } else {\r
-                   tmpNode.addNeighbour(this.m_mapNodes[(locY - 1) * this.m_nrofblocks + locX]);\r
-               }\r
-           }\r
-           if((int)(tmp & 4) == 0) {\r
-               // can go right\r
-               if(locX == this.m_nrofblocks - 1) {\r
-                   tmpNode.addNeighbour(this.m_mapNodes[locY * this.m_nrofblocks]);\r
-               } else {\r
-                   tmpNode.addNeighbour(this.m_mapNodes[i + 1]);\r
-               }\r
-           }\r
-           if((int)(tmp & 8) == 0) {\r
-               // can go down\r
-               if(locY == this.m_nrofblocks - 1) {\r
-                   tmpNode.addNeighbour(this.m_mapNodes[locX]);\r
-               } else {\r
-                   tmpNode.addNeighbour(this.m_mapNodes[(locY + 1) * this.m_nrofblocks + locX]);\r
-               }\r
-           }\r
-       }\r
     } \r
 \r
     public void placePacman(Pacman t) {\r
@@ -152,6 +120,9 @@ public class Map {
        while((!death) && (i < this.m_ghostsX.length)) {\r
            if((t.m_locX == this.m_ghostsX[i]) && (t.m_locY == this.m_ghostsY[i])) {\r
                death = true;\r
+               t.m_death = true;\r
+               t.m_leftLives--;\r
+               //System.printString("Pacman " + t.m_index + " caught! " + t.m_leftLives + "\n");\r
            }\r
            i++;\r
        }\r
@@ -159,16 +130,29 @@ public class Map {
            // reach the destination\r
            //System.printString("Hit destination!\n");\r
            death = true;\r
+           t.m_success = true;\r
+           t.m_leftLevels--;\r
+           //System.printString("Pacman " + t.m_index + " hit, upgrade! " + t.m_leftLevels + "\n");\r
        }\r
        if(death) {\r
-           // pacman caught by ghost\r
-           // set pacman as death\r
-           t.m_death = true;\r
-           // kick it out\r
-           //this.m_map[t.y * this.m_nrofblocks + t.x - 1] -= 16;\r
-           this.m_deathcount++;\r
-           this.m_pacMenX[t.m_index] = -1;\r
-           this.m_pacMenY[t.m_index] = -1;\r
+           if(t.isFinish()) {\r
+               // pacman has no more lives or no more levels\r
+               // kick it out\r
+               this.m_deathcount++;\r
+               this.m_pacMenX[t.m_index] = -1;\r
+               this.m_pacMenY[t.m_index] = -1;\r
+           } else {\r
+               if(t.m_death) {\r
+                   this.m_leftLives[t.m_index]--;\r
+               } else if(t.m_success) {\r
+                   this.m_leftLevels[t.m_index]--;\r
+               }\r
+               t.reset();\r
+               this.m_pacMenX[t.m_index] = t.m_locX;\r
+               this.m_pacMenY[t.m_index] = t.m_locY;\r
+               this.m_directions[t.m_index] = 0;\r
+               //System.printString("Pacman " + t.m_index + " reset: (" + t.m_locX + ", " + t.m_locY + ")\n");\r
+           }\r
        }\r
        return death;\r
     }\r
@@ -176,4 +160,44 @@ public class Map {
     public boolean isfinish() {\r
        return this.m_nrofpacs == 0;\r
     }\r
+    \r
+    public Vector getNeighbours(int index) {\r
+       Vector neighbours = new Vector();\r
+       int tmp = this.m_map[index];\r
+       int locX = index % this.m_nrofblocks;\r
+       int locY = index / this.m_nrofblocks;\r
+       if((int)(tmp & 1) == 0) {\r
+           // can go left\r
+           if(locX == 0) {\r
+               neighbours.addElement(new Integer(locY * this.m_nrofblocks + this.m_nrofblocks - 1));\r
+           } else {\r
+               neighbours.addElement(new Integer(index - 1));\r
+           }\r
+       } \r
+       if((int)(tmp & 2) == 0) {\r
+           // can go up\r
+           if(locY == 0) {\r
+               neighbours.addElement(new Integer((this.m_nrofblocks - 1) * this.m_nrofblocks + locX));\r
+           } else {\r
+               neighbours.addElement(new Integer((locY - 1) * this.m_nrofblocks + locX));\r
+           }\r
+       }\r
+       if((int)(tmp & 4) == 0) {\r
+           // can go right\r
+           if(locX == this.m_nrofblocks - 1) {\r
+               neighbours.addElement(new Integer(locY * this.m_nrofblocks));\r
+           } else {\r
+               neighbours.addElement(new Integer(index + 1));\r
+           }\r
+       }\r
+       if((int)(tmp & 8) == 0) {\r
+           // can go down\r
+           if(locY == this.m_nrofblocks - 1) {\r
+               neighbours.addElement(new Integer(locX));\r
+           } else {\r
+               neighbours.addElement(new Integer((locY + 1) * this.m_nrofblocks + locX));\r
+           }\r
+       }\r
+       return neighbours;\r
+    }\r
 }\r