new files for search algorithm... needs testing
authoradash <adash>
Sat, 28 Feb 2009 02:34:21 +0000 (02:34 +0000)
committeradash <adash>
Sat, 28 Feb 2009 02:34:21 +0000 (02:34 +0000)
Robust/src/Benchmarks/Distributed/RainForest/dsm/Goal.java [new file with mode: 0644]
Robust/src/Benchmarks/Distributed/RainForest/dsm/Path.java [new file with mode: 0644]
Robust/src/Benchmarks/Distributed/RainForest/dsm/RainForest.java
Robust/src/Benchmarks/Distributed/RainForest/dsm/makefile

diff --git a/Robust/src/Benchmarks/Distributed/RainForest/dsm/Goal.java b/Robust/src/Benchmarks/Distributed/RainForest/dsm/Goal.java
new file mode 100644 (file)
index 0000000..0f44184
--- /dev/null
@@ -0,0 +1,27 @@
+public class Goal {
+  private int LocX;
+  private int LocY;
+
+  public Goal() {
+    LocX = 0;
+    LocY = 0;
+  }
+
+  public Goal(int x, int y) {
+    LocX = x;
+    LocY = y;
+  }
+
+  public void setXY(int x, int y) {
+    LocX = x;
+    LocY = y;
+  }
+
+  public int getX() {
+    return LocX;
+  }
+
+  public int getY() {
+    return LocY;
+  }
+}
diff --git a/Robust/src/Benchmarks/Distributed/RainForest/dsm/Path.java b/Robust/src/Benchmarks/Distributed/RainForest/dsm/Path.java
new file mode 100644 (file)
index 0000000..515b5dc
--- /dev/null
@@ -0,0 +1,150 @@
+/**
+ ** A path determined by some path finding algorithm. A series of steps from
+ ** the starting location to the target location. This includes a step for the
+ ** initial location.
+ ** 
+ **/
+public class Path {
+  /** The list of steps building up this path */
+  private Vector steps = new Vector();
+
+  /**
+   *   * Create an empty path
+   *     */
+  public Path() {
+
+  }
+
+  /**
+   ** Get the length of the path, i.e. the number of steps
+   ** 
+   ** @return The number of steps in this path
+   **/
+  public int getLength() {
+    return steps.size();
+  }
+
+  /**
+   ** Get the step at a given index in the path
+   ** 
+   ** @param index The index of the step to retrieve. Note this should
+   ** be >= 0 and < getLength();
+   ** @return The step information, the position on the map.
+   **/
+  public Step getStep(int index) {
+    return (Step) steps.get(index);
+  }
+
+  /**
+   ** Get the x coordinate for the step at the given index
+   ** 
+   ** @param index The index of the step whose x coordinate should be retrieved
+   ** @return The x coordinate at the step
+   **/
+  public int getX(int index) {
+    return getStep(index).x;
+  }
+
+  /**
+   ** Get the y coordinate for the step at the given index
+   ** 
+   ** @param index The index of the step whose y coordinate should be retrieved
+   ** @return The y coordinate at the step
+   **/
+  public int getY(int index) {
+    return getStep(index).y;
+  }
+
+  /**
+   ** Append a step to the path.  
+   ** 
+   ** @param x The x coordinate of the new step
+   ** @param y The y coordinate of the new step
+   **/
+  public void appendStep(int x, int y) {
+    steps.add(new Step(x,y));
+  }
+
+  /**
+   ** Prepend a step to the path.  
+   ** 
+   ** @param x The x coordinate of the new step
+   ** @param y The y coordinate of the new step
+   **/
+  public void prependStep(int x, int y) {
+    steps.add(0, new Step(x, y));
+  }
+
+  /**
+   ** Check if this path contains the given step
+   ** 
+   ** @param x The x coordinate of the step to check for
+   ** @param y The y coordinate of the step to check for
+   ** @return True if the path contains the given step
+   **/
+  public boolean contains(int x, int y) {
+    return steps.contains(new Step(x,y));
+  }
+
+  /**
+   ** A single step within the path
+   ** 
+   ** @author Kevin Glass
+   **/
+  public class Step {
+    /** The x coordinate at the given step */
+    private int x;
+    /** The y coordinate at the given step */
+    private int y;
+
+    /**
+     ** Create a new step
+     ** 
+     ** @param x The x coordinate of the new step
+     ** @param y The y coordinate of the new step
+     **/
+    public Step(int x, int y) {
+      this.x = x;
+      this.y = y;
+    }
+
+    /**
+     ** Get the x coordinate of the new step
+     ** 
+     ** @return The x coodindate of the new step
+     **/
+    public int getX() {
+      return x;
+    }
+
+    /**
+     ** Get the y coordinate of the new step
+     ** 
+     ** @return The y coodindate of the new step
+     **/
+    public int getY() {
+      return y;
+    }
+
+    /**
+     ** @see Object#hashCode()
+     **/
+    public int hashCode() {
+      return x*y;
+    }
+
+    /**
+     ** @see Object#equals(Object)
+     **/
+    public boolean equals(Object other) {
+      if (other instanceof Step) {
+        Step o = (Step) other;
+
+        return (o.x == x) && (o.y == y);
+      }
+
+      return false;
+    }
+  }
+}
+
index 061a4148ec9d821d5623aeae2c1bd2db81d21c32..73b04b1242eb2881611c81d0c1e717ce0d2ae119 100644 (file)
@@ -20,7 +20,16 @@ public class RainForest extends Thread {
 
   public void run() {
     // For N interations do one move and synchronise
-    return;
+    System.println("Start run\n");
+    Barrier barr;
+    barr = new Barrier("128.196.136.162");
+    for(int i = 0; i<ROUNDS; i++) {
+      atomic {
+        doOneMove(land, gamer);
+      }
+      Barrier.enterBarrier(barr);
+    }
+    System.println("End of run\n");
   }
 
   public static void main(String[] args) {
@@ -123,8 +132,68 @@ public class RainForest extends Thread {
   }
 
   //TODO
-  public void doOneMove() {
+  public void doOneMove(GameMap land, Player mover) {
+    // 1. Get start(x, y) position of the player
+    // 2. Get type of player (lumberjack or planter)
+    // 3. Check if you have a goal(tx,ty)
+    //     a.If yes 
+    //        check retvalue = run A* from my location to goal(tx,ty) 
+    //        if retvalue = empty
+    //          pick new goal
+    //          go to 3
+    //          i.e wait here 
+    //          go to next round
+    //        else {
+    //          if planter
+    //            check if you are at goal
+    //               if yes
+    //                 can you plant tree there? i.e. 40% of block around is not full and there is no tree there
+    //                   if yes
+    //                     plant tree
+    //                     reset start(x, y) to goal(tx, ty) position
+    //                     set goal to empty
+    //                     continue to next round
+    //                   if no
+    //                     reset start(x, y) to goal(tx, ty) position
+    //                     set goal = pick new goal
+    //                     go to 3
+    //               if no
+    //                 move one step i.e. update player position
+    //                 continue to next round
+    //          if lumberjack
+    //            check if you are at goal
+    //              if yes
+    //                can you cut tree(i.e. Tree present at that location)
+    //                  if yes 
+    //                    cut tree
+    //                    set start(x,y) to goal(tx, ty) position
+    //                    set goal to empty
+    //                    continue to next round
+    //                  if no
+    //                    reset start(x,y) to goal coordinates(tx,ty)
+    //                    set goal = pick new goal
+    //                    go to 3
+    //              if no
+    //                move one step i.e, update player position
+    //                continue to next round
+    //        }
+    //      b.If no
+    //         pick new goal
+    //         go to 3
+  }
 
+  public int pickNewGoalX(Player mover) {
+    //Randomly generate goal
+    Random rand = new Random(mover.x);
+    int row = rand.nextInt(ROW-1);
+    //int col = rand.nextInt(COLUMN-1);
+    return row;
+  }
 
+  public int pickNewGoalY(Player mover) {
+    //Randomly generate goal
+    Random rand = new Random(mover.y);
+    int col = rand.nextInt(COLUMN-1);
+    return col;
   }
 }
index 6ce4c58e4dc1cf4b8d288efb87f9fb93bf92c0e4..5c823954fc5b995256a4c0900851a84b3f02877f 100644 (file)
@@ -4,7 +4,8 @@ SRC=tmp${MAINCLASS}.java \
        TreeType.java \
        GameMap.java \
        RockType.java \
-       Barrier.java
+       Barrier.java \
+       Goal.java
 
 FLAGS1=-dsm -optimize -mainclass ${MAINCLASS}
 FLAGS2=-dsm -dsmcaching -optimize -mainclass ${MAINCLASS}