summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2002-05-01 05:39:41 +0000
committerJohn Wiegley <johnw@newartisans.com>2002-05-01 05:39:41 +0000
commit652c8b322bf058c35eb48b5373976f22e3e3276f (patch)
tree327151f018a3db90e696bd8943506ffe942e9fd0
parent4197d08b7f37f9c1155559897d750ad1f53af241 (diff)
*** no comment ***
-rw-r--r--PLAN3
-rw-r--r--chess-autosave.el84
-rw-r--r--chess-clock.el15
3 files changed, 67 insertions, 35 deletions
diff --git a/PLAN b/PLAN
index 2baf874..c7cd54e 100644
--- a/PLAN
+++ b/PLAN
@@ -14,6 +14,9 @@ chess
- have an option which causes all completed games to be added to a
given database
+chess-autosave
+- recovering from an autosave against crafty does not seem to work
+
BEFORE FINAL RELEASE
use more asserts throughout the code
diff --git a/chess-autosave.el b/chess-autosave.el
index 9ab935c..9296785 100644
--- a/chess-autosave.el
+++ b/chess-autosave.el
@@ -26,8 +26,7 @@
(if (file-readable-p chess-autosave-file)
(if (y-or-n-p (chess-string 'chess-read-autosave))
(progn
- (chess-game-copy-game game (chess-autosave-read
- chess-autosave-file))
+ (chess-autosave-read game chess-autosave-file)
(delete-file chess-autosave-file))
(if (y-or-n-p (chess-string 'chess-delete-autosave))
(delete-file chess-autosave-file)
@@ -48,41 +47,66 @@
(if (file-readable-p chess-autosave-file)
(delete-file chess-autosave-file)))))
+(defun chess-prin1-ply (ply)
+ (insert "([")
+ (let ((pos (chess-ply-pos ply)))
+ (dotimes (i 74)
+ (prin1 (aref pos i) (current-buffer))
+ (insert ? )))
+ (insert "nil]")
+ (let ((changes (chess-ply-changes ply)))
+ (if changes
+ (insert ? ))
+ (while changes
+ (if (eq (car changes) :next-pos)
+ (setq changes (cddr changes))
+ (prin1 (car changes) (current-buffer))
+ (if (cdr changes)
+ (insert ? ))
+ (setq changes (cdr changes)))))
+ (insert ")"))
+
(defun chess-autosave-write (game file)
"Write a chess GAME to FILE as raw Lisp."
(with-current-buffer (find-file-noselect file t)
- (erase-buffer)
- (insert "(nil ")
- (prin1 (chess-game-tags game) (current-buffer))
- (insert " nil (")
- (dolist (ply (chess-game-plies game))
- (insert "([")
- (let ((pos (chess-ply-pos ply)))
- (dotimes (i 74)
- (prin1 (aref pos i) (current-buffer))
- (unless (= i 73)
- (insert ? ))))
- (insert ?\])
- (let ((changes (chess-ply-changes ply)))
- (if changes
- (insert ? ))
- (while changes
- (if (eq (car changes) :next-pos)
- (setq changes (cddr changes))
- (prin1 (car changes) (current-buffer))
- (if (cdr changes)
- (insert ? ))
- (setq changes (cdr changes)))))
- (insert ") "))
- (insert "))")
- (basic-save-buffer)
- (message nil)))
+ (let ((index (chess-game-index game)))
+ (if (or (= 1 index) (eobp))
+ (progn
+ (erase-buffer)
+ (prin1 (chess-game-tags game)
+ (current-buffer))
+ (insert "\n(\n;;## ply 0\n"))
+ (goto-char (point-max))
+ (re-search-backward "^;;## ply")
+ (forward-line)
+ (delete-region (point) (point-max)))
+ (chess-prin1-ply (chess-game-ply game (1- index)))
+ (insert (format "\n;;## ply %d\n" index))
+ (chess-prin1-ply (chess-game-ply game))
+ (insert ")\n")
+ (basic-save-buffer)
+ (message nil))))
-(defun chess-autosave-read (file)
+(defun chess-autosave-read (game file)
"Read a chess game as raw Lisp from FILE."
(with-current-buffer (find-file-noselect file t)
(goto-char (point-min))
- (read (current-buffer))))
+ (chess-game-set-tags game (read (current-buffer)))
+
+ (let* ((plies (read (current-buffer)))
+ (game-plies plies)
+ prev-ply)
+ (while plies
+ (if prev-ply
+ (chess-pos-set-preceding-ply (chess-ply-pos (car plies))
+ prev-ply))
+ (if (cdr plies)
+ (chess-ply-set-keyword (car plies) :next-pos
+ (chess-ply-pos (cadr plies))))
+ (setq prev-ply (car plies)
+ plies (cdr plies)))
+
+ (chess-game-set-plies game game-plies))))
(provide 'chess-autosave)
diff --git a/chess-clock.el b/chess-clock.el
index cbb5c37..9ef01f7 100644
--- a/chess-clock.el
+++ b/chess-clock.el
@@ -55,19 +55,24 @@
(> (chess-game-index game) 0))
(unless chess-clock-timer
(setq chess-clock-timer
- (run-with-timer 0 1 'chess-clock-tick-tock (current-buffer))))
+ (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 (and chess-clock-timer (chess-game-over-p game))
- (cancel-timer chess-clock-timer)
- (setq chess-clock-timer nil)))
+ (if (chess-game-over-p game)
+ (chess-clock-handler game 'destroy)))
((eq event 'set-data)
(if (and (eq (car args) 'active)
(not (chess-game-data game 'active)))
- (chess-clock-handler game 'destroy)))))
+ (chess-clock-handler game 'destroy)))
+
+ ((eq event 'destroy)
+ (if chess-clock-timer
+ (cancel-timer chess-clock-timer)
+ (setq chess-clock-timer nil)))))
(defvar chess-clock-tick-tocking nil)