# HG changeset patch # User Mike Becker # Date 1535543113 -7200 # Node ID 611332453da08b9e95e5ebb2f938478861662f27 # Parent 564af8a16828533dcc1db0aff3d62157eb4341c6 move log has now three columns and starts scrolling after 45 moves diff -r 564af8a16828 -r 611332453da0 src/chess/rules.c --- a/src/chess/rules.c Tue Aug 28 15:56:33 2018 +0200 +++ b/src/chess/rules.c Wed Aug 29 13:45:13 2018 +0200 @@ -171,10 +171,12 @@ gamestate->lastmove->next = elem; gamestate->lastmove = elem; + gamestate->movecount++; } else { elem->move.movetime.tv_usec = 0; elem->move.movetime.tv_sec = 0; gamestate->movelist = gamestate->lastmove = elem; + gamestate->movecount = 1; } } diff -r 564af8a16828 -r 611332453da0 src/chess/rules.h --- a/src/chess/rules.h Tue Aug 28 15:56:33 2018 +0200 +++ b/src/chess/rules.h Wed Aug 29 13:45:13 2018 +0200 @@ -112,6 +112,7 @@ Board board; MoveList* movelist; MoveList* lastmove; + unsigned int movecount; /* number of (half-)moves (counting BOTH colors) */ _Bool checkmate; _Bool stalemate; _Bool remis; diff -r 564af8a16828 -r 611332453da0 src/game.c --- a/src/game.c Tue Aug 28 15:56:33 2018 +0200 +++ b/src/game.c Wed Aug 29 13:45:13 2018 +0200 @@ -38,7 +38,7 @@ #include #include -static const uint8_t boardx = 10, boardy = 10; +static const uint8_t boardx = 4, boardy = 10; static int inputy = 21; /* should be overridden on game startup */ static int timecontrol(GameState *gamestate, GameInfo *gameinfo) { @@ -112,29 +112,32 @@ } /* move log */ - // TODO: introduce window to avoid bugs with a long move log - uint8_t logy = 1; - const uint8_t logx = boardx + 30; - int logi = 1; + uint8_t logy = 2; + const uint8_t logx = boardx + 28; + move(logy, logx); + + unsigned int logi = 0; MoveList *logelem = gamestate->movelist; + /* wrap log after 45 moves */ + while (gamestate->movecount/6-logi/3 >= 15) { + logelem = logelem->next->next; + logi++; + } + while (logelem) { - logi++; - if (logi % 2 == 0) { - if ((logi - 2) % 4 == 0) { - logy++; - move(logy, logx); - } - printw("%d. ", logi / 2); + _Bool iswhite = (logelem->move.piece & COLOR_MASK) == WHITE; + if (iswhite) { + logi++; + printw("%d. ", logi); } addstr(logelem->move.string); - if (!logelem->next) { - if (gamestate->stalemate) { - addstr(" stalemate"); - } + if (!iswhite && logi%3 == 0) { + move(++logy, logx); + } else { + addch(' '); } - addch(' '); logelem = logelem->next; }