diff options
Diffstat (limited to 'core/src')
-rw-r--r-- | core/src/ch/asynk/tankontank/engine/Board.java | 21 | ||||
-rw-r--r-- | core/src/ch/asynk/tankontank/engine/SearchBoard.java | 19 |
2 files changed, 19 insertions, 21 deletions
diff --git a/core/src/ch/asynk/tankontank/engine/Board.java b/core/src/ch/asynk/tankontank/engine/Board.java index c8a927c..3e2d44f 100644 --- a/core/src/ch/asynk/tankontank/engine/Board.java +++ b/core/src/ch/asynk/tankontank/engine/Board.java @@ -190,27 +190,6 @@ public abstract class Board implements Disposable return tiles[idx]; } - public int distance(int col0, int row0, int col1, int row1) - { - int a = (row1 - row0); - int b = (col1 - col0); - int c = (b - a); - int aa = Math.abs(a); - int ab = Math.abs(b); - int ac = Math.abs(c); - if (ac > aa) { - if (ac > ab) - return ac; - else - return ab; - } else { - if (aa > ab) - return aa; - else - return ab; - } - } - public float getWidth() { return image.getWidth(); diff --git a/core/src/ch/asynk/tankontank/engine/SearchBoard.java b/core/src/ch/asynk/tankontank/engine/SearchBoard.java index 14c4334..fea114a 100644 --- a/core/src/ch/asynk/tankontank/engine/SearchBoard.java +++ b/core/src/ch/asynk/tankontank/engine/SearchBoard.java @@ -80,6 +80,25 @@ public class SearchBoard return nodes[((col - colOffset)) + (row * cols)]; } + public int distance(int col0, int row0, int col1, int row1) + { + int dx = Math.abs(col1 - col0); + int dy = Math.abs(row1 - row0); + int dz = Math.abs((col0 - row0) - (col1 - row1)); + + if (dx > dy) { + if (dx > dz) + return dx; + else + return dz; + } else { + if (dy > dz) + return dy; + else + return dz; + } + } + public void adjacentMoves(Node src) { // move to enter dst by sides[i] |