diff options
author | Markus Uhlin <markus@nifty-networks.net> | 2024-04-21 16:57:30 +0200 |
---|---|---|
committer | Markus Uhlin <markus@nifty-networks.net> | 2024-04-21 16:57:30 +0200 |
commit | df725ecc74c1bdad755a16c8cefb555f4926014e (patch) | |
tree | aa389d41056dfd9bc0b6420aa4cd1acd2f4de653 /FICS/obsproc.c | |
parent | 08f4a8d9e2f99cc8241df5eaa36562972d6162b5 (diff) |
Revised com_forward()
Diffstat (limited to 'FICS/obsproc.c')
-rw-r--r-- | FICS/obsproc.c | 169 |
1 files changed, 101 insertions, 68 deletions
diff --git a/FICS/obsproc.c b/FICS/obsproc.c index ad72ee2..ba47f0b 100644 --- a/FICS/obsproc.c +++ b/FICS/obsproc.c @@ -1178,78 +1178,111 @@ PUBLIC int com_sposition(int p, param_list param) return COM_OK; } -PUBLIC int com_forward(int p, param_list param) +PUBLIC int +com_forward(int p, param_list param) { - int nHalfMoves = 1; - int g, i; - int p1; - unsigned now; + int g, i; + int nHalfMoves = 1; + int p1; + unsigned int now; - if (!((parray[p].game >=0) &&(garray[parray[p].game].status == GAME_EXAMINE))) { - pprintf(p, "You are not examining any games.\n"); - return COM_OK; - } - g = parray[p].game; - if (!strcmp(garray[g].white_name, garray[g].black_name)) { - pprintf(p, "You cannot go forward; no moves are stored.\n"); - return COM_OK; - } - if (param[0].type == TYPE_INT) { - nHalfMoves = param[0].val.integer; - } - if (garray[g].numHalfMoves > garray[g].revertHalfMove) { - pprintf(p, "No more moves.\n"); - return COM_OK; - } - if (garray[g].numHalfMoves < garray[g].totalHalfMoves) { - for (p1 = 0; p1 < p_num; p1++) { - if (parray[p1].status != PLAYER_PROMPT) - continue; - if (player_is_observe(p1, g) || parray[p1].game == g) { - pprintf(p1, "%s goes forward %d move%s.\n", - parray[p].name, nHalfMoves, (nHalfMoves == 1) ? "" : "s"); - } - } - } - for (i = 0; i < nHalfMoves; i++) { - if (garray[g].numHalfMoves < garray[g].totalHalfMoves) { - execute_move(&garray[g].game_state, &garray[g].moveList[garray[g].numHalfMoves], 1); - if (garray[g].numHalfMoves + 1 > garray[g].examMoveListSize) { - garray[g].examMoveListSize += 20; /* Allocate 20 moves at a - time */ - if (!garray[g].examMoveList) { - garray[g].examMoveList = (move_t *) rmalloc(sizeof(move_t) * garray[g].examMoveListSize); - } else { - garray[g].examMoveList = (move_t *) rrealloc(garray[g].examMoveList, sizeof(move_t) * garray[g].examMoveListSize); + if (!(parray[p].game >= 0 && garray[parray[p].game].status == + GAME_EXAMINE)) { + pprintf(p, "You are not examining any games.\n"); + return COM_OK; } - } - garray[g].examMoveList[garray[g].numHalfMoves] = garray[g].moveList[garray[g].numHalfMoves]; - garray[g].revertHalfMove++; - garray[g].numHalfMoves++; - } else { - for (p1 = 0; p1 < p_num; p1++) { - if (parray[p1].status != PLAYER_PROMPT) - continue; - if (player_is_observe(p1, g) || parray[p1].game == g) { - pprintf(p1, "End of game.\n"); + + g = parray[p].game; + + if (!strcmp(garray[g].white_name, garray[g].black_name)) { + pprintf(p, "You cannot go forward; no moves are stored.\n"); + return COM_OK; } - } - break; - } - } - /* roll back time */ - if (garray[g].game_state.onMove == WHITE) { - garray[g].wTime += (garray[g].lastDecTime - garray[g].lastMoveTime); - } else { - garray[g].bTime += (garray[g].lastDecTime - garray[g].lastMoveTime); - } - now = tenth_secs(); - if (garray[g].numHalfMoves == 0) - garray[g].timeOfStart = now; - garray[g].lastMoveTime = now; - garray[g].lastDecTime = now; - send_boards(g); - return COM_OK; + + if (param[0].type == TYPE_INT) + nHalfMoves = param[0].val.integer; + + if (garray[g].numHalfMoves > garray[g].revertHalfMove) { + pprintf(p, "No more moves.\n"); + return COM_OK; + } + + if (garray[g].numHalfMoves < garray[g].totalHalfMoves) { + for (p1 = 0; p1 < p_num; p1++) { + if (parray[p1].status != PLAYER_PROMPT) + continue; + if (player_is_observe(p1, g) || parray[p1].game == g) { + pprintf(p1, "%s goes forward %d move%s.\n", + parray[p].name, + nHalfMoves, + (nHalfMoves == 1 ? "" : "s")); + } + } + } + + for (i = 0; i < nHalfMoves; i++) { + if (garray[g].numHalfMoves < garray[g].totalHalfMoves) { + execute_move(&garray[g].game_state, + &garray[g].moveList[garray[g].numHalfMoves], 1); + + if (garray[g].numHalfMoves + 1 > + garray[g].examMoveListSize) { + // Allocate 20 moves at a time. + garray[g].examMoveListSize += 20; + + if (!garray[g].examMoveList) { + garray[g].examMoveList = + reallocarray(NULL, + sizeof(move_t), + garray[g].examMoveListSize); + if (garray[g].examMoveList == NULL) + err(1, "%s", __func__); + malloc_count++; + } else { + garray[g].examMoveList = + reallocarray(garray[g].examMoveList, + sizeof(move_t), + garray[g].examMoveListSize); + if (garray[g].examMoveList == NULL) + err(1, "%s", __func__); + } + } + + garray[g].examMoveList[garray[g].numHalfMoves] = + garray[g].moveList[garray[g].numHalfMoves]; + garray[g].revertHalfMove++; + garray[g].numHalfMoves++; + } else { + for (p1 = 0; p1 < p_num; p1++) { + if (parray[p1].status != PLAYER_PROMPT) + continue; + if (player_is_observe(p1, g) || + parray[p1].game == g) + pprintf(p1, "End of game.\n"); + } + + break; + } + } + + // roll back time + if (garray[g].game_state.onMove == WHITE) { + garray[g].wTime += (garray[g].lastDecTime - + garray[g].lastMoveTime); + } else { + garray[g].bTime += (garray[g].lastDecTime - + garray[g].lastMoveTime); + } + + now = tenth_secs(); + + if (garray[g].numHalfMoves == 0) + garray[g].timeOfStart = now; + garray[g].lastMoveTime = now; + garray[g].lastDecTime = now; + + send_boards(g); + return COM_OK; } PUBLIC int |