comparison lisp/play/gametree.el @ 49598:0d8b17d428b5

Trailing whitepace deleted.
author Juanma Barranquero <lekktu@gmail.com>
date Tue, 04 Feb 2003 13:24:35 +0000
parents b7d8faf8cca0
children 695cf19ef79e d7ddb3e565de
comparison
equal deleted inserted replaced
49597:e88404e8f2cf 49598:0d8b17d428b5
65 ;; 27. Qe5 Ne5 28. Kf1 Nf3 -/+ 65 ;; 27. Qe5 Ne5 28. Kf1 Nf3 -/+
66 ;; 27. Kf1 Nh2 28. Kf2 Ng4 29. fg4 Rf8 30. Ke1 Qg3 31. Kd1 Rf2 -+ 66 ;; 27. Kf1 Nh2 28. Kf2 Ng4 29. fg4 Rf8 30. Ke1 Qg3 31. Kd1 Rf2 -+
67 67
68 ;; and the cursor is positioned on the new line just after the move 68 ;; 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, 69 ;; number, so you can start typing the new analysis. That's it,
70 ;; quite simple. 70 ;; quite simple.
71 71
72 ;; As of version 1.1, a simple score reducer has been implemented. 72 ;; 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 73 ;; As you type in leaf variations, you can add a numerical score tag
74 ;; to them with C-c ; . Then, with the cursor on a variation higher 74 ;; to them with C-c ; . Then, with the cursor on a variation higher
75 ;; up in the tree, you can do C-c ^ and the program will compute the 75 ;; up in the tree, you can do C-c ^ and the program will compute the
197 (delete-char (1- (save-excursion (skip-chars-forward " \t")))))))) 197 (delete-char (1- (save-excursion (skip-chars-forward " \t"))))))))
198 198
199 (defun gametree-looking-at-ply () 199 (defun gametree-looking-at-ply ()
200 "Read and return the number of the ply under point." 200 "Read and return the number of the ply under point."
201 (if (eobp) 0 201 (if (eobp) 0
202 (let ((boundary (concat "[ \t]*\\([1-9][0-9]*\\)\\(" 202 (let ((boundary (concat "[ \t]*\\([1-9][0-9]*\\)\\("
203 gametree-full-ply-regexp "\\|" 203 gametree-full-ply-regexp "\\|"
204 gametree-half-ply-regexp "\\)")) 204 gametree-half-ply-regexp "\\)"))
205 (limit (save-excursion (beginning-of-line 1) (point)))) 205 (limit (save-excursion (beginning-of-line 1) (point))))
206 (if (looking-at boundary) 206 (if (looking-at boundary)
207 (+ (* 2 (string-to-int (match-string 1))) 207 (+ (* 2 (string-to-int (match-string 1)))
208 (if (string-match gametree-half-ply-regexp (match-string 2)) 1 0)) 208 (if (string-match gametree-half-ply-regexp (match-string 2)) 1 0))
209 (save-excursion 209 (save-excursion
210 (re-search-backward boundary limit) 210 (re-search-backward boundary limit)
211 (skip-chars-backward "0123456789") 211 (skip-chars-backward "0123456789")
212 (1+ (* 2 (string-to-int 212 (1+ (* 2 (string-to-int
213 (buffer-substring (point) (match-end 1)))))))))) 213 (buffer-substring (point) (match-end 1))))))))))
214 214
215 (defun gametree-current-branch-ply () 215 (defun gametree-current-branch-ply ()
216 "Return the ply number of the first move of the current variation." 216 "Return the ply number of the first move of the current variation."
217 (save-excursion 217 (save-excursion
218 (beginning-of-line 1) 218 (beginning-of-line 1)
219 (re-search-forward (concat "\\=" outline-regexp) nil t) 219 (re-search-forward (concat "\\=" outline-regexp) nil t)
242 (prog1 (buffer-substring p (point)) 242 (prog1 (buffer-substring p (point))
243 (delete-region p (point))))))) 243 (delete-region p (point)))))))
244 (save-excursion 244 (save-excursion
245 (beginning-of-line 1) 245 (beginning-of-line 1)
246 (insert following-leaves)))) 246 (insert following-leaves))))
247 247
248 248
249 ;;;; Functions related to the task of saving and restoring current 249 ;;;; Functions related to the task of saving and restoring current
250 ;;;; outline layout 250 ;;;; outline layout
251 251
252 (defsubst gametree-show-children-and-entry () 252 (defsubst gametree-show-children-and-entry ()
334 (if (looking-at "[^\n]*-\*-[^\n]*gametree-local-layout: \\([^;\n]*\\);") 334 (if (looking-at "[^\n]*-\*-[^\n]*gametree-local-layout: \\([^;\n]*\\);")
335 (progn 335 (progn
336 (goto-char (match-beginning 1)) 336 (goto-char (match-beginning 1))
337 (delete-region (point) (match-end 1)) 337 (delete-region (point) (match-end 1))
338 (let ((standard-output (current-buffer))) 338 (let ((standard-output (current-buffer)))
339 (princ gametree-local-layout)))))) 339 (princ gametree-local-layout))))))
340 340
341 341
342 ;;;; Scoring functions 342 ;;;; Scoring functions
343 343
344 (defun gametree-current-branch-score () 344 (defun gametree-current-branch-score ()
406 (condition-case nil 406 (condition-case nil
407 (outline-next-visible-heading 1) 407 (outline-next-visible-heading 1)
408 (error 408 (error
409 (goto-char (point-max)) 409 (goto-char (point-max))
410 (if (not (bolp)) (insert "\n")))) 410 (if (not (bolp)) (insert "\n"))))
411 (let ((starting-plys 411 (let ((starting-plys
412 (if (> (gametree-current-branch-depth) parent-depth) 412 (if (> (gametree-current-branch-depth) parent-depth)
413 (gametree-current-branch-ply) 413 (gametree-current-branch-ply)
414 (save-excursion (forward-line -1) 414 (save-excursion (forward-line -1)
415 (gametree-current-branch-ply))))) 415 (gametree-current-branch-ply)))))
416 (goto-char (1- (point))) 416 (goto-char (1- (point)))
427 reflects the number of game plys between the beginning of the current 427 reflects the number of game plys between the beginning of the current
428 variation and the breaking point. 428 variation and the breaking point.
429 429
430 With a numerical argument AT-MOVE, split the variation before 430 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 431 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 432 only work of Black's moves are explicitly numbered, for instance
433 `1. e4 1: e5'." 433 `1. e4 1: e5'."
434 (interactive "*P") 434 (interactive "*P")
435 (if at-move (progn 435 (if at-move (progn
436 (end-of-line 1) 436 (end-of-line 1)
437 (let ((limit (point))) 437 (let ((limit (point)))
464 (save-excursion 464 (save-excursion
465 (beginning-of-line 1) 465 (beginning-of-line 1)
466 (funcall gametree-make-heading-function depth) 466 (funcall gametree-make-heading-function depth)
467 (gametree-prettify-heading)))) 467 (gametree-prettify-heading))))
468 (save-excursion 468 (save-excursion
469 (if (not (looking-at (concat "[ \t]*[1-9][0-9]*\\(" 469 (if (not (looking-at (concat "[ \t]*[1-9][0-9]*\\("
470 gametree-full-ply-regexp "\\|" 470 gametree-full-ply-regexp "\\|"
471 gametree-half-ply-regexp "\\)"))) 471 gametree-half-ply-regexp "\\)")))
472 (progn 472 (progn
473 (insert (format (if (= 0 (mod (gametree-looking-at-ply) 2)) 473 (insert (format (if (= 0 (mod (gametree-looking-at-ply) 2))
474 gametree-full-ply-format 474 gametree-full-ply-format
475 gametree-half-ply-format) 475 gametree-half-ply-format)
523 (insert gametree-score-opener) 523 (insert gametree-score-opener)
524 (if (not auto) (insert gametree-score-manual-flag)) 524 (if (not auto) (insert gametree-score-manual-flag))
525 (save-excursion (insert gametree-score-closer))) 525 (save-excursion (insert gametree-score-closer)))
526 (if (not (null score)) 526 (if (not (null score))
527 (save-excursion 527 (save-excursion
528 (insert (int-to-string (prefix-numeric-value score)))))) 528 (insert (int-to-string (prefix-numeric-value score))))))
529 529
530 (defun gametree-compute-and-insert-score () 530 (defun gametree-compute-and-insert-score ()
531 "Compute current node score, maybe recursively from subnodes. Insert it. 531 "Compute current node score, maybe recursively from subnodes. Insert it.
532 Subnodes which have been manually scored are honored." 532 Subnodes which have been manually scored are honored."
533 (interactive "*") 533 (interactive "*")
534 (let ((auto (not (and (looking-at gametree-score-regexp) 534 (let ((auto (not (and (looking-at gametree-score-regexp)
566 (let ((inhibit-read-only t)) 566 (let ((inhibit-read-only t))
567 (gametree-hack-file-layout)) 567 (gametree-hack-file-layout))
568 nil) 568 nil)
569 569
570 (define-derived-mode gametree-mode outline-mode "GameTree" 570 (define-derived-mode gametree-mode outline-mode "GameTree"
571 "Major mode for managing game analysis trees. 571 "Major mode for managing game analysis trees.
572 Useful to postal and email chess (and, it is hoped, also checkers, go, 572 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. 573 shogi, etc.) players, it is a slightly modified version of Outline mode.
574 574
575 \\{gametree-mode-map}" 575 \\{gametree-mode-map}"
576 (auto-fill-mode 0) 576 (auto-fill-mode 0)