1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6 (require 'chess-display)
8 (defgroup chess-ics1 nil
9 "The ICS1 style ASCII display."
10 :group 'chess-display)
12 (defface chess-ics1-black-face
13 '((((class color) (background light)) (:foreground "Green"))
14 (((class color) (background dark)) (:foreground "Green"))
16 "*The face used for black pieces on the ASCII display."
19 (defface chess-ics1-white-face
20 '((((class color) (background light)) (:foreground "Yellow"))
21 (((class color) (background dark)) (:foreground "Yellow"))
23 "*The face used for white pieces on the ASCII display."
26 (defface chess-ics1-highlight-face
27 '((((class color) (background light)) (:background "#add8e6"))
28 (((class color) (background dark)) (:background "#add8e6")))
29 "Face to use for highlighting pieces that have been selected."
32 (defcustom chess-ics1-popup-function 'chess-display-popup-in-window
33 "The function used to popup a chess-ics1 display."
39 (defun chess-ics1-handler (event &rest args)
41 ((eq event 'initialize) t)
43 (if chess-display-popup
44 (funcall chess-ics1-popup-function)))
46 (apply 'chess-ics1-draw args))
47 ((eq event 'highlight)
48 (apply 'chess-ics1-highlight args))))
50 (defun chess-ics1-draw (position perspective)
51 "Draw the given POSITION from PERSPECTIVE's point of view.
52 PERSPECTIVE is t for white or nil for black."
53 (let ((inhibit-redisplay t)
56 (let* ((inverted (not perspective))
57 (rank (if inverted 7 0))
58 (file (if inverted 7 0))
60 (insert "\n +---+---+---+---+---+---+---+---+\n")
61 (while (if inverted (>= rank 0) (< rank 8))
62 (if (/= rank (if inverted 7 0))
63 (insert " +---+---+---+---+---+---+---+---+\n"))
64 (while (if inverted (>= file 0) (< file 8))
65 (let ((piece (chess-pos-piece position
66 (chess-rf-to-index rank file)))
68 (if (= file (if inverted 7 0))
69 (insert (format " %d " (1+ (- 7 rank)))))
71 (setq begin (1- (point)))
72 (let ((p (char-to-string piece)))
74 0 1 (list 'face (if (> piece ?a)
75 'chess-ics1-black-face
76 'chess-ics1-white-face)) p)
79 (add-text-properties begin (point)
81 (chess-rf-to-index rank file))))
82 (setq file (if inverted (1- file) (1+ file))))
84 (setq file (if inverted 7 0)
85 rank (if inverted (1- rank) (1+ rank))))
86 (insert " +---+---+---+---+---+---+---+---+\n")
88 (insert " h g f e d c b a\n\n")
89 (insert " a b c d e f g h\n\n")))
90 (set-buffer-modified-p nil)
93 (defun chess-ics1-highlight (index &optional mode)
94 (if (null (get-buffer-window (current-buffer) t))
95 (pop-to-buffer (current-buffer)))
96 (let ((inverted (not (chess-display-perspective nil)))
99 (goto-char (point-min))
100 (let ((rank (chess-index-rank index))
101 (file (chess-index-file index)))
102 (goto-line (+ 3 (* 2 (if inverted (- 7 rank) rank))))
103 (forward-char (+ 8 (* 4 (if inverted (- 7 file) file)))))
104 (skip-chars-backward "^|")
106 (skip-chars-forward "^|")
107 (put-text-property beg (point) 'face
110 'chess-ics1-highlight-face)
112 (chess-display-get-face mode)))))))
114 (defun chess-debug-position (&optional position)
115 "This is a debugging function, and not meant from general use."
117 (let ((pos (or position (chess-engine-position nil))))
118 (with-current-buffer (get-buffer-create "*scratch*")
119 (chess-ics1-draw pos t)
120 (funcall chess-ics1-popup-function))))
122 (provide 'chess-ics1)
124 ;;; chess-ics1.el ends here