summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk/tankontank
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/ch/asynk/tankontank')
-rw-r--r--core/src/ch/asynk/tankontank/engine/Board.java3
-rw-r--r--core/src/ch/asynk/tankontank/engine/SearchBoard.java16
-rw-r--r--core/src/ch/asynk/tankontank/engine/TileList.java12
3 files changed, 23 insertions, 8 deletions
diff --git a/core/src/ch/asynk/tankontank/engine/Board.java b/core/src/ch/asynk/tankontank/engine/Board.java
index b8ded2d..7b6a414 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.ArrayList;
import java.util.Iterator;
@@ -241,7 +242,7 @@ public abstract class Board implements Disposable
protected int buildPossibleMoves(Pawn pawn, TileList moves)
{
Tile from = pawn.getTile();
- List<SearchBoard.Node> nodes = searchBoard.possibleMovesFrom(pawn, from.getCol(), from.getRow());
+ Set<SearchBoard.Node> nodes = searchBoard.possibleMovesFrom(pawn, from.getCol(), from.getRow());
return moves.fromNodes(nodes);
}
diff --git a/core/src/ch/asynk/tankontank/engine/SearchBoard.java b/core/src/ch/asynk/tankontank/engine/SearchBoard.java
index 46af16b..668899b 100644
--- a/core/src/ch/asynk/tankontank/engine/SearchBoard.java
+++ b/core/src/ch/asynk/tankontank/engine/SearchBoard.java
@@ -1,9 +1,11 @@
package ch.asynk.tankontank.engine;
import java.util.List;
-import java.util.ArrayDeque;
-import java.util.LinkedList;
import java.util.ArrayList;
+import java.util.Set;
+import java.util.LinkedHashSet;
+import java.util.LinkedList;
+import java.util.ArrayDeque;
public class SearchBoard
{
@@ -40,7 +42,7 @@ public class SearchBoard
private LinkedList<Node> queue;
private ArrayDeque<Node> roadMarch;
- private List<Node> moves;
+ private Set<Node> moves;
private List<Node> targets;
private List<Node> los;
@@ -74,7 +76,7 @@ public class SearchBoard
this.stack = new ArrayDeque<Node>(20);
this.roadMarch = new ArrayDeque<Node>(5);
- this.moves = new ArrayList<Node>(40);
+ this.moves = new LinkedHashSet<Node>(40);
this.targets = new ArrayList<Node>(10);
this.los = new ArrayList<Node>(10);
@@ -139,7 +141,7 @@ public class SearchBoard
a[5] = getNode((src.col - 1), (src.row - 1));
}
- public List<Node> possibleMovesFrom(Pawn pawn, int col, int row)
+ public Set<Node> possibleMovesFrom(Pawn pawn, int col, int row)
{
searchCount += 1;
moves.clear();
@@ -190,7 +192,7 @@ public class SearchBoard
dst.parent = src;
dst.roadMarch = roadMarch;
stack.push(dst);
- if (!moves.contains(dst)) moves.add(dst);
+ moves.add(dst);
}
} else {
dst.search = searchCount;
@@ -232,7 +234,7 @@ public class SearchBoard
dst.parent = src;
dst.roadMarch = true;
roadMarch.push(dst);
- if (!moves.contains(dst)) moves.add(dst);
+ moves.add(dst);
}
} else {
dst.search = searchCount;
diff --git a/core/src/ch/asynk/tankontank/engine/TileList.java b/core/src/ch/asynk/tankontank/engine/TileList.java
index 4f27057..8d9078d 100644
--- a/core/src/ch/asynk/tankontank/engine/TileList.java
+++ b/core/src/ch/asynk/tankontank/engine/TileList.java
@@ -1,5 +1,6 @@
package ch.asynk.tankontank.engine;
+import java.util.Set;
import java.util.List;
import java.util.ArrayList;
@@ -26,6 +27,17 @@ public class TileList extends ArrayList<Tile>
return size();
}
+ public int fromNodes(Set<SearchBoard.Node> nodes)
+ {
+ clear();
+ for (SearchBoard.Node node : nodes) {
+ Tile tile = board.getTile(node.col, node.row);
+ add(tile);
+ }
+
+ return size();
+ }
+
public void show()
{
enable(overlay, true);