diff -r f87cad9445b4 -r 9cb41383540f src/game.c --- a/src/game.c Sat Apr 04 12:35:59 2026 +0200 +++ b/src/game.c Sat Apr 04 13:25:47 2026 +0200 @@ -124,31 +124,28 @@ uint8_t logy = 2; const uint8_t logx = boardx + 28; move(logy, logx); - + + /* count full moves */ 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) { - bool iswhite = (logelem->move.piece & COLOR_MASK) == WHITE; + for (unsigned mi = logi*2 ; mi < gamestate->movecount ; mi++) { + bool iswhite = mi % 2 == 0; if (iswhite) { logi++; printw("%d. ", logi); } - addstr(logelem->move.string); + addstr(gamestate->moves[mi].string); if (!iswhite && logi%3 == 0) { move(++logy, logx); } else { addch(' '); } - - logelem = logelem->next; } } @@ -518,7 +515,7 @@ addstr("Game has ended. Use -S to analyze it.\n"); return; } - curcol = opponent_color(gamestate.lastmove->move.piece&COLOR_MASK); + curcol = opponent_color(last_move(&gamestate).piece&COLOR_MASK); } else { printw("Can't read PGN file (%s)\n", strerror(errno)); return; @@ -546,8 +543,8 @@ mycolor = opponent_color(mycolor); } - bool myturn = (gamestate->lastmove ? - (gamestate->lastmove->move.piece & COLOR_MASK) : BLACK) != mycolor; + bool myturn = (gamestate->movecount > 0 ? + (last_move(gamestate).piece & COLOR_MASK) : BLACK) != mycolor; bool running; do { @@ -586,19 +583,18 @@ } void dump_moveinfo(GameState *gamestate) { - int i = 1; - for (MoveList *movelist = gamestate->movelist ; - movelist ; movelist = movelist->next) { - if (++i % 2 == 0) { - printw("%d. %s", i/2, movelist->move.string); + for (unsigned i = 0 ; i < gamestate->movecount ; i++) { + if (i % 2 == 0) { + printw("%d. %s", 1+i/2, gamestate->moves[i].string); } else { - printw(" %s", movelist->move.string); + printw("%s", gamestate->moves[i].string); } - if (i % 20) { + // only five moves reliably fit into one screen row + if ((i+1) % 10) { addch(' '); } else { addch('\n'); } - } + } refresh(); }