src/game.c

changeset 98
9cb41383540f
parent 94
864f59271974
equal deleted inserted replaced
97:f87cad9445b4 98:9cb41383540f
122 122
123 /* move log */ 123 /* move log */
124 uint8_t logy = 2; 124 uint8_t logy = 2;
125 const uint8_t logx = boardx + 28; 125 const uint8_t logx = boardx + 28;
126 move(logy, logx); 126 move(logy, logx);
127 127
128 /* count full moves */
128 unsigned int logi = 0; 129 unsigned int logi = 0;
129 MoveList *logelem = gamestate->movelist; 130
130
131 /* wrap log after 45 moves */ 131 /* wrap log after 45 moves */
132 while (gamestate->movecount/6-logi/3 >= 15) { 132 while (gamestate->movecount/6-logi/3 >= 15) {
133 logelem = logelem->next->next;
134 logi++; 133 logi++;
135 } 134 }
136 135
137 while (logelem) { 136 for (unsigned mi = logi*2 ; mi < gamestate->movecount ; mi++) {
138 bool iswhite = (logelem->move.piece & COLOR_MASK) == WHITE; 137 bool iswhite = mi % 2 == 0;
139 if (iswhite) { 138 if (iswhite) {
140 logi++; 139 logi++;
141 printw("%d. ", logi); 140 printw("%d. ", logi);
142 } 141 }
143 142
144 addstr(logelem->move.string); 143 addstr(gamestate->moves[mi].string);
145 if (!iswhite && logi%3 == 0) { 144 if (!iswhite && logi%3 == 0) {
146 move(++logy, logx); 145 move(++logy, logx);
147 } else { 146 } else {
148 addch(' '); 147 addch(' ');
149 } 148 }
150
151 logelem = logelem->next;
152 } 149 }
153 } 150 }
154 151
155 static void eval_move_failed_msg(int code) { 152 static void eval_move_failed_msg(int code) {
156 switch (code) { 153 switch (code) {
516 } 513 }
517 if (!is_game_running(&gamestate)) { 514 if (!is_game_running(&gamestate)) {
518 addstr("Game has ended. Use -S to analyze it.\n"); 515 addstr("Game has ended. Use -S to analyze it.\n");
519 return; 516 return;
520 } 517 }
521 curcol = opponent_color(gamestate.lastmove->move.piece&COLOR_MASK); 518 curcol = opponent_color(last_move(&gamestate).piece&COLOR_MASK);
522 } else { 519 } else {
523 printw("Can't read PGN file (%s)\n", strerror(errno)); 520 printw("Can't read PGN file (%s)\n", strerror(errno));
524 return; 521 return;
525 } 522 }
526 } 523 }
544 uint8_t mycolor = settings->gameinfo.servercolor; 541 uint8_t mycolor = settings->gameinfo.servercolor;
545 if (!settings->ishost) { 542 if (!settings->ishost) {
546 mycolor = opponent_color(mycolor); 543 mycolor = opponent_color(mycolor);
547 } 544 }
548 545
549 bool myturn = (gamestate->lastmove ? 546 bool myturn = (gamestate->movecount > 0 ?
550 (gamestate->lastmove->move.piece & COLOR_MASK) : BLACK) != mycolor; 547 (last_move(gamestate).piece & COLOR_MASK) : BLACK) != mycolor;
551 548
552 bool running; 549 bool running;
553 do { 550 do {
554 clear(); 551 clear();
555 draw_board(gamestate, mycolor, settings->unicode); 552 draw_board(gamestate, mycolor, settings->unicode);
584 } 581 }
585 refresh(); 582 refresh();
586 } 583 }
587 584
588 void dump_moveinfo(GameState *gamestate) { 585 void dump_moveinfo(GameState *gamestate) {
589 int i = 1; 586 for (unsigned i = 0 ; i < gamestate->movecount ; i++) {
590 for (MoveList *movelist = gamestate->movelist ; 587 if (i % 2 == 0) {
591 movelist ; movelist = movelist->next) { 588 printw("%d. %s", 1+i/2, gamestate->moves[i].string);
592 if (++i % 2 == 0) { 589 } else {
593 printw("%d. %s", i/2, movelist->move.string); 590 printw("%s", gamestate->moves[i].string);
594 } else { 591 }
595 printw(" %s", movelist->move.string); 592 // only five moves reliably fit into one screen row
596 } 593 if ((i+1) % 10) {
597 if (i % 20) {
598 addch(' '); 594 addch(' ');
599 } else { 595 } else {
600 addch('\n'); 596 addch('\n');
601 } 597 }
602 } 598 }
603 refresh(); 599 refresh();
604 } 600 }

mercurial