From 5fa83cfc23272e9717317f9779de1c411a9c60f8 Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Thu, 14 Jan 2010 14:24:43 +0100 Subject: [PATCH] coord_dx(), coord_dy(): Introduce --- move.h | 3 +++ tactics.h | 4 +--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/move.h b/move.h index 8fe1659..304069e 100644 --- a/move.h +++ b/move.h @@ -12,6 +12,9 @@ typedef int coord_t; #define coord_x(c, b) ((c) % board_size(b)) #define coord_y(c, b) ((c) / board_size(b)) #define coord_eq(c1, c2) ((c1) == (c2)) +/* TODO: Smarter way to do this? */ +#define coord_dx(c1, c2, b) (coord_x(c1, b) - coord_x(c2, b)) +#define coord_dy(c1, c2, b) (coord_y(c1, b) - coord_y(c2, b)) static coord_t pass = -1; static coord_t resign = -2; diff --git a/tactics.h b/tactics.h index 6ace5bb..b43962d 100644 --- a/tactics.h +++ b/tactics.h @@ -100,9 +100,7 @@ coord_edge_distance(coord_t c, struct board *b) static inline int coord_gridcular_distance(coord_t c1, coord_t c2, struct board *b) { - int x1 = coord_x(c1, b), y1 = coord_y(c1, b); - int x2 = coord_x(c2, b), y2 = coord_y(c2, b); - int dx = abs(x1 - x2), dy = abs(y1 - y2); + int dx = abs(coord_dx(c1, c2, b)), dy = abs(coord_dy(c1, c2, b)); return dx + dy + (dx > dy ? dx : dy); } -- 2.11.4.GIT