]> code.delx.au - gnu-emacs-elpa/blob - chess-tutorial.el
*** no comment ***
[gnu-emacs-elpa] / chess-tutorial.el
1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2 ;;
3 ;; A special kind of display that merely autosaves the game
4 ;;
5
6 (require 'chess-game)
7
8 (chess-message-catalog 'english
9 '((queen-would-take . "The queen would take your knight!")
10 (congratulations . "Congratulations!")
11 (knight-1-done . "Goal: take all the pawns, without letting the queen take your knight")
12 (cannot-take-queen . "You cannot take the queen")))
13
14 (defun chess-tutorial-knight-1 (game ignore event &rest args)
15 (if (eq event 'move)
16 (let ((position (chess-game-pos game)))
17 (if (null (chess-pos-search position ?p))
18 (chess-message 'congratulations)
19 (cond
20 ((chess-search-position position
21 (car (chess-pos-search position ?N)) ?q)
22 (let ((chess-display-handling-event nil))
23 (chess-game-undo game 1))
24 (chess-error 'queen-would-take))
25 ((not (chess-pos-search position ?q))
26 (let ((chess-display-handling-event nil))
27 (chess-game-undo game 1))
28 (chess-error 'cannot-take-queen)))))))
29
30 (defun chess-tutorial ()
31 (interactive)
32 (let* (chess-default-modules
33 (display (chess-create-display t)))
34 (with-current-buffer display
35 (chess-module-set-leader nil)
36 (chess-game-set-start-position
37 (chess-display-game nil)
38 (chess-fen-to-pos "8/3p1p/2p3p/4q/2p3p/3p1p/8/N w - -"))
39 (chess-game-add-hook (chess-display-game nil) 'chess-tutorial-knight-1)
40 (setq chess-pos-always-white t)
41 (chess-display-popup nil)
42 (chess-message 'knight-1-done))))
43
44 (provide 'chess-tutorial)
45
46 ;;; chess-tutorial.el ends here