aboutsummaryrefslogtreecommitdiffstats
path: root/FICS/movecheck.c
diff options
context:
space:
mode:
authorMarkus Uhlin <markus@nifty-networks.net>2024-03-16 20:53:45 +0100
committerMarkus Uhlin <markus@nifty-networks.net>2024-03-16 20:53:45 +0100
commit28dc2710c3899a8e6835002d131fad10867bc975 (patch)
tree8d01f1c640c8e22b7977b95743fbf8f60b4dc72c /FICS/movecheck.c
parenta8a7a56b60ae26c68e9cc5cbd52c07be0f637afe (diff)
Reformatted in_check()
Diffstat (limited to 'FICS/movecheck.c')
-rw-r--r--FICS/movecheck.c63
1 files changed, 35 insertions, 28 deletions
diff --git a/FICS/movecheck.c b/FICS/movecheck.c
index eae82bd..790b94b 100644
--- a/FICS/movecheck.c
+++ b/FICS/movecheck.c
@@ -756,38 +756,45 @@ PUBLIC int legal_andcheck_move(game_state_t * gs,
return 0;
}
-PUBLIC int in_check(game_state_t * gs)
+PUBLIC int
+in_check(game_state_t * gs)
{
- int f, r;
- int kf = -1, kr = -1;
+ int f, r;
+ int kf = -1, kr = -1;
+
+ /* Find the king */
+ if (gs->onMove == WHITE) {
+ for (f = 0; f < 8 && kf < 0; f++) {
+ for (r = 0; r < 8 && kf < 0; r++) {
+ if (gs->board[f][r] == B_KING) {
+ kf = f;
+ kr = r;
+ }
+ }
+ }
+ } else {
+ for (f = 0; f < 8 && kf < 0; f++) {
+ for (r = 0; r < 8 && kf < 0; r++) {
+ if (gs->board[f][r] == W_KING) {
+ kf = f;
+ kr = r;
+ }
+ }
+ }
+ }
- /* Find the king */
- if (gs->onMove == WHITE) {
- for (f = 0; f < 8 && kf < 0; f++)
- for (r = 0; r < 8 && kf < 0; r++)
- if (gs->board[f][r] == B_KING) {
- kf = f;
- kr = r;
+ if (kf < 0) {
+ fprintf(stderr, "FICS: Error game with no king!\n");
+ return 0;
}
- } else {
- for (f = 0; f < 8 && kf < 0; f++)
- for (r = 0; r < 8 && kf < 0; r++)
- if (gs->board[f][r] == W_KING) {
- kf = f;
- kr = r;
+
+ for (InitPieceLoop(gs->board, &f, &r, gs->onMove);
+ NextPieceLoop(gs->board, &f, &r, gs->onMove);) {
+ if (legal_move(gs, f, r, kf, kr)) // In Check?
+ return 1;
}
- }
- if (kf < 0) {
- fprintf(stderr, "FICS: Error game with no king!\n");
- return 0;
- }
- for (InitPieceLoop(gs->board, &f, &r, gs->onMove);
- NextPieceLoop(gs->board, &f, &r, gs->onMove);) {
- if (legal_move(gs, f, r, kf, kr)) { /* In Check? */
- return 1;
- }
- }
- return 0;
+
+ return 0;
}
PRIVATE int