--- /dev/null
+/**
+ ** 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;
+ }
+ }
+}
+
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) {
}
//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;
}
}