diff options
author | Markus Uhlin <markus@nifty-networks.net> | 2024-05-04 12:55:41 +0200 |
---|---|---|
committer | Markus Uhlin <markus@nifty-networks.net> | 2024-05-04 12:55:41 +0200 |
commit | 5568dbb33da1edfc836de8dc370ee5c7986275e7 (patch) | |
tree | 1b2eb8a18b55fc851349834c9333899a915b78e0 /FICS/gamedb.c | |
parent | 2171d2fbf5bf5b36b73b79e075a64aae7184e5c3 (diff) |
Reformatted ReadGameState()
Diffstat (limited to 'FICS/gamedb.c')
-rw-r--r-- | FICS/gamedb.c | 81 |
1 files changed, 47 insertions, 34 deletions
diff --git a/FICS/gamedb.c b/FICS/gamedb.c index d5ea043..23891d4 100644 --- a/FICS/gamedb.c +++ b/FICS/gamedb.c @@ -771,41 +771,54 @@ PRIVATE void WriteGameState(FILE * fp, game_state_t *gs) fprintf(fp, " %d %d %d\n", gs->lastIrreversable, gs->onMove, gs->moveNum); } -PRIVATE int ReadGameState(FILE * fp, game_state_t *gs, int version) +PRIVATE int +ReadGameState(FILE *fp, game_state_t *gs, int version) { - int i, j; - char pieceChar; - int wkmoved, wqrmoved, wkrmoved, bkmoved, bqrmoved, bkrmoved; - - if (version == 0) { - for (i = 0; i < 8; i++) - for (j = 0; j < 8; j++) - if (fscanf(fp, "%d ", &gs->board[i][j]) != 1) - return -1; - } else { - getc(fp); /* Skip past a newline. */ - for (i = 0; i < 8; i++) - for (j = 0; j < 8; j++) { - pieceChar = getc(fp); - gs->board[i][j] = CharToPiece(pieceChar); - } - } - if (fscanf(fp, "%d %d %d %d %d %d", - &wkmoved, &wqrmoved, &wkrmoved, - &bkmoved, &bqrmoved, &bkrmoved) != 6) - return -1; - gs->wkmoved = wkmoved; - gs->wqrmoved = wqrmoved; - gs->wkrmoved = wkrmoved; - gs->bkmoved = bkmoved; - gs->bqrmoved = bqrmoved; - gs->bkrmoved = bkrmoved; - for (i = 0; i < 8; i++) - if (fscanf(fp, " %d %d", &gs->ep_possible[0][i], &gs->ep_possible[1][i]) != 2) - return -1; - if (fscanf(fp, " %d %d %d\n", &gs->lastIrreversable, &gs->onMove, &gs->moveNum) != 3) - return -1; - return 0; + char pieceChar; + int i, j; + int wkmoved, wqrmoved, wkrmoved, bkmoved, bqrmoved, bkrmoved; + + if (version == 0) { + for (i = 0; i < 8; i++) { + for (j = 0; j < 8; j++) { + if (fscanf(fp, "%d ", &gs->board[i][j]) != 1) + return -1; + } + } + } else { + getc(fp); /* Skip past a newline. */ + + for (i = 0; i < 8; i++) { + for (j = 0; j < 8; j++) { + pieceChar = getc(fp); + gs->board[i][j] = CharToPiece(pieceChar); + } + } + } + + if (fscanf(fp, "%d %d %d %d %d %d", + &wkmoved, &wqrmoved, &wkrmoved, + &bkmoved, &bqrmoved, &bkrmoved) != 6) + return -1; + + gs->wkmoved = wkmoved; + gs->wqrmoved = wqrmoved; + gs->wkrmoved = wkrmoved; + + gs->bkmoved = bkmoved; + gs->bqrmoved = bqrmoved; + gs->bkrmoved = bkrmoved; + + for (i = 0; i < 8; i++) { + if (fscanf(fp, " %d %d", &gs->ep_possible[0][i], + &gs->ep_possible[1][i]) != 2) + return -1; + } + + if (fscanf(fp, " %d %d %d\n", &gs->lastIrreversable, &gs->onMove, + &gs->moveNum) != 3) + return -1; + return 0; } PUBLIC int |