aboutsummaryrefslogtreecommitdiffstats
path: root/FICS/movecheck.c
diff options
context:
space:
mode:
authorMarkus Uhlin <markus@nifty-networks.net>2024-03-17 21:58:51 +0100
committerMarkus Uhlin <markus@nifty-networks.net>2024-03-17 21:58:51 +0100
commitc37aab377021b45c86c6c19856cb2bb08ddbcedc (patch)
treecb1a2d597d4781a95dbc1f3e920ea9f1c79bf0ed /FICS/movecheck.c
parent0adb8adf8a6f401aa3ded334b1e79d7b2369a534 (diff)
Reformatted functions
Diffstat (limited to 'FICS/movecheck.c')
-rw-r--r--FICS/movecheck.c118
1 files changed, 76 insertions, 42 deletions
diff --git a/FICS/movecheck.c b/FICS/movecheck.c
index 10f8744..ce4db9a 100644
--- a/FICS/movecheck.c
+++ b/FICS/movecheck.c
@@ -129,52 +129,86 @@ PUBLIC int NextPieceLoop(board_t b, int *f, int *r, int color)
return 0;
}
-PUBLIC int InitPieceLoop(board_t b, int *f, int *r, int color)
+PUBLIC int
+InitPieceLoop(board_t b, int *f, int *r, int color)
{
- *f = 0;
- *r = -1;
- return 1;
+ *f = 0;
+ *r = -1;
+ return 1;
}
-/* All of the routines assume that the obvious problems have been checked */
-/* See legal_move() */
-PRIVATE int legal_pawn_move( game_state_t *gs, int ff, int fr, int tf, int tr )
+/*
+ * All of the routines assume that the obvious problems have been
+ * checked. See legal_move().
+ */
+PRIVATE int
+legal_pawn_move(game_state_t *gs, int ff, int fr, int tf, int tr)
{
- if (ff == tf) {
- if (gs->board[tf][tr] != NOPIECE) return 0;
- if (gs->onMove == WHITE) {
- if (tr - fr == 1) return 1;
- if ((fr == 1) && (tr - fr == 2) && gs->board[ff][2]==NOPIECE) return 1;
- } else {
- if (fr - tr == 1) return 1;
- if ((fr == 6) && (fr - tr == 2) && gs->board[ff][5]==NOPIECE) return 1;
- }
- return 0;
- }
- if (ff != tf) { /* Capture ? */
- if ((ff - tf != 1) && (tf - ff != 1)) return 0;
- if ((fr - tr != 1) && (tr - fr != 1)) return 0;
- if (gs->onMove == WHITE) {
- if (fr > tr) return 0;
- if ((gs->board[tf][tr] != NOPIECE) && iscolor(gs->board[tf][tr],BLACK))
- return 1;
- if (gs->ep_possible[0][ff] == 1) {
- if ((tf==ff+1) && (gs->board[ff+1][fr] == B_PAWN)) return 1;
- } else if (gs->ep_possible[0][ff] == -1) {
- if ((tf==ff-1) && (gs->board[ff-1][fr] == B_PAWN)) return 1;
- }
- } else {
- if (tr > fr) return 0;
- if ((gs->board[tf][tr] != NOPIECE) && iscolor(gs->board[tf][tr],WHITE))
- return 1;
- if (gs->ep_possible[1][ff] == 1) {
- if ((tf==ff+1) && (gs->board[ff+1][fr] == W_PAWN)) return 1;
- } else if (gs->ep_possible[1][ff] == -1) {
- if ((tf==ff-1) && (gs->board[ff-1][fr] == W_PAWN)) return 1;
- }
- }
- }
- return 0;
+ if (ff == tf) {
+ if (gs->board[tf][tr] != NOPIECE)
+ return 0;
+
+ if (gs->onMove == WHITE) {
+ if (tr - fr == 1)
+ return 1;
+ if (fr == 1 &&
+ (tr - fr) == 2 &&
+ gs->board[ff][2] == NOPIECE)
+ return 1;
+ } else {
+ if (fr - tr == 1)
+ return 1;
+ if (fr == 6 &&
+ (fr - tr) == 2 &&
+ gs->board[ff][5] == NOPIECE)
+ return 1;
+ }
+
+ return 0;
+ }
+
+ if (ff != tf) { // Capture ?
+ if ((ff - tf) != 1 && (tf - ff) != 1)
+ return 0;
+ if ((fr - tr) != 1 && (tr - fr) != 1)
+ return 0;
+
+ if (gs->onMove == WHITE) {
+ if (fr > tr)
+ return 0;
+ if (gs->board[tf][tr] != NOPIECE &&
+ iscolor(gs->board[tf][tr], BLACK))
+ return 1;
+
+ if (gs->ep_possible[0][ff] == 1) {
+ if (tf == (ff + 1) && gs->board[ff + 1][fr] ==
+ B_PAWN)
+ return 1;
+ } else if (gs->ep_possible[0][ff] == -1) {
+ if (tf == (ff - 1) && gs->board[ff - 1][fr] ==
+ B_PAWN)
+ return 1;
+ }
+ } else {
+ if (tr > fr)
+ return 0;
+ if (gs->board[tf][tr] != NOPIECE &&
+ iscolor(gs->board[tf][tr], WHITE))
+ return 1;
+
+ if (gs->ep_possible[1][ff] == 1) {
+ if (tf == (ff + 1) && gs->board[ff + 1][fr] ==
+ W_PAWN)
+ return 1;
+ } else if (gs->ep_possible[1][ff] == -1) {
+ if (tf == (ff - 1) && gs->board[ff - 1][fr] ==
+ W_PAWN)
+ return 1;
+ }
+ }
+ }
+
+ return 0;
}
PRIVATE int