aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--FICS/movecheck.c77
1 files changed, 45 insertions, 32 deletions
diff --git a/FICS/movecheck.c b/FICS/movecheck.c
index 28d0bac..69b8293 100644
--- a/FICS/movecheck.c
+++ b/FICS/movecheck.c
@@ -194,39 +194,52 @@ PRIVATE int legal_knight_move(game_state_t * gs, int ff, int fr, int tf, int tr)
return 0;
}
-PRIVATE int legal_bishop_move(game_state_t * gs, int ff, int fr, int tf, int tr)
+PRIVATE int
+legal_bishop_move(game_state_t *gs, int ff, int fr, int tf, int tr)
{
- int dx, dy, x, y;
- int startx, starty;
- int count;
- int incx, incy;
-
- if (ff > tf) {
- dx = ff - tf;
- incx = -1;
- } else {
- dx = tf - ff;
- incx = 1;
- }
- startx = ff + incx;
- if (fr > tr) {
- dy = fr - tr;
- incy = -1;
- } else {
- dy = tr - fr;
- incy = 1;
- }
- starty = fr + incy;
- if (dx != dy)
- return 0; /* Not diagonal */
- if (dx == 1)
- return 1; /* One square, ok */
- count = dx - 1;
- for (x = startx, y = starty; count; x += incx, y += incy, count--) {
- if (gs->board[x][y] != NOPIECE)
- return 0;
- }
- return 1;
+ int count;
+ int dx, dy, x, y;
+ int incx, incy;
+ int startx, starty;
+
+ if (ff > tf) {
+ dx = ff - tf;
+ incx = -1;
+ } else {
+ dx = tf - ff;
+ incx = 1;
+ }
+
+ startx = ff + incx;
+
+ if (fr > tr) {
+ dy = fr - tr;
+ incy = -1;
+ } else {
+ dy = tr - fr;
+ incy = 1;
+ }
+
+ starty = fr + incy;
+
+ if (dx != dy)
+ return 0; // Not diagonal
+ if (dx == 1)
+ return 1; // One square, ok.
+
+ count = dx - 1;
+ x = startx;
+ y = starty;
+
+ while (count) {
+ if (gs->board[x][y] != NOPIECE)
+ return 0;
+ x += incx;
+ y += incy;
+ count--;
+ }
+
+ return 1;
}
PRIVATE int