]> code.delx.au - gnu-emacs-elpa/blob - chess-tutorial.el
bug fixes
[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
13 (defun chess-tutorial-knight-1 (game ignore event &rest args)
14 (if (eq event 'move)
15 (let ((position (chess-game-pos game)))
16 (if (null (chess-pos-search position ?p))
17 (chess-message 'congratulations)
18 (when (chess-search-position
19 position (car (chess-pos-search position ?N)) ?q)
20 (chess-game-run-hooks chess-module-game 'undo 1)
21 (chess-display-update nil)
22 (chess-error 'queen-would-take))))))
23
24 (defun chess-tutorial ()
25 (interactive)
26 (let* (chess-default-modules
27 (display (chess-create-display t)))
28 (with-current-buffer display
29 (chess-game-set-start-position
30 (chess-display-game nil)
31 (chess-fen-to-pos "8/3p1p/2p3p/4q/2p3p/3p1p/8/N w - -"))
32 (chess-game-add-hook (chess-display-game nil) 'chess-tutorial-knight-1)
33 (setq chess-pos-always-white t)
34 (chess-display-popup nil)
35 (chess-message 'knight-1-done))))
36
37 (provide 'chess-tutorial)
38
39 ;;; chess-tutorial.el ends here