[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] 30/255: saving the board configuration with each sgf step
From: |
Eric Schulte |
Subject: |
[elpa] 30/255: saving the board configuration with each sgf step |
Date: |
Sun, 16 Mar 2014 01:02:13 +0000 |
eschulte pushed a commit to branch go
in repository elpa.
commit 099a98bba8fe7ec682be9fc7a89118c9f259fd93
Author: Eric Schulte <address@hidden>
Date: Wed May 16 23:49:18 2012 -0400
saving the board configuration with each sgf step
This involves both defining a setf method to set values at the current
point in the sgf file, as well as defining a backing store for board
information which won't change when the board changes.
---
sgf.el | 63 +++++++++++++++++++++++++++++++++++++++++----------------------
1 files changed, 41 insertions(+), 22 deletions(-)
diff --git a/sgf.el b/sgf.el
index 7b0096c..98fd973 100644
--- a/sgf.el
+++ b/sgf.el
@@ -277,6 +277,17 @@
(body (board-body-to-string board)))
(mapconcat #'identity (list header body header) "\n")))
+(defun board-to-pieces (board)
+ (let (pieces)
+ (dotimes (n (length board) pieces)
+ (let ((val (aref board n)))
+ (when val (push (cons val n) pieces))))))
+
+(defun pieces-to-board (pieces size)
+ (let ((board (make-vector size nil)))
+ (dolist (piece pieces board)
+ (setf (aref board (cdr piece)) (car piece)))))
+
(defun update-display ()
(unless *sgf* (error "sgf: buffer has not associated sgf data"))
(delete-region (point-min) (point-max))
@@ -309,6 +320,8 @@
(setq *sgf* game)
(setq *board* (make-board size))
(setq *index* '(0))
+ (push (cons :pieces (board-to-pieces *board*))
+ (sgf-ref *sgf* *index*))
(update-display))
(pop-to-buffer buffer)))
@@ -319,6 +332,15 @@
(setq index (cdr index)))
part))
+(defun set-sgf-ref (sgf index new)
+ (eval `(setf ,(if (listp index)
+ (reduce (lambda (acc el) (list 'nth el acc))
+ index :initial-value 'sgf)
+ `(nth ,accessor 'sgf))
+ ',new)))
+
+(defsetf sgf-ref set-sgf-ref)
+
(defun up ())
(defun down ())
@@ -329,8 +351,10 @@
(unless (sgf-ref *sgf* *index*)
(update-display)
(error "sgf: no more backwards moves."))
- (revert-moves *board* (sgf-ref *sgf* *index*))
- (decf (car (last *index*))))
+ (decf (car (last *index*)))
+ (setq *board* (pieces-to-board
+ (aget :pieces (sgf-ref *sgf* *index*))
+ (length *board*))))
(update-display)))
(defun right (&optional num)
@@ -341,10 +365,18 @@
(decf (car (last *index*)))
(update-display)
(error "sgf: no more forward moves."))
- (clean-board *board*)
- (apply-moves *board* (sgf-ref *sgf* *index*)))
+ (if (aget :pieces (sgf-ref *sgf* *index*))
+ (setf *board* (pieces-to-board
+ (aget :pieces (sgf-ref *sgf* *index*))
+ (length *board*)))
+ (clear-labels *board*)
+ (apply-moves *board* (sgf-ref *sgf* *index*))
+ (push (cons :pieces (board-to-pieces *board*))
+ (sgf-ref *sgf* *index*))))
(update-display)))
+(sgf-ref *game* '(0))
+
;;; Board manipulation functions
(defun move-type (move)
@@ -366,24 +398,11 @@
(:move (set (car move) (cdr move)))
(:label (mapcar (lambda (data) (set (car move) data)) (cdr move)))))))
-(defun revert-moves (board moves)
- (flet ((unset (data)
- (setf (aref board (pos-to-index (aget :pos data)
- (board-size board)))
- nil)))
- (dolist (move moves board)
- (case (move-type move)
- (:move (unset (cdr move)))
- (:label (mapcar #'unset (cdr move)))))))
-
-(defun clean-board (board)
- ;; TODO: need to remove dead stones, need a board-wide-check and sweep
- (flet ((alive-p (board point) t))
- (dotimes (point (length board))
- (when (aref board point)
- (unless (and (member (aref board point) '(:b :w))
- (alive-p board point))
- (setf (aref board point) nil))))))
+(defun clear-labels (board)
+ (dotimes (point (length board))
+ (when (aref board point)
+ (unless (member (aref board point) '(:b :w))
+ (setf (aref board point) nil)))))
;;; Display mode
- [elpa] 23/255: more complex but more intuitive and useful `range', (continued)
- [elpa] 23/255: more complex but more intuitive and useful `range', Eric Schulte, 2014/03/15
- [elpa] 21/255: display sgf file as a go board in a buffer, Eric Schulte, 2014/03/15
- [elpa] 25/255: right and left are mainly working, Eric Schulte, 2014/03/15
- [elpa] 29/255: q now quits a sgf display buffer, Eric Schulte, 2014/03/15
- [elpa] 28/255: adding a major mode for board navigation keys, Eric Schulte, 2014/03/15
- [elpa] 27/255: implementation notes, Eric Schulte, 2014/03/15
- [elpa] 31/255: a test to protect against unwanted state changes, Eric Schulte, 2014/03/15
- [elpa] 33/255: removing dead pieces after moves, Eric Schulte, 2014/03/15
- [elpa] 35/255: compiled and caught some minor issues, Eric Schulte, 2014/03/15
- [elpa] 32/255: consolidating utility functions, Eric Schulte, 2014/03/15
- [elpa] 30/255: saving the board configuration with each sgf step,
Eric Schulte <=
- [elpa] 18/255: applying moves to a board, Eric Schulte, 2014/03/15
- [elpa] 37/255: remove debug printf, Eric Schulte, 2014/03/15
- [elpa] 34/255: beginning to stub out tests for dead stone removal, Eric Schulte, 2014/03/15
- [elpa] 38/255: more capture tests, failing multistone captures, Eric Schulte, 2014/03/15
- [elpa] 36/255: passing all tests (at least it did this once), Eric Schulte, 2014/03/15
- [elpa] 26/255: improvements, considering labels and moves, Eric Schulte, 2014/03/15
- [elpa] 40/255: parsing empty properties, Eric Schulte, 2014/03/15
- [elpa] 42/255: more work with tree parsing, Eric Schulte, 2014/03/15
- [elpa] 46/255: TODO: try using load-read-function and try loading these files w/read, Eric Schulte, 2014/03/15
- [elpa] 45/255: looking at a new method of parsing trees, Eric Schulte, 2014/03/15