diff options
| author | John Wiegley <johnw@newartisans.com> | 2002-04-09 04:26:02 +0000 |
|---|---|---|
| committer | John Wiegley <johnw@newartisans.com> | 2002-04-09 04:26:02 +0000 |
| commit | 6b8ac5acf330b03e88d0b342c79abbb7d338e0c2 (patch) | |
| tree | 9df6dc3602f81a1acd5f2d6d234b6e4f6a45d57f /chess-game.el | |
| parent | 18f22844af74b15732d7fc7dfad318a1ba0c0d99 (diff) | |
Bug fixes and the beginnings of ICS client support
Diffstat (limited to 'chess-game.el')
| -rw-r--r-- | chess-game.el | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/chess-game.el b/chess-game.el index d1eb706..a33971f 100644 --- a/chess-game.el +++ b/chess-game.el @@ -148,32 +148,37 @@ progress (nil), if it is drawn, resigned, mate, etc." (let ((current-ply (chess-game-ply game)) (changes (chess-ply-changes ply)) (position (chess-ply-pos ply))) + (if (chess-ply-final-p current-ply) + (error "Cannot add moves to a completed game")) (unless (equal position (chess-ply-pos current-ply)) (error "Positions do not match")) - (unless (chess-search-position - position (cadr (chess-ply-changes ply)) - (chess-pos-piece position (car (chess-ply-changes ply)))) + (unless (or (chess-ply-has-keyword ply :resign) + (chess-search-position + position (cadr (chess-ply-changes ply)) + (chess-pos-piece position (car (chess-ply-changes ply))))) (signal 'chess-illegal "Illegal move")) (chess-ply-set-changes current-ply changes) (chess-game-add-ply game (chess-ply-create (chess-ply-next-pos current-ply))) (cond - ((or (memq :draw changes) - (memq :perpetual changes) - (memq :repetition changes) - (memq :stalemate changes)) + ((chess-ply-has-keyword ply :draw :perpetual :repetition :stalemate) (chess-game-set-tag game "Result" "1/2-1/2") - (chess-game-run-hooks game 'game-over)) + (chess-game-run-hooks game 'game-drawn)) - ((or (memq :resign changes) - (memq :checkmate changes)) - (chess-game-set-tag game "Result" (if (chess-game-side-to-move game) - "0-1" "1-0")) - (chess-game-run-hooks game 'game-over)) + ((chess-ply-has-keyword ply :resign :checkmate) + (let ((color (chess-game-side-to-move game))) + (chess-game-set-tag game "Result" (if color "0-1" "1-0")) + (if (chess-ply-has-keyword ply :resign) + (chess-game-run-hooks game 'resign color) + (chess-game-run-hooks game 'game-over)))) (t (chess-game-run-hooks game 'move current-ply))))) +(defsubst chess-game-resign (game) + "Resign the current game." + (chess-game-move game (list (chess-game-pos game) :resign))) + (provide 'chess-game) ;;; chess-game.el ends here |
