67 |
|
|
68 |
;; and the cursor is positioned on the new line just after the move |
;; and the cursor is positioned on the new line just after the move |
69 |
;; number, so you can start typing the new analysis. That's it, |
;; number, so you can start typing the new analysis. That's it, |
70 |
;; quite simple. |
;; quite simple. |
71 |
|
|
72 |
;; As of version 1.1, a simple score reducer has been implemented. |
;; As of version 1.1, a simple score reducer has been implemented. |
73 |
;; As you type in leaf variations, you can add a numerical score tag |
;; As you type in leaf variations, you can add a numerical score tag |
199 |
(defun gametree-looking-at-ply () |
(defun gametree-looking-at-ply () |
200 |
"Read and return the number of the ply under point." |
"Read and return the number of the ply under point." |
201 |
(if (eobp) 0 |
(if (eobp) 0 |
202 |
(let ((boundary (concat "[ \t]*\\([1-9][0-9]*\\)\\(" |
(let ((boundary (concat "[ \t]*\\([1-9][0-9]*\\)\\(" |
203 |
gametree-full-ply-regexp "\\|" |
gametree-full-ply-regexp "\\|" |
204 |
gametree-half-ply-regexp "\\)")) |
gametree-half-ply-regexp "\\)")) |
205 |
(limit (save-excursion (beginning-of-line 1) (point)))) |
(limit (save-excursion (beginning-of-line 1) (point)))) |
206 |
(if (looking-at boundary) |
(if (looking-at boundary) |
207 |
(+ (* 2 (string-to-int (match-string 1))) |
(+ (* 2 (string-to-int (match-string 1))) |
208 |
(if (string-match gametree-half-ply-regexp (match-string 2)) 1 0)) |
(if (string-match gametree-half-ply-regexp (match-string 2)) 1 0)) |
209 |
(save-excursion |
(save-excursion |
210 |
(re-search-backward boundary limit) |
(re-search-backward boundary limit) |
211 |
(skip-chars-backward "0123456789") |
(skip-chars-backward "0123456789") |
212 |
(1+ (* 2 (string-to-int |
(1+ (* 2 (string-to-int |
213 |
(buffer-substring (point) (match-end 1)))))))))) |
(buffer-substring (point) (match-end 1)))))))))) |
214 |
|
|
215 |
(defun gametree-current-branch-ply () |
(defun gametree-current-branch-ply () |
216 |
"Return the ply number of the first move of the current variation." |
"Return the ply number of the first move of the current variation." |
217 |
(save-excursion |
(save-excursion |
244 |
(save-excursion |
(save-excursion |
245 |
(beginning-of-line 1) |
(beginning-of-line 1) |
246 |
(insert following-leaves)))) |
(insert following-leaves)))) |
247 |
|
|
248 |
|
|
249 |
;;;; Functions related to the task of saving and restoring current |
;;;; Functions related to the task of saving and restoring current |
250 |
;;;; outline layout |
;;;; outline layout |
336 |
(goto-char (match-beginning 1)) |
(goto-char (match-beginning 1)) |
337 |
(delete-region (point) (match-end 1)) |
(delete-region (point) (match-end 1)) |
338 |
(let ((standard-output (current-buffer))) |
(let ((standard-output (current-buffer))) |
339 |
(princ gametree-local-layout)))))) |
(princ gametree-local-layout)))))) |
340 |
|
|
341 |
|
|
342 |
;;;; Scoring functions |
;;;; Scoring functions |
408 |
(error |
(error |
409 |
(goto-char (point-max)) |
(goto-char (point-max)) |
410 |
(if (not (bolp)) (insert "\n")))) |
(if (not (bolp)) (insert "\n")))) |
411 |
(let ((starting-plys |
(let ((starting-plys |
412 |
(if (> (gametree-current-branch-depth) parent-depth) |
(if (> (gametree-current-branch-depth) parent-depth) |
413 |
(gametree-current-branch-ply) |
(gametree-current-branch-ply) |
414 |
(save-excursion (forward-line -1) |
(save-excursion (forward-line -1) |
429 |
|
|
430 |
With a numerical argument AT-MOVE, split the variation before |
With a numerical argument AT-MOVE, split the variation before |
431 |
White's AT-MOVEth move, or Black's if negative. The last option will |
White's AT-MOVEth move, or Black's if negative. The last option will |
432 |
only work of Black's moves are explicitly numbered, for instance |
only work of Black's moves are explicitly numbered, for instance |
433 |
`1. e4 1: e5'." |
`1. e4 1: e5'." |
434 |
(interactive "*P") |
(interactive "*P") |
435 |
(if at-move (progn |
(if at-move (progn |
466 |
(funcall gametree-make-heading-function depth) |
(funcall gametree-make-heading-function depth) |
467 |
(gametree-prettify-heading)))) |
(gametree-prettify-heading)))) |
468 |
(save-excursion |
(save-excursion |
469 |
(if (not (looking-at (concat "[ \t]*[1-9][0-9]*\\(" |
(if (not (looking-at (concat "[ \t]*[1-9][0-9]*\\(" |
470 |
gametree-full-ply-regexp "\\|" |
gametree-full-ply-regexp "\\|" |
471 |
gametree-half-ply-regexp "\\)"))) |
gametree-half-ply-regexp "\\)"))) |
472 |
(progn |
(progn |
473 |
(insert (format (if (= 0 (mod (gametree-looking-at-ply) 2)) |
(insert (format (if (= 0 (mod (gametree-looking-at-ply) 2)) |
525 |
(save-excursion (insert gametree-score-closer))) |
(save-excursion (insert gametree-score-closer))) |
526 |
(if (not (null score)) |
(if (not (null score)) |
527 |
(save-excursion |
(save-excursion |
528 |
(insert (int-to-string (prefix-numeric-value score)))))) |
(insert (int-to-string (prefix-numeric-value score)))))) |
529 |
|
|
530 |
(defun gametree-compute-and-insert-score () |
(defun gametree-compute-and-insert-score () |
531 |
"Compute current node score, maybe recursively from subnodes. Insert it. |
"Compute current node score, maybe recursively from subnodes. Insert it. |
532 |
Subnodes which have been manually scored are honored." |
Subnodes which have been manually scored are honored." |
568 |
nil) |
nil) |
569 |
|
|
570 |
(define-derived-mode gametree-mode outline-mode "GameTree" |
(define-derived-mode gametree-mode outline-mode "GameTree" |
571 |
"Major mode for managing game analysis trees. |
"Major mode for managing game analysis trees. |
572 |
Useful to postal and email chess (and, it is hoped, also checkers, go, |
Useful to postal and email chess (and, it is hoped, also checkers, go, |
573 |
shogi, etc.) players, it is a slightly modified version of Outline mode. |
shogi, etc.) players, it is a slightly modified version of Outline mode. |
574 |
|
|