summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk/tankontank/engine
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2014-10-01 11:29:03 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2014-10-01 11:29:03 +0200
commit32705832a647b2f882da07b27d274bfda3de5344 (patch)
tree5e46436c373dabff38dc62c8fbf7353ddd575360 /core/src/ch/asynk/tankontank/engine
parent048f714663da82a70dc7423881daf7b9195a32d9 (diff)
downloadRustAndDust-32705832a647b2f882da07b27d274bfda3de5344.zip
RustAndDust-32705832a647b2f882da07b27d274bfda3de5344.tar.gz
SearchBoard: adjacents is now local to function
Diffstat (limited to 'core/src/ch/asynk/tankontank/engine')
-rw-r--r--core/src/ch/asynk/tankontank/engine/SearchBoard.java54
1 files changed, 28 insertions, 26 deletions
diff --git a/core/src/ch/asynk/tankontank/engine/SearchBoard.java b/core/src/ch/asynk/tankontank/engine/SearchBoard.java
index 8c5b93a..1ac52bc 100644
--- a/core/src/ch/asynk/tankontank/engine/SearchBoard.java
+++ b/core/src/ch/asynk/tankontank/engine/SearchBoard.java
@@ -28,7 +28,6 @@ public class SearchBoard
private Board board;
private int searchCount;
private Node nodes[];
- private Node adjacents[];
private Board.Orientation sides[];
private ArrayDeque<Node> stack;
@@ -53,7 +52,6 @@ public class SearchBoard
nodes[i + (j * cols)] = new Node((i + dx), j);
}
- this.adjacents = new Node[6];
this.sides = new Board.Orientation[6];
sides[0] = Board.Orientation.NORTH;
sides[1] = Board.Orientation.NORTH_EAST;
@@ -116,15 +114,15 @@ public class SearchBoard
}
}
- public void adjacentMoves(Node src)
+ public void adjacentMoves(Node src, Node a[])
{
// move to enter dst by sides[i]
- adjacents[0] = getNode((src.col - 1), src.row);
- adjacents[1] = getNode(src.col, (src.row + 1));
- adjacents[2] = getNode((src.col + 1), (src.row + 1));
- adjacents[3] = getNode((src.col + 1), src.row);
- adjacents[4] = getNode(src.col, (src.row - 1));
- adjacents[5] = getNode((src.col - 1), (src.row - 1));
+ a[0] = getNode((src.col - 1), src.row);
+ a[1] = getNode(src.col, (src.row + 1));
+ a[2] = getNode((src.col + 1), (src.row + 1));
+ a[3] = getNode((src.col + 1), src.row);
+ a[4] = getNode(src.col, (src.row - 1));
+ a[5] = getNode((src.col - 1), (src.row - 1));
}
public List<Node> possibleMovesFrom(Pawn pawn, int col, int row)
@@ -132,6 +130,8 @@ public class SearchBoard
searchCount += 1;
moves.clear();
+ Node adjacents[] = new Node[6];
+
Node from = getNode(col, row);
from.parent = null;
from.search = searchCount;
@@ -157,7 +157,7 @@ public class SearchBoard
continue;
}
- adjacentMoves(src);
+ adjacentMoves(src, adjacents);
for(int i = 0; i < 6; i++) {
Node dst = adjacents[i];
@@ -197,7 +197,7 @@ public class SearchBoard
while(roadMarch.size() != 0) {
Node src = roadMarch.pop();
- adjacentMoves(src);
+ adjacentMoves(src, adjacents);
for(int i = 0; i < 6; i++) {
Node dst = adjacents[i];
@@ -235,38 +235,38 @@ public class SearchBoard
return moves;
}
- private void adjacentTargets(Node src, int angle)
+ private void adjacentTargets(Node src, int angle, Node a[])
{
// move in allowed directions
if (Board.Orientation.NORTH.isInSides(angle))
- adjacents[0] = getNode((src.col + 1), src.row);
+ a[0] = getNode((src.col + 1), src.row);
else
- adjacents[0] = null;
+ a[0] = null;
if (Board.Orientation.NORTH_EAST.isInSides(angle))
- adjacents[1] = getNode(src.col, (src.row - 1));
+ a[1] = getNode(src.col, (src.row - 1));
else
- adjacents[1] = null;
+ a[1] = null;
if (Board.Orientation.SOUTH_EAST.isInSides(angle))
- adjacents[2] = getNode((src.col - 1), (src.row - 1));
+ a[2] = getNode((src.col - 1), (src.row - 1));
else
- adjacents[2] = null;
+ a[2] = null;
if (Board.Orientation.SOUTH.isInSides(angle))
- adjacents[3] = getNode((src.col - 1), src.row);
+ a[3] = getNode((src.col - 1), src.row);
else
- adjacents[3] = null;
+ a[3] = null;
if (Board.Orientation.SOUTH_WEST.isInSides(angle))
- adjacents[4] = getNode(src.col, (src.row + 1));
+ a[4] = getNode(src.col, (src.row + 1));
else
- adjacents[4] = null;
+ a[4] = null;
if (Board.Orientation.NORTH_WEST.isInSides(angle))
- adjacents[5] = getNode((src.col + 1), (src.row + 1));
+ a[5] = getNode((src.col + 1), (src.row + 1));
else
- adjacents[5] = null;
+ a[5] = null;
}
public List<Node> possibleTargetsFrom(Pawn pawn, int col, int row)
@@ -274,6 +274,8 @@ public class SearchBoard
searchCount += 1;
targets.clear();
+ Node adjacents[] = new Node[6];
+
Tile tile = board.getTile(col, row);
int range = pawn.getAttackRangeFrom(tile);
@@ -297,9 +299,9 @@ public class SearchBoard
continue;
if (!first && (((range - src.remaining) % 2) == 0))
- adjacentTargets(src, extendedAngle);
+ adjacentTargets(src, extendedAngle, adjacents);
else
- adjacentTargets(src, angle);
+ adjacentTargets(src, angle, adjacents);
first = false;
int rangeLeft = src.remaining - 1;