diff options
| -rw-r--r-- | TODO | 61 | ||||
| -rw-r--r-- | chess-display.el | 4 | ||||
| -rw-r--r-- | chess-game.el | 14 | ||||
| -rw-r--r-- | chess-pgn.el | 22 | ||||
| -rw-r--r-- | chess-ply.el | 10 |
5 files changed, 39 insertions, 72 deletions
@@ -1,45 +1,17 @@ -* 2.0 -** Breakdown - -*** Core library -*** Display modules -*** Chess engines - -** Finished writing `define-chess-module' - -** Call `chess-game-move' in chess-display to move the pieces - -** Keyboard shortcuts - -*** Right now "nf, nf", causes an error -*** Castling is not supported -*** Capital letters not supported - -** Long castling is signaled as an illegal move from chess-standard - -** Support pre-defined sessions, like `crafty' - -Or, allow the user to choose the rules modules with C-u M-x eshell, -and the core engine module all the time. So M-x eshell would prompt -for the engine module, defaulting to crafty. - -* Other +- Port image display code to XEmacs -- Clipboard copy and paste should be global, and occur in this module +- Allow the user to retract a move when playing against an engine. -- Port image display code to XEmacs +- Long castling is signaled as an illegal move from chess-standard -- Keep a history of boards, and the moves corresponding with them, so - that the move history can be stepped through forward and back. +- Capital letters not supported in keyboard shortcut entry -- Allow the user to retract a move when playing against crafty. +---------------------------------------------------------------------- - Tie-in to ics.el, by adding "Internet opponent" to the opponents list. -- The ability to read and playback existing PGN files. - - A way to set the time control, and display its status. - After a castle, the rook might place the opponent's king in check. @@ -55,27 +27,6 @@ for the engine module, defaulting to crafty. - Allow the opponent to give hints. -- Choose the default image set based on the screen size. - -- Find some prettier image sets. - -- If the chess computer croaks, handle it gracefully. - -- A better way to visually show who's turn it is now? - -- The source have some strings with non-ascii content. - -- In a PGN file, offer the commands: chess-continue, chess-replay, - chess-show-position (which works for whichever sequence the cursor - is in). - -- For modified boards, add a command key to say that it's really black - to play, not white (or vice versa). - -- Multiple game buffer selection is a bit screwy. M-1 M-x chess will - not select the first buffer, for example. Perhaps named games would - be better? - - Add a command that will load a saved game, continue it, and then enter a move for whichever color is next to play. This would make it trivial to add chess drivers to AIM, IRC, etc. The mere command @@ -83,8 +34,6 @@ for the engine module, defaulting to crafty. make my move as Nf3. It would also make chess by e-mail a snap to implement. -- Modify etalk's chess.el to use this chess.el as its library. - - Add an analyze command that will indicate which pieces are defended, how well, which are attacked, which moves would increase defense/attack/both, etc. Basically, everything that can be known diff --git a/chess-display.el b/chess-display.el index e8fc67d..7b83e67 100644 --- a/chess-display.el +++ b/chess-display.el @@ -404,7 +404,9 @@ The key bindings available in this mode are: (if ply (setq chess-display-mode-line (concat - " " (if color "White" "BLACK") + (if (chess-ply-final-p ply) + " FINISHED" + (concat " " (if color "White" "BLACK"))) (if index (concat " " (int-to-string (if (> index 1) diff --git a/chess-game.el b/chess-game.el index fd3c5fa..6abdc20 100644 --- a/chess-game.el +++ b/chess-game.el @@ -129,7 +129,7 @@ (defsubst chess-game-pos (game &optional index) "Return the position related to GAME's INDEX position." - (car (chess-game-ply game index))) + (chess-ply-pos (chess-game-ply game index))) (defun chess-game-create (&optional position search-func tags) @@ -166,19 +166,23 @@ progress (nil), if it is drawn, resigned, mate, etc." (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-game-set-tag game "Result" "1/2-1/2")) + (chess-game-set-tag game "Result" "1/2-1/2") + (chess-game-run-hooks game 'game-over)) + ((or (memq ':resign changes) (memq ':checkmate changes)) (chess-game-set-tag game "Result" (if (chess-game-side-to-move game) - "0-1" "1-0"))) + "0-1" "1-0")) + (chess-game-run-hooks game 'game-over)) + (t - (chess-game-add-ply game (chess-ply-create - (chess-ply-next-pos current-ply))) (chess-game-run-hooks game 'move current-ply))))) ;; A few convenience functions diff --git a/chess-pgn.el b/chess-pgn.el index 04a8575..db13793 100644 --- a/chess-pgn.el +++ b/chess-pgn.el @@ -79,18 +79,20 @@ "NYI: Still have to implement INDENTED argument." (while plies (unless for-black - (insert (format "%d. %s" index - (chess-game-ply-to-algebraic game (car plies)))) - (unless no-annotations - (chess-pgn-insert-annotations game index (car plies))) + (when (chess-ply-changes (car plies)) + (insert (format "%d. %s" index + (chess-game-ply-to-algebraic game (car plies)))) + (unless no-annotations + (chess-pgn-insert-annotations game index (car plies)))) (setq plies (cdr plies) index (1+ index))) (when plies - (when for-black - (insert (format "%d. ..." index)) - (setq for-black nil)) - (insert (format " %s" (chess-game-ply-to-algebraic game (car plies)))) - (unless no-annotations - (chess-pgn-insert-annotations game index (car plies))) + (when (chess-ply-changes (car plies)) + (when for-black + (insert (format "%d. ..." index)) + (setq for-black nil)) + (insert (format " %s" (chess-game-ply-to-algebraic game (car plies)))) + (unless no-annotations + (chess-pgn-insert-annotations game index (car plies)))) (setq plies (cdr plies))) (if plies (insert ? )))) diff --git a/chess-ply.el b/chess-ply.el index f5261b9..e4f3120 100644 --- a/chess-ply.el +++ b/chess-ply.el @@ -72,6 +72,16 @@ ;; annotate and extend the ply correctly (cons (chess-pos-copy position) changes)) +(defun chess-ply-final-p (ply) + "Return non-nil if this is the last ply of a game/variation." + (let ((changes (chess-ply-changes ply))) + (or (memq ':draw changes) + (memq ':perpetual changes) + (memq ':repetition changes) + (memq ':stalemate changes) + (memq ':resign changes) + (memq ':checkmate changes)))) + (defun chess-legal-plies (position &optional search-func) "Return a list of all legal plies in POSITION." (let (plies) |
