summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2014-11-05 10:34:21 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2014-11-05 10:34:21 +0100
commit193a61e3ec86ac2383f4a222194bda6d8c46221b (patch)
tree937f5491625494df73098b2a2dcc2d66e5ca2b78 /core/src/ch/asynk
parentc1b741955570b98003e81ba054cb6c217b9c3d0b (diff)
downloadRustAndDust-193a61e3ec86ac2383f4a222194bda6d8c46221b.zip
RustAndDust-193a61e3ec86ac2383f4a222194bda6d8c46221b.tar.gz
Board: add Tile getAdjTileAt(Tile, Orientation) and Tile findBestEntry(Pawn, Tile, Orientation)
Diffstat (limited to 'core/src/ch/asynk')
-rw-r--r--core/src/ch/asynk/tankontank/engine/Board.java63
1 files changed, 63 insertions, 0 deletions
diff --git a/core/src/ch/asynk/tankontank/engine/Board.java b/core/src/ch/asynk/tankontank/engine/Board.java
index d4271ef..28e5c6a 100644
--- a/core/src/ch/asynk/tankontank/engine/Board.java
+++ b/core/src/ch/asynk/tankontank/engine/Board.java
@@ -187,6 +187,32 @@ public abstract class Board implements Disposable
tiles[5] = getTile((tile.col - 1), (tile.row - 1));
}
+ public Tile getAdjTileAt(Tile tile, Orientation o)
+ {
+ Tile t = null;
+ switch(o) {
+ case NORTH:
+ t = getTile((tile.col + 1), tile.row);
+ break;
+ case NORTH_EAST:
+ t = getTile(tile.col, (tile.row - 1));
+ break;
+ case SOUTH_EAST:
+ t = getTile((tile.col - 1), (tile.row - 1));
+ break;
+ case SOUTH:
+ t = getTile((tile.col - 1), tile.row);
+ break;
+ case SOUTH_WEST:
+ t = getTile(tile.col, (tile.row + 1));
+ break;
+ case NORTH_WEST:
+ t = getTile((tile.col + 1), (tile.row + 1));
+ break;
+ }
+ return t;
+ }
+
protected void addAnimation(Animation a)
{
nextAnimations.add(a);
@@ -318,6 +344,43 @@ public abstract class Board implements Disposable
return assists.size();
}
+ public Tile findBestEntry(Pawn pawn, Tile to, Orientation from)
+ {
+ // FIXME board corners
+ Tile entry = null;
+ int cost = Integer.MAX_VALUE;
+ boolean road = false;
+
+ Orientation o = from.opposite().left();
+ boolean r = to.road(o);
+ int c = to.costFrom(pawn, o);
+ if ((c < cost) || (r && (c == cost))) {
+ entry = getAdjTileAt(to, o);
+ cost = c;
+ road = r;
+ }
+
+ o = from.opposite();
+ r = to.road(o);
+ c = to.costFrom(pawn, o);
+ if ((c < cost) || (r && (c == cost))) {
+ entry = getAdjTileAt(to, o);
+ cost = c;
+ road = r;
+ }
+
+ o = from.opposite().right();
+ r = to.road(o);
+ c = to.costFrom(pawn, o);
+ if ((c < cost) || (r && (c == cost))) {
+ entry = getAdjTileAt(to, o);
+ cost = c;
+ road = r;
+ }
+
+ return entry;
+ }
+
public void enableOverlayOn(Tile tile, int i, boolean enable)
{
if(tile.enableOverlay(i, enable))