use more sophiscated strategy for character moving
authorjzhou <jzhou>
Wed, 3 Sep 2008 01:47:03 +0000 (01:47 +0000)
committerjzhou <jzhou>
Wed, 3 Sep 2008 01:47:03 +0000 (01:47 +0000)
Robust/src/Benchmarks/MMG/Java/Ghost.java
Robust/src/Benchmarks/MMG/Nor/Ghost.java

index 9e5659fa9b60e5636b1cd2fa67885d07911f6c07..0d057a36bc095e8349f6991f3e25d07b5ad9d407 100755 (executable)
@@ -83,7 +83,7 @@ public class Ghost {
        int tmpdirection = 0;\r
        boolean first = true;\r
        while(!set) {\r
-           int parents[] = new int[this.m_map.m_nrofblocks * this.m_map.m_nrofblocks];\r
+           int parents[] = new int[this.m_map.m_nrofblocks * this.m_map.m_nrofblocks + 1];\r
            for(int i = 0; i < parents.length; i++) {\r
                parents[i] = -1;\r
            }\r
@@ -155,6 +155,7 @@ public class Ghost {
     // Array parents records parent for a node in the BFS search\r
     // Vector cuts specifies which nodes can not be the first one to access in this BFS\r
     private boolean BFS(Node start, Node end, int[] parents, Vector cuts) {\r
+       int steps = 0;\r
        Vector toaccess = new Vector();\r
        toaccess.addElement(start);\r
        while(toaccess.size() > 0) {\r
@@ -163,8 +164,10 @@ public class Ghost {
            toaccess.removeElementAt(0);\r
            if(access.getIndex() == end.getIndex()) {\r
                // hit the end node\r
+               parents[parents.length - 1] = steps;\r
                return true;\r
            }\r
+           steps++;\r
            Vector neighbours = access.getNeighbours();\r
            for(int i = 0; i < neighbours.size(); i++) {\r
                Node neighbour = (Node)neighbours.elementAt(i);\r
@@ -189,6 +192,7 @@ public class Ghost {
                }\r
            }\r
        }\r
+       parents[parents.length - 1] = -1;\r
        return false;\r
     }\r
     \r
index b813147e97e0f1e13b25969ba7a77df2e42ae637..228e6d8af407fef16231d73d39b25c4449d19825 100755 (executable)
@@ -85,7 +85,7 @@ public class Ghost {
        int tmpdirection = 0;
        boolean first = true;
        while(!set) {
-           int parents[] = new int[this.m_map.m_nrofblocks * this.m_map.m_nrofblocks];
+           int parents[] = new int[this.m_map.m_nrofblocks * this.m_map.m_nrofblocks + 1];
            for(int i = 0; i < parents.length; i++) {
                parents[i] = -1;
            }
@@ -157,6 +157,7 @@ public class Ghost {
     // Array parents records parent for a node in the BFS search
     // Vector cuts specifies which nodes can not be the first one to access in this BFS
     private boolean BFS(Node start, Node end, int[] parents, Vector cuts) {
+       int steps = 0;
        Vector toaccess = new Vector();
        toaccess.addElement(start);
        while(toaccess.size() > 0) {
@@ -165,8 +166,10 @@ public class Ghost {
            toaccess.removeElementAt(0);
            if(access.getIndex() == end.getIndex()) {
                // hit the end node
+               parents[parents.length - 1] = steps;
                return true;
            }
+           steps++;
            Vector neighbours = access.getNeighbours();
            for(int i = 0; i < neighbours.size(); i++) {
                Node neighbour = (Node)neighbours.elementAt(i);
@@ -191,6 +194,7 @@ public class Ghost {
                }
            }
        }
+       parents[parents.length - 1] = -1;
        return false;
     }