summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2014-10-01 09:33:00 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2014-10-01 09:33:00 +0200
commitb5bf236a20c7465ad0ba7839f80d1d2a71848b34 (patch)
treea6403138656d8b70677a9290dc974a5dbf5b14f9 /core/src/ch/asynk
parentfbb91b22c5bcbc22a83aeda96e9992bf786c2f97 (diff)
downloadRustAndDust-b5bf236a20c7465ad0ba7839f80d1d2a71848b34.zip
RustAndDust-b5bf236a20c7465ad0ba7839f80d1d2a71848b34.tar.gz
Board.distance() -> SearchBoard.distance()
Diffstat (limited to 'core/src/ch/asynk')
-rw-r--r--core/src/ch/asynk/tankontank/engine/Board.java21
-rw-r--r--core/src/ch/asynk/tankontank/engine/SearchBoard.java19
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]