helpful progress reporting
[IRC.git] / Robust / src / Benchmarks / MMG / Nor / Map.java
index a75ec229ac2d52fb0c90f842d6bf75aa4d819f8a..f056cd07af84fe6e689e4c056c5aa11e2f3e7bc7 100755 (executable)
@@ -8,13 +8,16 @@ public class Map {
     // maze
     private int m_nrofblocks;
     public int[] m_map;
-    public Node[] m_mapNodes;
     
     // pacmen information
     public int m_nrofpacs;
     public int[] m_pacMenX;
     public int[] m_pacMenY;
     public int[] m_directions;
+    public int[] m_pacOriX;
+    public int[] m_pacOriY;
+    public int[] m_leftLives;
+    public int[] m_leftLevels;
     public int[] m_desX;
     public int[] m_desY;
     public int m_paccount;
@@ -36,12 +39,15 @@ public class Map {
        //System.printString("step 1\n");
        this.m_nrofblocks = 15;
        this.m_map = new int[this.m_nrofblocks*this.m_nrofblocks];
-       this.m_mapNodes = new Node[this.m_nrofblocks*this.m_nrofblocks];
        
        this.m_nrofpacs = nrofpacs;
        this.m_pacMenX = new int[this.m_nrofpacs];
        this.m_pacMenY = new int[this.m_nrofpacs];
        this.m_directions = new int[this.m_nrofpacs];
+       this.m_pacOriX = new int[this.m_nrofpacs];
+       this.m_pacOriY = new int[this.m_nrofpacs];
+       this.m_leftLives = new int[this.m_nrofpacs];
+       this.m_leftLevels = new int[this.m_nrofpacs];
        this.m_desX = new int[this.m_nrofpacs];
        this.m_desY = new int[this.m_nrofpacs];
        this.m_paccount = 0;
@@ -59,12 +65,14 @@ public class Map {
        
        for(int i = 0; i < this.m_nrofblocks*this.m_nrofblocks; i++) {
            this.m_map[i] = -1;
-           this.m_mapNodes[i] = new Node(i%this.m_nrofblocks, i/this.m_nrofblocks, i);
        }
        
        //System.printString("step 2\n");
        for(int i = 0; i < this.m_nrofpacs; i++) {
            this.m_pacMenX[i] = this.m_pacMenY[i] = -1;
+           this.m_directions[i] = 0;
+           this.m_pacOriX[i] = this.m_pacOriY[i] = -1;
+           this.m_leftLives[i] = this.m_leftLevels[i] = 0;
            this.m_desX[i] = this.m_desY[i] = -1;
        }
        //System.printString("step 3\n");
@@ -93,46 +101,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;
        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;
        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
-       
-       // initilize the graph of the maze
-       for(i = 0; i < this.m_nrofblocks*this.m_nrofblocks; i++) {
-           int tmp = this.m_map[i];
-           Node tmpNode = this.m_mapNodes[i];
-           int locX = tmpNode.getXLoc();
-           int locY = tmpNode.getYLoc();
-           if((int)(tmp & 1) == 0) {
-               // can go left
-               if(locX == 0) {
-                   tmpNode.addNeighbour(this.m_mapNodes[locY * this.m_nrofblocks + this.m_nrofblocks - 1]);
-               } else {
-                   tmpNode.addNeighbour(this.m_mapNodes[i - 1]);
-               }
-           } 
-           if((int)(tmp & 2) == 0) {
-               // can go up
-               if(locY == 0) {
-                   tmpNode.addNeighbour(this.m_mapNodes[(this.m_nrofblocks - 1) * this.m_nrofblocks + locX]);
-               } else {
-                   tmpNode.addNeighbour(this.m_mapNodes[(locY - 1) * this.m_nrofblocks + locX]);
-               }
-           }
-           if((int)(tmp & 4) == 0) {
-               // can go right
-               if(locX == this.m_nrofblocks - 1) {
-                   tmpNode.addNeighbour(this.m_mapNodes[locY * this.m_nrofblocks]);
-               } else {
-                   tmpNode.addNeighbour(this.m_mapNodes[i + 1]);
-               }
-           }
-           if((int)(tmp & 8) == 0) {
-               // can go down
-               if(locY == this.m_nrofblocks - 1) {
-                   tmpNode.addNeighbour(this.m_mapNodes[locX]);
-               } else {
-                   tmpNode.addNeighbour(this.m_mapNodes[(locY + 1) * this.m_nrofblocks + locX]);
-               }
-           }
-       }
     } 
 
     public void placePacman(Pacman t) {
@@ -153,6 +121,9 @@ public class Map {
        while((!death) && (i < this.m_ghostsX.length)) {
            if((t.m_locX == this.m_ghostsX[i]) && (t.m_locY == this.m_ghostsY[i])) {
                death = true;
+               t.m_death = true;
+               t.m_leftLives--;
+               //System.printString("Pacman " + t.m_index + " caught! " + t.m_leftLives + "\n");
            }
            i++;
        }
@@ -160,16 +131,29 @@ public class Map {
            // reach the destination
            //System.printString("Hit destination!\n");
            death = true;
+           t.m_success = true;
+           t.m_leftLevels--;
+           //System.printString("Pacman " + t.m_index + " hit, upgrade! " + t.m_leftLevels + "\n");
        }
        if(death) {
-           // pacman caught by ghost
-           // set pacman as death
-           t.m_death = true;
-           // kick it out
-           //this.m_map[t.y * this.m_nrofblocks + t.x - 1] -= 16;
-           this.m_deathcount++;
-           this.m_pacMenX[t.m_index] = -1;
-           this.m_pacMenY[t.m_index] = -1;
+           if(t.isFinish()) {
+               // pacman has no more lives or no more levels
+               // kick it out
+               this.m_deathcount++;
+               this.m_pacMenX[t.m_index] = -1;
+               this.m_pacMenY[t.m_index] = -1;
+           } else {
+               if(t.m_death) {
+                   this.m_leftLives[t.m_index]--;
+               } else if(t.m_success) {
+                   this.m_leftLevels[t.m_index]--;
+               }
+               t.reset();
+               this.m_pacMenX[t.m_index] = t.m_locX;
+               this.m_pacMenY[t.m_index] = t.m_locY;
+               this.m_directions[t.m_index] = 0;
+               //System.printString("Pacman " + t.m_index + " reset: (" + t.m_locX + ", " + t.m_locY + ")\n");
+           }
        }
        return death;
     }
@@ -177,4 +161,44 @@ public class Map {
     public boolean isfinish() {
        return this.m_nrofpacs == 0;
     }
-}
\ No newline at end of file
+    
+    public Vector getNeighbours(int index) {
+       Vector neighbours = new Vector();
+       int tmp = this.m_map[index];
+       int locX = index % this.m_nrofblocks;
+       int locY = index / this.m_nrofblocks;
+       if((int)(tmp & 1) == 0) {
+           // can go left
+           if(locX == 0) {
+               neighbours.addElement(new Integer(locY * this.m_nrofblocks + this.m_nrofblocks - 1));
+           } else {
+               neighbours.addElement(new Integer(index - 1));
+           }
+       } 
+       if((int)(tmp & 2) == 0) {
+           // can go up
+           if(locY == 0) {
+               neighbours.addElement(new Integer((this.m_nrofblocks - 1) * this.m_nrofblocks + locX));
+           } else {
+               neighbours.addElement(new Integer((locY - 1) * this.m_nrofblocks + locX));
+           }
+       }
+       if((int)(tmp & 4) == 0) {
+           // can go right
+           if(locX == this.m_nrofblocks - 1) {
+               neighbours.addElement(new Integer(locY * this.m_nrofblocks));
+           } else {
+               neighbours.addElement(new Integer(index + 1));
+           }
+       }
+       if((int)(tmp & 8) == 0) {
+           // can go down
+           if(locY == this.m_nrofblocks - 1) {
+               neighbours.addElement(new Integer(locX));
+           } else {
+               neighbours.addElement(new Integer((locY + 1) * this.m_nrofblocks + locX));
+           }
+       }
+       return neighbours;
+    }
+}