From 0ff51a456823af3a416f16d2bb92427a4c9f3d68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Wed, 1 Oct 2014 14:08:46 +0200 Subject: Board: add possiblePaths(Pawn, int, int, int, int, Set) --- core/src/ch/asynk/tankontank/engine/Board.java | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/core/src/ch/asynk/tankontank/engine/Board.java b/core/src/ch/asynk/tankontank/engine/Board.java index 3d8afd5..8884b0f 100644 --- a/core/src/ch/asynk/tankontank/engine/Board.java +++ b/core/src/ch/asynk/tankontank/engine/Board.java @@ -1,5 +1,6 @@ package ch.asynk.tankontank.engine; +import java.util.Set; import java.util.List; import java.util.Vector; import java.util.Iterator; @@ -335,16 +336,35 @@ public abstract class Board implements Disposable public void possibleMovesFrom(Pawn pawn, int col, int row, Vector moves) { - List nodes = searchBoard.possibleMovesFrom(pawn, col, row); + List nodes = searchBoard.possibleMovesFrom(pawn, col, row); nodesToPoints(nodes, moves); } public void possibleTargetsFrom(Pawn pawn, int col, int row, Vector targets) { - List nodes = searchBoard.possibleTargetsFrom(pawn, col, row); + List nodes = searchBoard.possibleTargetsFrom(pawn, col, row); nodesToPoints(nodes, targets); } + public void possiblePaths(Pawn pawn, int col0, int row0, int col1, int row1, Set points) + { + // FIXME : optimize this + for (GridPoint2 point : points) + gridPoint2Pool.free(point); + points.clear(); + + List> paths = searchBoard.possiblePaths(pawn, col0, row0, col1, row1); + for (Vector path : paths) { + for (int i = 0, n = path.size(); i < n; i++) { + GridPoint2 point = gridPoint2Pool.obtain(); + SearchBoard.Node node = path.get(i); + point.set(node.col, node.row); + if (!points.add(point)) + gridPoint2Pool.free(point); + } + } + } + public void disableOverlaysOn(int col, int row) { disableOverlaysOn(getTile(col, row)); -- cgit v1.1-2-g2b99