summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2020-06-09 09:40:35 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2020-06-09 09:40:35 +0200
commita917b915de64a9647d5e792a81cc0765e4b5a177 (patch)
tree44d62b8f9ac8e8eb48cf9257384c257a0d2b74cc /core
parentea3d3d33042db994da60c8f51a7ddfdcc1b60671 (diff)
downloadgdx-boardgame-a917b915de64a9647d5e792a81cc0765e4b5a177.zip
gdx-boardgame-a917b915de64a9647d5e792a81cc0765e4b5a177.tar.gz
HexBoard : possibleMoves() supports roadMarch
Diffstat (limited to 'core')
-rw-r--r--core/src/ch/asynk/gdx/boardgame/boards/HexBoard.java15
1 files changed, 11 insertions, 4 deletions
diff --git a/core/src/ch/asynk/gdx/boardgame/boards/HexBoard.java b/core/src/ch/asynk/gdx/boardgame/boards/HexBoard.java
index e04f91e..1ee05ea 100644
--- a/core/src/ch/asynk/gdx/boardgame/boards/HexBoard.java
+++ b/core/src/ch/asynk/gdx/boardgame/boards/HexBoard.java
@@ -475,12 +475,14 @@ public class HexBoard implements Board
if (from.acc <= 0 || !from.isOnMap())
return tiles.size();
+ int roadMarchBonus = piece.roadMarchBonus();
+ from.roadMarch = roadMarchBonus > 0;
stack.push(from);
while(!stack.isEmpty()) {
final Tile src = stack.pop();
- if (src.acc <= 0) continue;
+ if ((src.acc + (src.roadMarch ? roadMarchBonus : 0)) <= 0) continue;
buildAdjacents(src.x, src.y);
for (int i = 0, j = 0; i < 6; i++, j++) {
@@ -488,21 +490,26 @@ public class HexBoard implements Board
if (!dst.isOnMap()) continue;
if (getAngles()[j] == -1) j++;
- int cost = piece.moveCost(src, dst, Orientation.fromR(getAngles()[j] + aOffset));
+ final Orientation o = Orientation.fromR(getAngles()[j] + aOffset);
+ int cost = piece.moveCost(src, dst, o);
if (cost == Integer.MAX_VALUE) continue; // impracticable
int r = src.acc - cost;
- if (r < 0 && !(src == from && piece.atLeastOneTileMove())) continue; // allow at least 1 tile move
+ boolean rm = src.roadMarch && src.hasRoad(o);
+ // not enough MP even with RM, maybe first move allowed
+ if ((r + (rm ? roadMarchBonus : 0)) < 0 && !(src == from && piece.atLeastOneTileMove())) continue;
if (dst.searchCount != searchCount) {
dst.searchCount = searchCount;
dst.acc = r;
dst.parent = src;
+ dst.roadMarch = rm;
stack.push(dst);
tiles.add(dst);
- } else if (r > dst.acc) {
+ } else if (r > dst.acc || (!dst.roadMarch && rm)) {
dst.acc = r;
dst.parent = src;
+ dst.roadMarch = rm;
stack.push(dst);
}
}