Wed, 29 Aug 2018 13:55:18 +0200
fixes castling not printed correctly to PGN
src/chess/king.c | file | annotate | diff | comparison | revisions | |
src/chess/pgn.c | file | annotate | diff | comparison | revisions | |
src/chess/rules.c | file | annotate | diff | comparison | revisions | |
src/client.c | file | annotate | diff | comparison | revisions | |
src/server.c | file | annotate | diff | comparison | revisions |
1.1 --- a/src/chess/king.c Wed Aug 29 13:45:13 2018 +0200 1.2 +++ b/src/chess/king.c Wed Aug 29 13:55:18 2018 +0200 1.3 @@ -70,10 +70,10 @@ 1.4 1.5 uint8_t opponent_color = opponent_color(move->piece&COLOR_MASK); 1.6 1.7 - // being in check does not "block" the king, so don't test it here 1.8 + /* being in check does not "block" the king, so don't test it here */ 1.9 _Bool blocked = 0; 1.10 1.11 - // just test, if castling move is blocked 1.12 + /* just test, if castling move is blocked */ 1.13 if (abs(move->tofile - move->fromfile) == 2) { 1.14 if (move->tofile == fileidx('c')) { 1.15 blocked |= gamestate->board[move->torow][fileidx('b')];
2.1 --- a/src/chess/pgn.c Wed Aug 29 13:45:13 2018 +0200 2.2 +++ b/src/chess/pgn.c Wed Aug 29 13:55:18 2018 +0200 2.3 @@ -61,7 +61,7 @@ 2.4 char tagkey[32]; 2.5 char tagvalue[128]; 2.6 2.7 - // read tag pairs 2.8 + /* read tag pairs */ 2.9 _Bool readmoves = 0; 2.10 while (!readmoves) { 2.11 while (isspace(c = fgetc(stream))); 2.12 @@ -99,7 +99,7 @@ 2.13 } 2.14 } 2.15 2.16 - // read moves 2.17 + /* read moves */ 2.18 if (fgetc(stream) != '.') { 2.19 return pgn_error_missing_dot; 2.20 } 2.21 @@ -109,7 +109,7 @@ 2.22 uint8_t curcol = WHITE; 2.23 2.24 while (readmoves) { 2.25 - // move 2.26 + /* move */ 2.27 while (isspace(c = fgetc(stream))); 2.28 i = 0; 2.29 do { 2.30 @@ -131,7 +131,7 @@ 2.31 // TODO: parse comments 2.32 while (isspace(c = fgetc(stream))); 2.33 2.34 - // end of game data encountered 2.35 + /* end of game data encountered */ 2.36 if (c == EOF) { 2.37 break; 2.38 } 2.39 @@ -144,15 +144,15 @@ 2.40 gamestate->remis = !gamestate->stalemate; 2.41 break; 2.42 } else { 2.43 - // oops, it was a move number, go back! 2.44 + /* oops, it was a move number, go back! */ 2.45 fseek(stream, -1, SEEK_CUR); 2.46 } 2.47 } 2.48 2.49 - // we have eaten the next valuable byte, so go back 2.50 + /* we have eaten the next valuable byte, so go back */ 2.51 fseek(stream, -1, SEEK_CUR); 2.52 2.53 - // skip move number after black move 2.54 + /* skip move number after black move */ 2.55 if (curcol == BLACK) { 2.56 while (isdigit(c = fgetc(stream))); 2.57 if (c != '.') { 2.58 @@ -169,7 +169,7 @@ 2.59 // TODO: tag pairs 2.60 size_t bytes = 0; 2.61 2.62 - // Result 2.63 + /* Result */ 2.64 char *result; 2.65 if (gamestate->stalemate || gamestate->remis) { 2.66 result = "1/2-1/2"; 2.67 @@ -185,7 +185,7 @@ 2.68 } 2.69 fprintf(stream, "[Result \"%s\"]\n\n", result); 2.70 2.71 - // moves 2.72 + /* moves */ 2.73 int i = 1; 2.74 for (MoveList *movelist = gamestate->movelist ; 2.75 movelist ; movelist = movelist->next) { 2.76 @@ -198,7 +198,7 @@ 2.77 2.78 // TODO: move time and maybe other comments 2.79 2.80 - // line break every 10 moves 2.81 + /* line break every 10 moves */ 2.82 if (i % 20) { 2.83 fputc(' ', stream); 2.84 } else {
3.1 --- a/src/chess/rules.c Wed Aug 29 13:45:13 2018 +0200 3.2 +++ b/src/chess/rules.c Wed Aug 29 13:55:18 2018 +0200 3.3 @@ -77,65 +77,69 @@ 3.4 /* at least 8 characters should be available, wipe them out */ 3.5 memset(string, 0, 8); 3.6 3.7 - /* special formats for castling */ 3.8 + unsigned int idx; 3.9 if ((move->piece&PIECE_MASK) == KING && 3.10 abs(move->tofile-move->fromfile) == 2) { 3.11 + /* special formats for castling */ 3.12 if (move->tofile==fileidx('c')) { 3.13 memcpy(string, "O-O-O", 5); 3.14 + idx = 5; 3.15 } else { 3.16 memcpy(string, "O-O", 3); 3.17 + idx = 3; 3.18 } 3.19 - } 3.20 + } else { 3.21 + /* start by notating the piece character */ 3.22 + string[0] = getpiecechr(move->piece); 3.23 + idx = string[0] ? 1 : 0; 3.24 3.25 - /* start by notating the piece character */ 3.26 - string[0] = getpiecechr(move->piece); 3.27 - int idx = string[0] ? 1 : 0; 3.28 - 3.29 - /* find out how many source information we do need */ 3.30 - uint8_t piece = move->piece & PIECE_MASK; 3.31 - if (piece == PAWN) { 3.32 - if (move->capture) { 3.33 - string[idx++] = filechr(move->fromfile); 3.34 - } 3.35 - } else if (piece != KING) { 3.36 - Move threats[16]; 3.37 - uint8_t threatcount; 3.38 - get_real_threats(gamestate, move->torow, move->tofile, 3.39 - move->piece&COLOR_MASK, threats, &threatcount); 3.40 - if (threatcount > 1) { 3.41 - int ambrows = 0, ambfiles = 0; 3.42 - for (uint8_t i = 0 ; i < threatcount ; i++) { 3.43 - if (threats[i].fromrow == move->fromrow) { 3.44 - ambrows++; 3.45 + /* find out how many source information we do need */ 3.46 + uint8_t piece = move->piece & PIECE_MASK; 3.47 + if (piece == PAWN) { 3.48 + if (move->capture) { 3.49 + string[idx++] = filechr(move->fromfile); 3.50 + } 3.51 + } else if (piece != KING) { 3.52 + /* resolve ambiguities, if any */ 3.53 + Move threats[16]; 3.54 + uint8_t threatcount; 3.55 + get_real_threats(gamestate, move->torow, move->tofile, 3.56 + move->piece&COLOR_MASK, threats, &threatcount); 3.57 + if (threatcount > 1) { 3.58 + int ambrows = 0, ambfiles = 0; 3.59 + for (uint8_t i = 0 ; i < threatcount ; i++) { 3.60 + if (threats[i].fromrow == move->fromrow) { 3.61 + ambrows++; 3.62 + } 3.63 + if (threats[i].fromfile == move->fromfile) { 3.64 + ambfiles++; 3.65 + } 3.66 } 3.67 - if (threats[i].fromfile == move->fromfile) { 3.68 - ambfiles++; 3.69 + /* ambiguous row, name file */ 3.70 + if (ambrows > 1) { 3.71 + string[idx++] = filechr(move->fromfile); 3.72 + } 3.73 + /* ambiguous file, name row */ 3.74 + if (ambfiles > 1) { 3.75 + string[idx++] = filechr(move->fromrow); 3.76 } 3.77 } 3.78 - /* ambiguous row, name file */ 3.79 - if (ambrows > 1) { 3.80 - string[idx++] = filechr(move->fromfile); 3.81 - } 3.82 - /* ambiguous file, name row */ 3.83 - if (ambfiles > 1) { 3.84 - string[idx++] = filechr(move->fromrow); 3.85 - } 3.86 } 3.87 - } 3.88 - 3.89 - /* capturing? */ 3.90 - if (move->capture) { 3.91 - string[idx++] = 'x'; 3.92 - } 3.93 - 3.94 - /* destination */ 3.95 - string[idx++] = filechr(move->tofile); 3.96 - string[idx++] = rowchr(move->torow); 3.97 - 3.98 - /* promotion? */ 3.99 - if (move->promotion) { 3.100 - string[idx++] = '='; 3.101 - string[idx++] = getpiecechr(move->promotion); 3.102 + 3.103 + /* capturing? */ 3.104 + if (move->capture) { 3.105 + string[idx++] = 'x'; 3.106 + } 3.107 + 3.108 + /* destination */ 3.109 + string[idx++] = filechr(move->tofile); 3.110 + string[idx++] = rowchr(move->torow); 3.111 + 3.112 + /* promotion? */ 3.113 + if (move->promotion) { 3.114 + string[idx++] = '='; 3.115 + string[idx++] = getpiecechr(move->promotion); 3.116 + } 3.117 } 3.118 3.119 /* check? */ 3.120 @@ -456,7 +460,7 @@ 3.121 for (uint8_t r = 0 ; r < 8 ; r++) { 3.122 for (uint8_t f = 0 ; f < 8 ; f++) { 3.123 if ((gamestate->board[r][f] & COLOR_MASK) == color) { 3.124 - // non-capturing move 3.125 + /* non-capturing move */ 3.126 memset(&(candidates[candidatecount]), 0, sizeof(Move)); 3.127 candidates[candidatecount].piece = gamestate->board[r][f]; 3.128 candidates[candidatecount].fromrow = r; 3.129 @@ -465,7 +469,7 @@ 3.130 candidates[candidatecount].tofile = file; 3.131 candidatecount++; 3.132 3.133 - // capturing move 3.134 + /* capturing move */ 3.135 memcpy(&(candidates[candidatecount]), 3.136 &(candidates[candidatecount-1]), sizeof(Move)); 3.137 candidates[candidatecount].capture = 1; 3.138 @@ -572,7 +576,7 @@ 3.139 3.140 int reason = INVALID_POSITION; 3.141 3.142 - // find threats for the specified position 3.143 + /* find threats for the specified position */ 3.144 for (uint8_t i = 0 ; i < threatcount ; i++) { 3.145 if ((threats[i].piece & (PIECE_MASK | COLOR_MASK)) 3.146 == move->piece && 3.147 @@ -584,7 +588,7 @@ 3.148 if (threat) { 3.149 return AMBIGUOUS_MOVE; 3.150 } else { 3.151 - // found threat is no real threat 3.152 + /* found threat is no real threat */ 3.153 if (is_pinned(gamestate, &(threats[i]))) { 3.154 reason = incheck?KING_IN_CHECK:PIECE_PINNED; 3.155 } else { 3.156 @@ -594,7 +598,7 @@ 3.157 } 3.158 } 3.159 3.160 - // can't threaten specified position 3.161 + /* can't threaten specified position */ 3.162 if (!threat) { 3.163 return reason; 3.164 }
4.1 --- a/src/client.c Wed Aug 29 13:45:13 2018 +0200 4.2 +++ b/src/client.c Wed Aug 29 13:55:18 2018 +0200 4.3 @@ -75,7 +75,7 @@ 4.4 4.5 uint8_t code = net_recieve_code(server.fd); 4.6 if (code == NETCODE_GAMEINFO) { 4.7 - // Start new game 4.8 + /* Start new game */ 4.9 net_recieve_data(server.fd, &(settings->gameinfo), sizeof(GameInfo)); 4.10 dump_gameinfo(&(settings->gameinfo)); 4.11 if (prompt_yesno("Accept challenge")) {
5.1 --- a/src/server.c Wed Aug 29 13:45:13 2018 +0200 5.2 +++ b/src/server.c Wed Aug 29 13:55:18 2018 +0200 5.3 @@ -69,7 +69,7 @@ 5.4 GameState continuegame; 5.5 gamestate_init(&continuegame); 5.6 if (settings->continuepgn) { 5.7 - // preload PGN data before handshake 5.8 + /* preload PGN data before handshake */ 5.9 FILE *pgnfile = fopen(settings->continuepgn, "r"); 5.10 if (pgnfile) { 5.11 int result = read_pgn(pgnfile, &continuegame, 5.12 @@ -106,7 +106,7 @@ 5.13 5.14 int fd = server.client->fd; 5.15 if (settings->continuepgn) { 5.16 - // Continue game, send PGN data 5.17 + /* Continue game, send PGN data */ 5.18 uint16_t mc = 0; 5.19 MoveList *movelist = continuegame.movelist; 5.20 while (movelist) { 5.21 @@ -133,7 +133,7 @@ 5.22 net_send_data(fd, NETCODE_PGNDATA, pgndata, pgndata_size); 5.23 free(pgndata); 5.24 } else { 5.25 - // Start new game 5.26 + /* Start new game */ 5.27 net_send_data(fd, NETCODE_GAMEINFO, 5.28 &(settings->gameinfo), sizeof(GameInfo)); 5.29 }