From 3eef4dae35c7b939c2c8ede377f6274b6a67d81c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Tue, 9 Jun 2020 07:14:43 +0200 Subject: Piece : add atLeastOneTileMove() --- core/src/ch/asynk/gdx/boardgame/Piece.java | 5 +++++ core/src/ch/asynk/gdx/boardgame/boards/HexBoard.java | 2 +- test/src/ch/asynk/gdx/boardgame/test/HexScreen.java | 3 ++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/core/src/ch/asynk/gdx/boardgame/Piece.java b/core/src/ch/asynk/gdx/boardgame/Piece.java index 6944afc..5f47309 100644 --- a/core/src/ch/asynk/gdx/boardgame/Piece.java +++ b/core/src/ch/asynk/gdx/boardgame/Piece.java @@ -134,4 +134,9 @@ public class Piece implements Drawable, Positionable, Rotable, Scalable // Integer.MAX_VALUE means impracticable return Integer.MAX_VALUE; } + + public boolean atLeastOneTileMove() + { + return true; + } } diff --git a/core/src/ch/asynk/gdx/boardgame/boards/HexBoard.java b/core/src/ch/asynk/gdx/boardgame/boards/HexBoard.java index 639741e..e04f91e 100644 --- a/core/src/ch/asynk/gdx/boardgame/boards/HexBoard.java +++ b/core/src/ch/asynk/gdx/boardgame/boards/HexBoard.java @@ -492,7 +492,7 @@ public class HexBoard implements Board if (cost == Integer.MAX_VALUE) continue; // impracticable int r = src.acc - cost; - if (r < 0 && src != from) continue; // allow at least 1 tile move + if (r < 0 && !(src == from && piece.atLeastOneTileMove())) continue; // allow at least 1 tile move if (dst.searchCount != searchCount) { dst.searchCount = searchCount; diff --git a/test/src/ch/asynk/gdx/boardgame/test/HexScreen.java b/test/src/ch/asynk/gdx/boardgame/test/HexScreen.java index 0a1494c..e60ebe2 100644 --- a/test/src/ch/asynk/gdx/boardgame/test/HexScreen.java +++ b/test/src/ch/asynk/gdx/boardgame/test/HexScreen.java @@ -47,9 +47,10 @@ class Unit extends Piece @Override public int moveCost(Tile from, Tile to, Orientation orientation) { + Terrain dst = ((Hex)to).terrain; + if (dst == Terrain.HILL) return 3; if (!hardTarget) return 1; if (orientation.belongsTo(((Hex)from).roads)) return 1; - Terrain dst = ((Hex)to).terrain; if (dst.difficult()) return 2; return 1; } -- cgit v1.1-2-g2b99