From fbed4659a16b7e28ab960e28f11d11b841ed1d86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Wed, 5 Nov 2014 10:55:14 +0100 Subject: PossiblePaths: support int init(Pawn pawn, Tile from, Tile to) --- core/src/ch/asynk/tankontank/engine/PossiblePaths.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/core/src/ch/asynk/tankontank/engine/PossiblePaths.java b/core/src/ch/asynk/tankontank/engine/PossiblePaths.java index 55a5cd9..bcda72b 100644 --- a/core/src/ch/asynk/tankontank/engine/PossiblePaths.java +++ b/core/src/ch/asynk/tankontank/engine/PossiblePaths.java @@ -13,6 +13,7 @@ public class PossiblePaths implements Iterable private final Board board; public Pawn pawn; + public Tile from; public Tile to; public Orientation orientation; private List stack; @@ -34,15 +35,21 @@ public class PossiblePaths implements Iterable this.orientation = Orientation.KEEP; } - public int init(Pawn pawn, Tile to) + public int init(Pawn pawn, Tile from, Tile to) { clear(); this.pawn = pawn; + this.from = from; this.to = to; return build(); } + public int init(Pawn pawn, Tile to) + { + return init(pawn, pawn.getTile(), to); + } + public void clear() { for (List tiles : this.paths) tiles.clear(); @@ -78,7 +85,6 @@ public class PossiblePaths implements Iterable private int build() { // from and to are not part of the path - Tile from = pawn.getTile(); if (board.distance(from, to) == 1) { ArrayList temp = new ArrayList(0); // temp.add(from); @@ -199,7 +205,7 @@ public class PossiblePaths implements Iterable { int steps = 0; - Tile tile = pawn.getTile(); + Tile tile = from; Orientation o = pawn.getOrientation(); for (Tile next : getPath(idx)) { Orientation nextO = Orientation.fromMove(tile.col, tile.row, next.col, next.row); @@ -221,7 +227,7 @@ public class PossiblePaths implements Iterable @Override public Iterator iterator() { - return new Vector3Iterator(pawn, to, orientation, getPath(0)); + return new Vector3Iterator(pawn, from, to, orientation, getPath(0)); } private void printToErr(String what, List> paths) @@ -248,13 +254,13 @@ class Vector3Iterator implements Iterator private int i; private List path; - public Vector3Iterator(Pawn pawn, Tile to, Orientation orientation, List path) + public Vector3Iterator(Pawn pawn, Tile from, Tile to, Orientation orientation, List path) { this.pawn = pawn; this.to = to; + this.tile = from; this.orientation = orientation; this.path = path; - this.tile = pawn.getTile(); this.o = pawn.getOrientation(); this.v.set(pawn.getPosition().x, pawn.getPosition().y, o.r()); this.i = 0; -- cgit v1.1-2-g2b99