move log has now three columns and starts scrolling after 45 moves

Wed, 29 Aug 2018 13:45:13 +0200

author
Mike Becker <universe@uap-core.de>
date
Wed, 29 Aug 2018 13:45:13 +0200
changeset 63
611332453da0
parent 62
564af8a16828
child 64
4eda5df55f86

move log has now three columns and starts scrolling after 45 moves

src/chess/rules.c file | annotate | diff | comparison | revisions
src/chess/rules.h file | annotate | diff | comparison | revisions
src/game.c file | annotate | diff | comparison | revisions
     1.1 --- a/src/chess/rules.c	Tue Aug 28 15:56:33 2018 +0200
     1.2 +++ b/src/chess/rules.c	Wed Aug 29 13:45:13 2018 +0200
     1.3 @@ -171,10 +171,12 @@
     1.4          
     1.5          gamestate->lastmove->next = elem;
     1.6          gamestate->lastmove = elem;
     1.7 +        gamestate->movecount++;
     1.8      } else {
     1.9          elem->move.movetime.tv_usec = 0;
    1.10          elem->move.movetime.tv_sec = 0;
    1.11          gamestate->movelist = gamestate->lastmove = elem;
    1.12 +        gamestate->movecount = 1;
    1.13      }
    1.14  }
    1.15  
     2.1 --- a/src/chess/rules.h	Tue Aug 28 15:56:33 2018 +0200
     2.2 +++ b/src/chess/rules.h	Wed Aug 29 13:45:13 2018 +0200
     2.3 @@ -112,6 +112,7 @@
     2.4      Board board;
     2.5      MoveList* movelist;
     2.6      MoveList* lastmove;
     2.7 +    unsigned int movecount; /* number of (half-)moves (counting BOTH colors) */
     2.8      _Bool checkmate;
     2.9      _Bool stalemate;
    2.10      _Bool remis;
     3.1 --- a/src/game.c	Tue Aug 28 15:56:33 2018 +0200
     3.2 +++ b/src/game.c	Wed Aug 29 13:45:13 2018 +0200
     3.3 @@ -38,7 +38,7 @@
     3.4  #include <stdio.h>
     3.5  #include <errno.h>
     3.6  
     3.7 -static const uint8_t boardx = 10, boardy = 10;
     3.8 +static const uint8_t boardx = 4, boardy = 10;
     3.9  static int inputy = 21; /* should be overridden on game startup */
    3.10  
    3.11  static int timecontrol(GameState *gamestate, GameInfo *gameinfo) {
    3.12 @@ -112,29 +112,32 @@
    3.13      }
    3.14      
    3.15      /* move log */
    3.16 -    // TODO: introduce window to avoid bugs with a long move log
    3.17 -    uint8_t logy = 1;
    3.18 -    const uint8_t logx = boardx + 30;
    3.19 -    int logi = 1;
    3.20 +    uint8_t logy = 2;
    3.21 +    const uint8_t logx = boardx + 28;
    3.22 +    move(logy, logx);
    3.23 +    
    3.24 +    unsigned int logi = 0;
    3.25      MoveList *logelem = gamestate->movelist;
    3.26      
    3.27 +    /* wrap log after 45 moves */
    3.28 +    while (gamestate->movecount/6-logi/3 >= 15) {
    3.29 +        logelem = logelem->next->next;
    3.30 +        logi++;
    3.31 +    }
    3.32 +    
    3.33      while (logelem) {
    3.34 -        logi++;
    3.35 -        if (logi % 2 == 0) {
    3.36 -            if ((logi - 2) % 4 == 0) {
    3.37 -                logy++;
    3.38 -                move(logy, logx);
    3.39 -            }
    3.40 -            printw("%d. ", logi / 2);
    3.41 +        _Bool iswhite = (logelem->move.piece & COLOR_MASK) == WHITE;
    3.42 +        if (iswhite) {
    3.43 +            logi++;
    3.44 +            printw("%d. ", logi);
    3.45          }
    3.46  
    3.47          addstr(logelem->move.string);
    3.48 -        if (!logelem->next) {
    3.49 -            if (gamestate->stalemate) {
    3.50 -                addstr(" stalemate");
    3.51 -            }
    3.52 +        if (!iswhite && logi%3 == 0) {
    3.53 +            move(++logy, logx);
    3.54 +        } else {
    3.55 +            addch(' ');
    3.56          }
    3.57 -        addch(' ');
    3.58  
    3.59          logelem = logelem->next;
    3.60      }

mercurial