| 90 |
90 |
| 91 /* copy the most recent move and position if a move was played */ |
91 /* copy the most recent move and position if a move was played */ |
| 92 if (gamestate->movecount > 0) { |
92 if (gamestate->movecount > 0) { |
| 93 simulation.fen_start = strdup(gamestate->movecount == 1 ? |
93 simulation.fen_start = strdup(gamestate->movecount == 1 ? |
| 94 gamestate->fen_start : gamestate->fen[gamestate->movecount - 2]); |
94 gamestate->fen_start : gamestate->fen[gamestate->movecount - 2]); |
| 95 simulation.moves[0] = last_move(gamestate); |
95 simulation.moves[0] = gamestate->moves[gamestate->movecount - 1]; |
| 96 simulation.fen[0] = strdup(gamestate->fen[gamestate->movecount - 1]); |
96 simulation.fen[0] = strdup(gamestate->fen[gamestate->movecount - 1]); |
| 97 simulation.movecount++; |
97 simulation.movecount++; |
| 98 } else { |
98 } else { |
| 99 simulation.fen_start = strdup(gamestate->fen_start); |
99 simulation.fen_start = strdup(gamestate->fen_start); |
| 100 } |
100 } |
| 198 move->timestamp.tv_sec = curtimestamp.tv_sec; |
198 move->timestamp.tv_sec = curtimestamp.tv_sec; |
| 199 move->timestamp.tv_usec = (int32_t) curtimestamp.tv_usec; |
199 move->timestamp.tv_usec = (int32_t) curtimestamp.tv_usec; |
| 200 move->movetime.tv_usec = 0; |
200 move->movetime.tv_usec = 0; |
| 201 move->movetime.tv_sec = 0; |
201 move->movetime.tv_sec = 0; |
| 202 if (gamestate->movecount > 1) { |
202 if (gamestate->movecount > 1) { |
| 203 struct movetimeval lasttstamp = last_move(gamestate).timestamp; |
203 struct movetimeval lasttstamp = |
| |
204 gamestate->moves[gamestate->movecount - 1].timestamp; |
| 204 uint64_t sec = curtimestamp.tv_sec - lasttstamp.tv_sec; |
205 uint64_t sec = curtimestamp.tv_sec - lasttstamp.tv_sec; |
| 205 suseconds_t micros; |
206 suseconds_t micros; |
| 206 if (curtimestamp.tv_usec < lasttstamp.tv_usec) { |
207 if (curtimestamp.tv_usec < lasttstamp.tv_usec) { |
| 207 micros = 1000000-(lasttstamp.tv_usec - curtimestamp.tv_usec); |
208 micros = 1000000-(lasttstamp.tv_usec - curtimestamp.tv_usec); |
| 208 sec--; |
209 sec--; |
| 467 if (is_covered(&simulation, mykingrow, mykingfile, oppcolor)) { |
468 if (is_covered(&simulation, mykingrow, mykingfile, oppcolor)) { |
| 468 gamestate_cleanup(&simulation); |
469 gamestate_cleanup(&simulation); |
| 469 if (piece_type(move->piece) == KING) { |
470 if (piece_type(move->piece) == KING) { |
| 470 return KING_MOVES_INTO_CHECK; |
471 return KING_MOVES_INTO_CHECK; |
| 471 } else { |
472 } else { |
| 472 /* last move is always not null in this case */ |
473 if (gamestate->moves[gamestate->movecount - 1].check) { |
| 473 return last_move(gamestate).check ? |
474 return KING_IN_CHECK; |
| 474 KING_IN_CHECK : PIECE_PINNED; |
475 } else { |
| |
476 return PIECE_PINNED; |
| |
477 } |
| 475 } |
478 } |
| 476 } |
479 } |
| 477 |
480 |
| 478 /* correct check and checkmate flags (move is still valid) */ |
481 /* correct check and checkmate flags (move is still valid) */ |
| 479 Move threats[16]; |
482 Move threats[16]; |
| 708 } |
711 } |
| 709 |
712 |
| 710 static int getlocation(GameState *gamestate, Move *move) { |
713 static int getlocation(GameState *gamestate, Move *move) { |
| 711 |
714 |
| 712 Color color = piece_color(move->piece); |
715 Color color = piece_color(move->piece); |
| 713 bool incheck = gamestate->movecount > 0 ? last_move(gamestate).check:false; |
716 bool incheck = false; |
| |
717 if (gamestate->movecount > 0) { |
| |
718 incheck = gamestate->moves[gamestate->movecount - 1].check; |
| |
719 } |
| 714 |
720 |
| 715 Move threats[16], *threat = NULL; |
721 Move threats[16], *threat = NULL; |
| 716 size_t threatcount; |
722 size_t threatcount; |
| 717 |
723 |
| 718 /* determine all threats and sort out the unreal threats on our own */ |
724 /* determine all threats and sort out the unreal threats on our own */ |