Rev 171 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 171 | Rev 185 | ||
---|---|---|---|
Line 138... | Line 138... | ||
138 | int char_index; |
138 | int char_index; |
139 | int fieldstart; |
139 | int fieldstart; |
140 | int fieldstop; |
140 | int fieldstop; |
141 | int program_index; |
141 | int program_index; |
142 | int variation_depth; |
142 | int variation_depth; |
- | 143 | int new_gamestate; |
|
143 | char movenumber_string[8]; |
144 | char movenumber_string[8]; |
144 | 145 | ||
145 | // did we chose NO game ? |
146 | // did we chose NO game ? |
146 | if (game == NULL) |
147 | if (game == NULL) |
147 | { |
148 | { |
Line 177... | Line 178... | ||
177 | new_move.source[1] = -1; |
178 | new_move.source[1] = -1; |
178 | new_move.target[0] = -1; |
179 | new_move.target[0] = -1; |
179 | new_move.target[1] = -1; |
180 | new_move.target[1] = -1; |
180 | new_move.promotion_type = 0; |
181 | new_move.promotion_type = 0; |
181 | pgn_comment[0] = 0; |
182 | pgn_comment[0] = 0; |
- | 183 | new_gamestate = STATE_PLAYING; // assume this is an unfinished game until told otherwise |
|
182 | for (;;) |
184 | for (;;) |
183 | { |
185 | { |
184 | // build the move number string |
186 | // build the move number string |
185 | sprintf_s (movenumber_string, sizeof (movenumber_string), "%d.", 1 + board->move_count / 2); |
187 | sprintf_s (movenumber_string, sizeof (movenumber_string), "%d.", 1 + board->move_count / 2); |
186 | 188 | ||
Line 297... | Line 299... | ||
297 | pgn_comment[0] = 0; // reset comment |
299 | pgn_comment[0] = 0; // reset comment |
298 | } |
300 | } |
299 | 301 | ||
300 | // has the game been closed ? |
302 | // has the game been closed ? |
301 | if (strncmp (&pgnfile_data[char_index], "1/2-1/2", 7) == 0) |
303 | if (strncmp (&pgnfile_data[char_index], "1/2-1/2", 7) == 0) |
302 |
|
304 | new_gamestate = STATE_DRAW_OTHER; // game closed on a draw (FIXME: identify variants) |
303 | else if (strncmp (&pgnfile_data[char_index], "1-0", 7) == 0) |
305 | else if (strncmp (&pgnfile_data[char_index], "1-0", 7) == 0) |
304 | { |
306 | { |
305 | // see if it's a checkmate |
307 | // see if it's a checkmate |
306 | if (board->moves[board->move_count - 1].is_check && board->moves[board->move_count - 1].is_stalemate) |
308 | if (board->moves[board->move_count - 1].is_check && board->moves[board->move_count - 1].is_stalemate) |
307 |
|
309 | new_gamestate = STATE_WHITEWIN_CHECKMATE; // game was won by white on a checkmate (checkmate = check + stalemate) |
308 | else |
310 | else |
309 |
|
311 | new_gamestate = STATE_WHITEWIN_RESIGNORFORFEIT; // game was won by white for another reason |
310 | } |
312 | } |
311 | else if (strncmp (&pgnfile_data[char_index], "0-1", 7) == 0) |
313 | else if (strncmp (&pgnfile_data[char_index], "0-1", 7) == 0) |
312 | { |
314 | { |
313 | // see if it's a checkmate |
315 | // see if it's a checkmate |
314 | if (board->moves[board->move_count - 1].is_check && board->moves[board->move_count - 1].is_stalemate) |
316 | if (board->moves[board->move_count - 1].is_check && board->moves[board->move_count - 1].is_stalemate) |
315 |
|
317 | new_gamestate = STATE_BLACKWIN_CHECKMATE; // game was won by black on a checkmate (checkmate = check + stalemate) |
316 | else |
318 | else |
317 |
|
319 | new_gamestate = STATE_BLACKWIN_RESIGNORFORFEIT; // game was won by black for another reason |
318 | } |
320 | } |
319 | 321 | ||
320 | board->players[1 - board->moves[board->move_count - 1].color].should_wakeup = true; // wake the player whose turn it is |
322 | board->players[1 - board->moves[board->move_count - 1].color].should_wakeup = true; // wake the player whose turn it is |
321 | break; // we've finished reading the game |
323 | break; // we've finished reading the game |
322 | } |
324 | } |
Line 365... | Line 367... | ||
365 | PGNFile_GameList_Shutdown (); |
367 | PGNFile_GameList_Shutdown (); |
366 | 368 | ||
367 | // we no longer need the file data space, so free it |
369 | // we no longer need the file data space, so free it |
368 | SAFE_free ((void **) &pgnfile_data); |
370 | SAFE_free ((void **) &pgnfile_data); |
369 | 371 | ||
- | 372 | board->game_state = new_gamestate; // save the new game state |
|
370 | return (true); // game loaded successfully, return TRUE |
373 | return (true); // game loaded successfully, return TRUE |
371 | } |
374 | } |
372 | 375 | ||
373 | 376 | ||
374 | bool PGNFile_Save (board_t *board, const wchar_t *pgnfile_pathname) |
377 | bool PGNFile_Save (board_t *board, const wchar_t *pgnfile_pathname) |