From 7719aaf6334b0425d42aeb579153c0b86ce613ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Tue, 20 Jan 2015 17:03:12 +0100 Subject: PossiblePaths -> PathBuilder --- .../ch/asynk/tankontank/engine/PathBuilder.java | 257 +++++++++++++++++++++ .../ch/asynk/tankontank/engine/PossiblePaths.java | 257 --------------------- core/src/ch/asynk/tankontank/game/Map.java | 26 +-- .../asynk/tankontank/game/states/StateBreak.java | 6 +- .../ch/asynk/tankontank/game/states/StateExit.java | 6 +- .../ch/asynk/tankontank/game/states/StateMove.java | 26 +-- .../asynk/tankontank/game/states/StateRotate.java | 14 +- core/test/ch/asynk/tankontank/BoardUtils.java | 12 +- core/test/ch/asynk/tankontank/Helpers.java | 14 +- 9 files changed, 309 insertions(+), 309 deletions(-) create mode 100644 core/src/ch/asynk/tankontank/engine/PathBuilder.java delete mode 100644 core/src/ch/asynk/tankontank/engine/PossiblePaths.java diff --git a/core/src/ch/asynk/tankontank/engine/PathBuilder.java b/core/src/ch/asynk/tankontank/engine/PathBuilder.java new file mode 100644 index 0000000..a227b01 --- /dev/null +++ b/core/src/ch/asynk/tankontank/engine/PathBuilder.java @@ -0,0 +1,257 @@ +package ch.asynk.tankontank.engine; + +import java.util.ArrayList; +import java.util.List; +import java.util.LinkedList; +import java.util.HashSet; +import java.util.LinkedHashSet; + +import com.badlogic.gdx.utils.Disposable; +import com.badlogic.gdx.math.Vector2; +import com.badlogic.gdx.math.Vector3; + +public class PathBuilder implements Disposable +{ + private final Board board; + + public Pawn pawn; + public Tile from; + public Tile to; + public int distance; + public Orientation orientation; + private List stack; + private List ctrlTiles; + private List paths; + private List filteredPaths; + private HashSet tiles; + + public PathBuilder(Board board, int tSize, int stSize, int ftSize, int vectSize) + { + this.board = board; + this.tiles = new LinkedHashSet(tSize); + this.stack = new ArrayList(stSize); + this.ctrlTiles = new ArrayList(ftSize); + this.paths = new LinkedList(); + this.filteredPaths = new LinkedList(); + this.to = null; + this.pawn = null; + this.orientation = Orientation.KEEP; + } + + public void init(Pawn pawn, Tile from) + { + this.pawn = pawn; + this.from = from; + } + + public void init(Pawn pawn) + { + init(pawn, pawn.getTile()); + } + + public boolean isSet() + { + return (to != null); + } + + @Override + public void dispose() + { + clear(); + } + + public void clear() + { + this.to = null; + this.distance = -1; + this.orientation = Orientation.KEEP; + for (Path path : this.paths) path.dispose(); + this.tiles.clear(); + this.stack.clear(); + this.ctrlTiles.clear(); + this.paths.clear(); + this.filteredPaths.clear(); + } + + public int size() + { + if (ctrlTiles.size() == 0) + return paths.size(); + return filteredPaths.size(); + } + + public boolean contains(Tile tile) + { + return tiles.contains(tile); + } + + public void enable(int i, boolean enable) + { + for (Tile tile : tiles) + board.enableOverlayOn(tile, i, enable); + } + + public int build(Tile to) + { + clear(); + this.to = to; + // from and to are not part of the path + this.distance = board.distance(from, to); + if (distance < 2) { + Orientation o = Orientation.fromMove(to.col, to.row, from.col, from.row); + Path path = Path.get(0); + path.roadMarch = to.road(o); + path.cost = to.costFrom(pawn, o); + paths.add(path); + } else { + findAllPaths(from, pawn.getMovementPoints(), true); + } + + // printToErr("paths", paths); + stack.clear(); + return paths.size(); + } + + private void findAllPaths(Tile from, int mvtLeft, boolean roadMarch) + { + Tile moves[] = new Tile[6]; + board.setAdjacentTiles(from, moves); + + for(int i = 0; i < 6; i++) { + Tile next = moves[i]; + if ((next == null) || next.isOffMap()) continue; + + Orientation o = board.getSide(i); + int m = (mvtLeft - next.costFrom(pawn, o)); + boolean r = roadMarch & next.road(o); + + int l = (m + (r ? pawn.getRoadMarchBonus() : 0)); + + if ((board.distance(next, to) <= l)) { + if (next == to) { + Path path = Path.get(stack.size() + 1); + for (Tile t: stack) { + path.tiles.add(t); + tiles.add(t); + } + path.roadMarch = r; + path.cost = (pawn.getMovementPoints() - m); + paths.add(path); + } else { + stack.add(next); + findAllPaths(next, m, r); + stack.remove(stack.size() - 1); + } + } + } + } + + public int toggleCtrlTile(Tile tile) + { + if (ctrlTiles.contains(tile)) + ctrlTiles.remove(tile); + else + ctrlTiles.add(tile); + return filterPaths(); + } + + private int filterPaths() + { + int s = ctrlTiles.size(); + + tiles.clear(); + filteredPaths.clear(); + for (Path path : paths) { + int ok = 0; + for (Tile filter : ctrlTiles) { + if (path.tiles.contains(filter)) + ok += 1; + } + if (ok == s) { + if (path.tiles.size() == (s + 0)) { // from and to are not part of the path + filteredPaths.clear(); + filteredPaths.add(path); + tiles.clear(); + for (Tile tile : path.tiles) tiles.add(tile); + break; + } else { + filteredPaths.add(path); + for (Tile tile : path.tiles) tiles.add(tile); + } + } + } + + // printToErr("filteredPaths", filteredPaths); + return filteredPaths.size(); + } + + public int pathCost(int i) + { + return paths.get(i).cost; + } + + public Move getMove() + { + if (size() != 1) { + System.err.println("ask for only move but they are many"); + return null; + } + + return Move.get(pawn, from, to, orientation, getPath(0)); + } + + public Move getExitMove() + { + Move move = getMove(); + move.type = Move.MoveType.EXIT; + return move; + } + + public boolean canExit(Orientation o) + { + List ps; + if (ctrlTiles.size() == 0) + ps = paths; + else + ps = filteredPaths; + + int mvt = pawn.getMovementPoints(); + int rBonus = pawn.getRoadMarchBonus(); + boolean road = to.road(o); + int cost = to.exitCost(); + + for (Path p : ps) { + int c = (p.cost + cost); + if ((c <= mvt) || (p.roadMarch && road && (c <= (mvt + rBonus)))) + return true; + } + return false; + } + + public Path getPath(int i) + { + if (ctrlTiles.size() == 0) + return paths.get(i); + return filteredPaths.get(i); + } + + public void setExit(Orientation o) + { + orientation = o; + Path path = getPath(0); + path.cost += 1; + path.tiles.add(to); + to = board.getAdjTileAt(to, o); + } + + private void printToErr(String what, List paths) + { + System.err.println(what + pawn + " ("+paths.size()+") " + from + " -> " + to); + for (Path path : paths) { + System.err.println(String.format(" - path (l:%d c:%d r:%b)", path.tiles.size(), path.cost, path.roadMarch)); + for(Tile tile : path.tiles) + System.err.println(" " + tile.toString()); + } + System.err.println(); + } +} diff --git a/core/src/ch/asynk/tankontank/engine/PossiblePaths.java b/core/src/ch/asynk/tankontank/engine/PossiblePaths.java deleted file mode 100644 index b54835e..0000000 --- a/core/src/ch/asynk/tankontank/engine/PossiblePaths.java +++ /dev/null @@ -1,257 +0,0 @@ -package ch.asynk.tankontank.engine; - -import java.util.ArrayList; -import java.util.List; -import java.util.LinkedList; -import java.util.HashSet; -import java.util.LinkedHashSet; - -import com.badlogic.gdx.utils.Disposable; -import com.badlogic.gdx.math.Vector2; -import com.badlogic.gdx.math.Vector3; - -public class PossiblePaths implements Disposable -{ - private final Board board; - - public Pawn pawn; - public Tile from; - public Tile to; - public int distance; - public Orientation orientation; - private List stack; - private List ctrlTiles; - private List paths; - private List filteredPaths; - private HashSet tiles; - - public PossiblePaths(Board board, int tSize, int stSize, int ftSize, int vectSize) - { - this.board = board; - this.tiles = new LinkedHashSet(tSize); - this.stack = new ArrayList(stSize); - this.ctrlTiles = new ArrayList(ftSize); - this.paths = new LinkedList(); - this.filteredPaths = new LinkedList(); - this.to = null; - this.pawn = null; - this.orientation = Orientation.KEEP; - } - - public void init(Pawn pawn, Tile from) - { - this.pawn = pawn; - this.from = from; - } - - public void init(Pawn pawn) - { - init(pawn, pawn.getTile()); - } - - public boolean isSet() - { - return (to != null); - } - - @Override - public void dispose() - { - clear(); - } - - public void clear() - { - this.to = null; - this.distance = -1; - this.orientation = Orientation.KEEP; - for (Path path : this.paths) path.dispose(); - this.tiles.clear(); - this.stack.clear(); - this.ctrlTiles.clear(); - this.paths.clear(); - this.filteredPaths.clear(); - } - - public int size() - { - if (ctrlTiles.size() == 0) - return paths.size(); - return filteredPaths.size(); - } - - public boolean contains(Tile tile) - { - return tiles.contains(tile); - } - - public void enable(int i, boolean enable) - { - for (Tile tile : tiles) - board.enableOverlayOn(tile, i, enable); - } - - public int build(Tile to) - { - clear(); - this.to = to; - // from and to are not part of the path - this.distance = board.distance(from, to); - if (distance < 2) { - Orientation o = Orientation.fromMove(to.col, to.row, from.col, from.row); - Path path = Path.get(0); - path.roadMarch = to.road(o); - path.cost = to.costFrom(pawn, o); - paths.add(path); - } else { - findAllPaths(from, pawn.getMovementPoints(), true); - } - - // printToErr("paths", paths); - stack.clear(); - return paths.size(); - } - - private void findAllPaths(Tile from, int mvtLeft, boolean roadMarch) - { - Tile moves[] = new Tile[6]; - board.setAdjacentTiles(from, moves); - - for(int i = 0; i < 6; i++) { - Tile next = moves[i]; - if ((next == null) || next.isOffMap()) continue; - - Orientation o = board.getSide(i); - int m = (mvtLeft - next.costFrom(pawn, o)); - boolean r = roadMarch & next.road(o); - - int l = (m + (r ? pawn.getRoadMarchBonus() : 0)); - - if ((board.distance(next, to) <= l)) { - if (next == to) { - Path path = Path.get(stack.size() + 1); - for (Tile t: stack) { - path.tiles.add(t); - tiles.add(t); - } - path.roadMarch = r; - path.cost = (pawn.getMovementPoints() - m); - paths.add(path); - } else { - stack.add(next); - findAllPaths(next, m, r); - stack.remove(stack.size() - 1); - } - } - } - } - - public int toggleCtrlTile(Tile tile) - { - if (ctrlTiles.contains(tile)) - ctrlTiles.remove(tile); - else - ctrlTiles.add(tile); - return filterPaths(); - } - - private int filterPaths() - { - int s = ctrlTiles.size(); - - tiles.clear(); - filteredPaths.clear(); - for (Path path : paths) { - int ok = 0; - for (Tile filter : ctrlTiles) { - if (path.tiles.contains(filter)) - ok += 1; - } - if (ok == s) { - if (path.tiles.size() == (s + 0)) { // from and to are not part of the path - filteredPaths.clear(); - filteredPaths.add(path); - tiles.clear(); - for (Tile tile : path.tiles) tiles.add(tile); - break; - } else { - filteredPaths.add(path); - for (Tile tile : path.tiles) tiles.add(tile); - } - } - } - - // printToErr("filteredPaths", filteredPaths); - return filteredPaths.size(); - } - - public int pathCost(int i) - { - return paths.get(i).cost; - } - - public Move getMove() - { - if (size() != 1) { - System.err.println("ask for only move but they are many"); - return null; - } - - return Move.get(pawn, from, to, orientation, getPath(0)); - } - - public Move getExitMove() - { - Move move = getMove(); - move.type = Move.MoveType.EXIT; - return move; - } - - public boolean canExit(Orientation o) - { - List ps; - if (ctrlTiles.size() == 0) - ps = paths; - else - ps = filteredPaths; - - int mvt = pawn.getMovementPoints(); - int rBonus = pawn.getRoadMarchBonus(); - boolean road = to.road(o); - int cost = to.exitCost(); - - for (Path p : ps) { - int c = (p.cost + cost); - if ((c <= mvt) || (p.roadMarch && road && (c <= (mvt + rBonus)))) - return true; - } - return false; - } - - public Path getPath(int i) - { - if (ctrlTiles.size() == 0) - return paths.get(i); - return filteredPaths.get(i); - } - - public void setExit(Orientation o) - { - orientation = o; - Path path = getPath(0); - path.cost += 1; - path.tiles.add(to); - to = board.getAdjTileAt(to, o); - } - - private void printToErr(String what, List paths) - { - System.err.println(what + pawn + " ("+paths.size()+") " + from + " -> " + to); - for (Path path : paths) { - System.err.println(String.format(" - path (l:%d c:%d r:%b)", path.tiles.size(), path.cost, path.roadMarch)); - for(Tile tile : path.tiles) - System.err.println(" " + tile.toString()); - } - System.err.println(); - } -} diff --git a/core/src/ch/asynk/tankontank/game/Map.java b/core/src/ch/asynk/tankontank/game/Map.java index 76369af..d0b461b 100644 --- a/core/src/ch/asynk/tankontank/game/Map.java +++ b/core/src/ch/asynk/tankontank/game/Map.java @@ -15,7 +15,7 @@ import ch.asynk.tankontank.engine.Move; import ch.asynk.tankontank.engine.SelectedTile; import ch.asynk.tankontank.engine.Orientation; import ch.asynk.tankontank.engine.Meteorology; -import ch.asynk.tankontank.engine.PossiblePaths; +import ch.asynk.tankontank.engine.PathBuilder; import ch.asynk.tankontank.engine.gfx.Animation; import ch.asynk.tankontank.engine.gfx.animations.AnimationSequence; import ch.asynk.tankontank.engine.gfx.animations.DiceAnimation; @@ -36,7 +36,7 @@ public abstract class Map extends Board private Random rand = new Random(); public final HexSet possibleMoves; - public final PossiblePaths possiblePaths; + public final PathBuilder pathBuilder; public final UnitList moveableUnits; public final UnitList possibleTargets; @@ -124,7 +124,7 @@ public abstract class Map extends Board setup(); possibleMoves = new HexSet(this, 40); - possiblePaths = new PossiblePaths(this, 10, 20, 5, 10); + pathBuilder = new PathBuilder(this, 10, 20, 5, 10); moveableUnits = new UnitList(6); possibleTargets = new UnitList(10); @@ -144,7 +144,7 @@ public abstract class Map extends Board super.dispose(); clearAll(); destroy.dispose(); - possiblePaths.dispose(); + pathBuilder.dispose(); DiceAnimation.free(); PromoteAnimation.free(); FireAnimation.free(); @@ -154,7 +154,7 @@ public abstract class Map extends Board { possibleMoves.clear(); possibleTargets.clear(); - possiblePaths.clear(); + pathBuilder.clear(); moveableUnits.clear(); engagementAssists.clear(); activatedUnits.clear(); @@ -190,9 +190,9 @@ public abstract class Map extends Board return collectPossibleMoves(unit, possibleMoves.asTiles()); } - public int togglePossiblePathHex(Hex hex) + public int togglePathBuilderHex(Hex hex) { - return possiblePaths.toggleCtrlTile(hex); + return pathBuilder.toggleCtrlTile(hex); } public int collectPossibleTargets(Unit unit, UnitList foes) @@ -328,7 +328,7 @@ public abstract class Map extends Board // unit.reset(); // } - return process(unit, possiblePaths.getExitMove()); + return process(unit, pathBuilder.getExitMove()); } public void promoteUnit(final Player player, final Unit unit) @@ -350,7 +350,7 @@ public abstract class Map extends Board public int moveUnit(Unit unit) { - return process(unit, possiblePaths.getMove()); + return process(unit, pathBuilder.getMove()); } public void revertMoves() @@ -556,10 +556,10 @@ public abstract class Map extends Board public void showPossibleMoves() { possibleMoves.enable(Hex.AREA, true); } public void hidePossibleMoves() { possibleMoves.enable(Hex.AREA, false); } - public void showPossiblePaths() { possiblePaths.enable(Hex.AREA, true); } - public void hidePossiblePaths() { possiblePaths.enable(Hex.AREA, false); } - public void showPath(Hex dst) { possiblePaths.enable(Hex.MOVE, true); showMove(dst); } - public void hidePath(Hex dst) { possiblePaths.enable(Hex.MOVE, false); hideMove(dst); } + public void showPathBuilder() { pathBuilder.enable(Hex.AREA, true); } + public void hidePathBuilder() { pathBuilder.enable(Hex.AREA, false); } + public void showPath(Hex dst) { pathBuilder.enable(Hex.MOVE, true); showMove(dst); } + public void hidePath(Hex dst) { pathBuilder.enable(Hex.MOVE, false); hideMove(dst); } public void selectHex(Hex hex) { selectedTile.set(hex); } public void unselectHex(Hex hex) { selectedTile.hide(); } diff --git a/core/src/ch/asynk/tankontank/game/states/StateBreak.java b/core/src/ch/asynk/tankontank/game/states/StateBreak.java index 91fae11..95ca24b 100644 --- a/core/src/ch/asynk/tankontank/game/states/StateBreak.java +++ b/core/src/ch/asynk/tankontank/game/states/StateBreak.java @@ -78,9 +78,9 @@ public class StateBreak extends StateCommon { if (activeUnit == null) return; - map.possiblePaths.init(activeUnit); - if (map.possiblePaths.build(to) == 1) { - map.possiblePaths.orientation = o; + map.pathBuilder.init(activeUnit); + if (map.pathBuilder.build(to) == 1) { + map.pathBuilder.orientation = o; map.moveUnit(activeUnit); ctrl.setAnimationCount(1); ctrl.setAfterAnimationState(StateType.DONE); diff --git a/core/src/ch/asynk/tankontank/game/states/StateExit.java b/core/src/ch/asynk/tankontank/game/states/StateExit.java index f1dadba..f8edf03 100644 --- a/core/src/ch/asynk/tankontank/game/states/StateExit.java +++ b/core/src/ch/asynk/tankontank/game/states/StateExit.java @@ -50,13 +50,13 @@ public class StateExit extends StateCommon Hex hex = unit.getHex(); if (selectedHex == hex) - map.possiblePaths.build(hex); + map.pathBuilder.build(hex); - Hex exitHex = (Hex) map.possiblePaths.to; + Hex exitHex = (Hex) map.pathBuilder.to; if (!exitZone.contains(exitHex)) throw new RuntimeException(String.format("%s not in exitZone", exitHex)); - map.possiblePaths.setExit(exitZone.orientation); + map.pathBuilder.setExit(exitZone.orientation); unit.hideMoveable(); if (to != null) diff --git a/core/src/ch/asynk/tankontank/game/states/StateMove.java b/core/src/ch/asynk/tankontank/game/states/StateMove.java index fb5be50..4794d35 100644 --- a/core/src/ch/asynk/tankontank/game/states/StateMove.java +++ b/core/src/ch/asynk/tankontank/game/states/StateMove.java @@ -15,18 +15,18 @@ public class StateMove extends StateCommon | (ctrl.cfg.canCancel ? Buttons.ABORT.b : 0)); if (prevState == StateType.ESCAPE) { - if (map.possiblePaths.size() == 1) + if (map.pathBuilder.size() == 1) ctrl.setState(StateType.ROTATE); return; } - map.possiblePaths.clear(); + map.pathBuilder.clear(); if (prevState == StateType.SELECT) { // use selectedHex and selectedUnit activeUnit = selectedUnit; activeUnit.showMoveable(); - map.possiblePaths.init(activeUnit); + map.pathBuilder.init(activeUnit); map.collectAndShowMovesAndAssits(activeUnit); if (to != null) { // quick move -> replay touchUp @@ -104,12 +104,12 @@ public class StateMove extends StateCommon if (to !=null) map.hidePath(to); to = null; - map.possiblePaths.clear(); + map.pathBuilder.clear(); ctrl.setState(StateType.ROTATE); return; } - int s = map.possiblePaths.size(); + int s = map.pathBuilder.size(); Unit unit = upHex.getUnit(); @@ -118,7 +118,7 @@ public class StateMove extends StateCommon changeUnit(unit); } else if ((s == 0) && map.possibleMoves.contains(upHex)) { s = collectPaths(upHex); - } else if (map.possiblePaths.contains(upHex)) { + } else if (map.pathBuilder.contains(upHex)) { s = togglePoint(downHex, s); } @@ -142,7 +142,7 @@ public class StateMove extends StateCommon } activeUnit = unit; Hex hex = activeUnit.getHex(); - map.possiblePaths.init(activeUnit, hex); + map.pathBuilder.init(activeUnit, hex); activeUnit.showMoveable(); map.hidePossibleMoves(); map.collectPossibleMoves(activeUnit); @@ -156,10 +156,10 @@ public class StateMove extends StateCommon private int collectPaths(Hex hex) { to = hex; - int s = map.possiblePaths.build(to); + int s = map.pathBuilder.build(to); map.showMove(to); map.hidePossibleMoves(); - map.showPossiblePaths(); + map.showPathBuilder(); return s; } @@ -170,10 +170,10 @@ public class StateMove extends StateCommon } else if (hex == to) { // } else { - map.hidePossiblePaths(); + map.hidePathBuilder(); map.togglePathOverlay(hex); - s = map.togglePossiblePathHex(hex); - map.showPossiblePaths(); + s = map.togglePathBuilderHex(hex); + map.showPathBuilder(); } return s; @@ -184,7 +184,7 @@ public class StateMove extends StateCommon Zone exitZone = ctrl.battle.getExitZone(unit); if ((exitZone == null) || !exitZone.contains(hex)) return false; - if ((unit.getHex() != hex) && !map.possiblePaths.canExit(exitZone.orientation)) + if ((unit.getHex() != hex) && !map.pathBuilder.canExit(exitZone.orientation)) return false; ctrl.setState(StateType.ESCAPE); return true; diff --git a/core/src/ch/asynk/tankontank/game/states/StateRotate.java b/core/src/ch/asynk/tankontank/game/states/StateRotate.java index 4331d3d..6b60dfb 100644 --- a/core/src/ch/asynk/tankontank/game/states/StateRotate.java +++ b/core/src/ch/asynk/tankontank/game/states/StateRotate.java @@ -20,13 +20,13 @@ public class StateRotate extends StateCommon if (to == null) to = activeUnit.getHex(); - if (!map.possiblePaths.isSet()) { - map.possiblePaths.init(activeUnit); - map.possiblePaths.build(to); + if (!map.pathBuilder.isSet()) { + map.pathBuilder.init(activeUnit); + map.pathBuilder.build(to); } - if (map.possiblePaths.size() != 1) - TankOnTank.debug("ERROR: possiblePaths.size() == " + map.possiblePaths.size()); + if (map.pathBuilder.size() != 1) + TankOnTank.debug("ERROR: pathBuilder.size() == " + map.pathBuilder.size()); rotateOnly = (to == activeUnit.getHex()); @@ -45,7 +45,7 @@ public class StateRotate extends StateCommon map.hidePath(to); map.hideDirections(to); map.hideOrientation(to); - map.possiblePaths.clear(); + map.pathBuilder.clear(); to = null; } @@ -97,7 +97,7 @@ public class StateRotate extends StateCommon if (!activeUnit.justEntered() && rotateOnly && (o == activeUnit.getOrientation())) return; - map.possiblePaths.orientation = o; + map.pathBuilder.orientation = o; rotationSet = true; if (ctrl.cfg.mustValidate) { diff --git a/core/test/ch/asynk/tankontank/BoardUtils.java b/core/test/ch/asynk/tankontank/BoardUtils.java index 53d3b0e..e18b9d1 100644 --- a/core/test/ch/asynk/tankontank/BoardUtils.java +++ b/core/test/ch/asynk/tankontank/BoardUtils.java @@ -36,14 +36,14 @@ public class BoardUtils @Test public void testPaths() { - int n = b.buildPossiblePaths(2, 2, 4, 3); + int n = b.buildPathBuilder(2, 2, 4, 3); - assertTrue(b.possiblePaths.distance == 2); + assertTrue(b.pathBuilder.distance == 2); assertTrue(n == 8); for(int p = 0; p < n; p++) { - Path path = b.possiblePaths.getPath(p); + Path path = b.pathBuilder.getPath(p); int z = path.tiles.size(); assertTrue(path.cost == (z + 1)); @@ -95,16 +95,16 @@ public class BoardUtils @Test public void testPathSet() { - int n = b.buildPossiblePaths(2, 2, 3, 3); + int n = b.buildPathBuilder(2, 2, 3, 3); assertTrue(n == 1); - n = b.buildPossiblePaths(2, 2, 4, 3); + n = b.buildPathBuilder(2, 2, 4, 3); assertTrue(n == 8); n = b.togglePoint(3, 3); assertTrue(n == 1); - n = b.buildPossiblePaths(2, 2, 5, 3); + n = b.buildPathBuilder(2, 2, 5, 3); assertTrue(n == 3); n = b.togglePoint(3, 3); diff --git a/core/test/ch/asynk/tankontank/Helpers.java b/core/test/ch/asynk/tankontank/Helpers.java index 9f49fc4..21d13ed 100644 --- a/core/test/ch/asynk/tankontank/Helpers.java +++ b/core/test/ch/asynk/tankontank/Helpers.java @@ -9,7 +9,7 @@ import ch.asynk.tankontank.engine.Tile; import ch.asynk.tankontank.engine.Board; import ch.asynk.tankontank.engine.Orientation; import ch.asynk.tankontank.engine.SearchBoard; -import ch.asynk.tankontank.engine.PossiblePaths; +import ch.asynk.tankontank.engine.PathBuilder; public class Helpers { @@ -95,7 +95,7 @@ public class Helpers { public FakePawn pawn; public FakeTile fakeTiles[]; - public PossiblePaths possiblePaths; + public PathBuilder pathBuilder; public FakeBoard(int cols, int rows, int mvt) { @@ -117,7 +117,7 @@ public class Helpers fakeTiles[108 - 2].offMap = true; pawn = new FakePawn(mvt); - possiblePaths = new PossiblePaths(this, 10, 20, 5, 10); + pathBuilder = new PathBuilder(this, 10, 20, 5, 10); } @Override @@ -129,15 +129,15 @@ public class Helpers return fakeTiles[i]; } - public int buildPossiblePaths(int x0, int y0, int x1, int y1) + public int buildPathBuilder(int x0, int y0, int x1, int y1) { - possiblePaths.init(pawn, getTile(x0, y0)); - return possiblePaths.build(getTile(x1, y1)); + pathBuilder.init(pawn, getTile(x0, y0)); + return pathBuilder.build(getTile(x1, y1)); } public int togglePoint(int x, int y) { - return possiblePaths.toggleCtrlTile(getTile(x, y)); + return pathBuilder.toggleCtrlTile(getTile(x, y)); } } } -- cgit v1.1-2-g2b99