aboutsummaryrefslogtreecommitdiffstats
path: root/FICS
diff options
context:
space:
mode:
authorMarkus Uhlin <markus@nifty-networks.net>2024-03-17 21:37:56 +0100
committerMarkus Uhlin <markus@nifty-networks.net>2024-03-17 21:37:56 +0100
commit96d81730bada204542411f34e3d945416fed48e0 (patch)
tree299b1b54d4f3b51eaac025ee5056ca5a14770c02 /FICS
parent445ce459ce967b469fcd83b405858d91b4e9f7d7 (diff)
Reformatted legal_bishop_move() and replaced the for-loop with a while-loop
Diffstat (limited to 'FICS')
-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