[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] 28/255: adding a major mode for board navigation keys
From: |
Eric Schulte |
Subject: |
[elpa] 28/255: adding a major mode for board navigation keys |
Date: |
Sun, 16 Mar 2014 01:02:12 +0000 |
eschulte pushed a commit to branch go
in repository elpa.
commit db02f8e704ef9d908a3fa46dfa57ad0218ba68b4
Author: Eric Schulte <address@hidden>
Date: Wed May 16 00:04:35 2012 -0400
adding a major mode for board navigation keys
---
sgf.el | 35 +++++++++++++++++++++++++++++------
1 files changed, 29 insertions(+), 6 deletions(-)
diff --git a/sgf.el b/sgf.el
index c5fb981..828c74e 100644
--- a/sgf.el
+++ b/sgf.el
@@ -305,6 +305,7 @@
(unless size
(error "sgf: game has no associated size"))
(with-current-buffer buffer
+ (sgf-mode)
(setq *sgf* game)
(setq *board* (make-board size))
(setq *index* '(0))
@@ -340,6 +341,7 @@
(decf (car (last *index*)))
(update-display)
(error "sgf: no more forward moves."))
+ (clean-board *board*)
(apply-moves *board* (sgf-ref *sgf* *index*)))
(update-display)))
@@ -356,8 +358,6 @@
(board-size board)))
(cond ((string= "B" val) :b)
((string= "W" val) :w)
- ;; TODO: instead of just storing the label
- ;; string do (:label string)
((string= "LB" val) (aget :label data))
((string= "LW" val) (aget :label data))
(t nil)))))
@@ -367,13 +367,36 @@
(:label (mapcar (lambda (data) (set (car move) data)) (cdr move)))))))
(defun revert-moves (board moves)
- (flet ((unset (move)
- (setf (aref board (pos-to-index (cdr move) (board-size board)))
+ (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 (set move))
- (:label (mapcar #'set 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))))))
+
+
+;;; Display mode
+(defvar sgf-mode-map
+ (let ((map (make-sparse-keymap)))
+ (define-key map (kbd "<right>") 'right)
+ (define-key map (kbd "<left>") 'left)
+ (define-key map (kbd "q") 'kill-buffer)
+ map)
+ "Keymap for `sgf-mode'.")
+
+(define-derived-mode sgf-mode nil "SGF"
+ "Major mode for editing text written for viewing SGF files.")
;;; Tests
- [elpa] 20/255: alright "i" *is* a valid position identifier, (continued)
- [elpa] 20/255: alright "i" *is* a valid position identifier, Eric Schulte, 2014/03/15
- [elpa] 16/255: cleaned up board printing, Eric Schulte, 2014/03/15
- [elpa] 09/255: parsing more complex trees, Eric Schulte, 2014/03/15
- [elpa] 19/255: moving games/ -> sgf-files/, Eric Schulte, 2014/03/15
- [elpa] 10/255: helper functions, Eric Schulte, 2014/03/15
- [elpa] 24/255: right and left implemented but buggy, Eric Schulte, 2014/03/15
- [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 <=
- [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, 2014/03/15
- [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