diff options
| author | John Wiegley <johnw@newartisans.com> | 2002-04-26 03:27:40 +0000 |
|---|---|---|
| committer | John Wiegley <johnw@newartisans.com> | 2002-04-26 03:27:40 +0000 |
| commit | 0e302a828c7e79491b5055cbeb0d8879cc3d8558 (patch) | |
| tree | 3b666f8db828ec78a449e2cad38a328c190a1985 | |
| parent | 738ff9a3b57b5e317e086a9ee4878fbb45f24b3e (diff) | |
fixes
| -rw-r--r-- | chess-clock.el | 19 | ||||
| -rw-r--r-- | chess-display.el | 16 | ||||
| -rw-r--r-- | chess-engine.el | 42 | ||||
| -rw-r--r-- | chess-game.el | 2 | ||||
| -rw-r--r-- | chess-ics.el | 16 |
5 files changed, 55 insertions, 40 deletions
diff --git a/chess-clock.el b/chess-clock.el index 74a791c..8913908 100644 --- a/chess-clock.el +++ b/chess-clock.el @@ -50,14 +50,15 @@ ((eq event 'move) (let ((white (chess-game-data game 'white-remaining)) (black (chess-game-data game 'black-remaining))) - (when (and white black (> (chess-game-index game) 0)) - (setq chess-clock-timer - (run-with-timer 0 1 'chess-clock-tick-tock (current-buffer))) + (when (and white black + (chess-game-data game 'active) + (> (chess-game-index game) 0)) + (unless chess-clock-timer + (setq chess-clock-timer + (run-with-timer 0 1 'chess-clock-tick-tock (current-buffer)))) (let ((last-ply (car (last (chess-game-plies game) 2)))) (chess-ply-set-keyword last-ply :white white) - (chess-ply-set-keyword last-ply :black black)))) - (if (chess-game-over-p game) - (chess-clock-handler game 'destroy))) + (chess-ply-set-keyword last-ply :black black))))) ((eq event 'set-data) (if (and (eq (car args) 'active) @@ -67,7 +68,7 @@ ((memq event '(destroy resign drawn)) (when chess-clock-timer (cancel-timer chess-clock-timer) - (setq chess-clock-timer))))) + (setq chess-clock-timer nil))))) (defvar chess-clock-tick-tocking nil) @@ -75,7 +76,9 @@ (unless chess-clock-tick-tocking (let ((chess-clock-tick-tocking t)) (with-current-buffer module - (let ((last-time chess-clock-last-time) counter) + (let ((last-time chess-clock-last-time) + (chess-game-inhibit-events t) + counter) (setq chess-clock-last-time (current-time)) (when (> (chess-game-index chess-module-game) 0) (if (chess-pos-side-to-move (chess-game-pos chess-module-game)) diff --git a/chess-display.el b/chess-display.el index 8c95d15..5e63f1e 100644 --- a/chess-display.el +++ b/chess-display.el @@ -175,8 +175,7 @@ also view the same game." (defun chess-display-clock-string () (let ((white (chess-game-data chess-module-game 'white-remaining)) (black (chess-game-data chess-module-game 'black-remaining))) - (if (and (not (and white black)) - (> chess-display-index 0)) + (if (not (and white black)) (let ((last-ply (chess-game-ply chess-module-game (1- chess-display-index)))) (setq white (chess-ply-keyword last-ply :white) @@ -271,9 +270,16 @@ also view the same game." (to (cadr ch))) (funcall chess-display-event-handler 'draw-square (chess-display-index-pos nil from) ? from) - (funcall chess-display-event-handler 'draw-square - (chess-display-index-pos nil to) - (chess-pos-piece position from) to)) + (let ((new-piece (chess-ply-keyword ply :promote))) + (if new-piece + (funcall chess-display-event-handler 'draw-square + (chess-display-index-pos nil to) + (if (chess-pos-side-to-move position) + new-piece + (downcase new-piece)) to) + (funcall chess-display-event-handler 'draw-square + (chess-display-index-pos nil to) + (chess-pos-piece position from) to)))) (setq ch (cddr ch))))))) (chess-message-catalog 'english diff --git a/chess-engine.el b/chess-engine.el index 14cae60..1ebbd76 100644 --- a/chess-engine.el +++ b/chess-engine.el @@ -87,26 +87,28 @@ (let ((game (chess-engine-game nil))) (cond ((eq event 'move) - (if (chess-game-data game 'active) - ;; we don't want the `move' event coming back to us - (let ((chess-engine-handling-event t)) - (when (car args) - ;; if the game index is still 0, then our opponent - ;; is white, and we need to pass over the move - (when (and (not chess-engine-inhibit-auto-pass) - (chess-game-data game 'my-color) - (= (chess-game-index game) 0)) - (chess-game-set-tag game "White" chess-engine-opponent-name) - (chess-game-set-tag game "Black" chess-full-name) - (chess-message 'now-black) - (chess-game-run-hooks game 'pass) - ;; if no one else flipped my-color, we'll do it - (if (chess-game-data game 'my-color) - (chess-game-set-data game 'my-color nil))) - (chess-game-move game (car args)) - (if (chess-game-over-p game) - (chess-game-set-data game 'active nil)) - t)))) + (let ((chess-engine-handling-event t)) + (when (and (car args) + (chess-game-data game 'active)) + + ;; if the game index is still 0, then our opponent + ;; is white, and we need to pass over the move + (when (and (not chess-engine-inhibit-auto-pass) + (chess-game-data game 'my-color) + (= (chess-game-index game) 0)) + (chess-game-set-tag game "White" chess-engine-opponent-name) + (chess-game-set-tag game "Black" chess-full-name) + (chess-message 'now-black) + (chess-game-run-hooks game 'pass) + ;; if no one else flipped my-color, we'll do it + (if (chess-game-data game 'my-color) + (chess-game-set-data game 'my-color nil))) + + (chess-game-move game (car args)) + + (if (chess-game-over-p game) + (chess-game-set-data game 'active nil)) + t))) ((eq event 'pass) (when (chess-game-data game 'active) diff --git a/chess-game.el b/chess-game.el index 7c90b38..e5c93b7 100644 --- a/chess-game.el +++ b/chess-game.el @@ -203,7 +203,7 @@ This conveys the status of the game at the given index." (defsubst chess-game-over-p (game) "Return the position related to GAME's INDEX position." - (let ((last-ply (car (last game 2)))) + (let ((last-ply (car (last (nth 3 game) 2)))) (and last-ply (chess-ply-final-p last-ply)))) diff --git a/chess-ics.el b/chess-ics.el index 0f80cba..1341ae1 100644 --- a/chess-ics.el +++ b/chess-ics.el @@ -107,7 +107,7 @@ The list is comprised of: the ply the string represents, who is white, who is black." (let ((parts (split-string string " ")) (position (chess-pos-create t)) - white black white-time black-time move) + white black white-time black-time move status) (assert (= (length parts) 32)) @@ -245,18 +245,22 @@ who is black." ;; causal ply (car (last (chess-game-plies game)))) (nth 1 info) t))) - (setq error 'setting-white-remaining) (chess-game-set-data game 'white-remaining (nth 4 info)) - (setq error 'setting-black-remaining) (chess-game-set-data game 'black-remaining (nth 5 info)) (setq error 'applying-move) (chess-game-move game ply) (setq error nil)) (setq error nil)) - (let ((chess-game-inhibit-events t) plies) + (let ((chess-game-inhibit-events t) + (color (chess-pos-side-to-move (nth 0 info))) + plies) (when (or (= 1 (nth 6 info)) (= -1 (nth 6 info))) - (chess-game-set-data game 'my-color (= 1 (nth 6 info))) - (chess-game-set-data game 'active t)) + (chess-game-set-data game 'my-color (if (= 1 (nth 6 info)) + color + (not color))) + (chess-game-set-data game 'active t) + (chess-game-set-data game 'white-remaining (nth 4 info)) + (chess-game-set-data game 'black-remaining (nth 5 info))) (chess-game-set-tag game "White" (nth 2 info)) (chess-game-set-tag game "Black" (nth 3 info)) (chess-game-set-tag game "Site" (car chess-ics-server)) |
