Mercurial > emacs
comparison lisp/play/gomoku.el @ 74155:8d99b6c54739
(gomoku-terminate-game, gomoku-human-takes-back, gomoku-prompt-for-move,
gomoku-human-plays, gomoku-offer-a-draw): Fix typos in output messages.
(gomoku-vector-length, gomoku-init-board): Fix typos in docstrings.
author | Juanma Barranquero <lekktu@gmail.com> |
---|---|
date | Fri, 24 Nov 2006 11:10:51 +0000 |
parents | 8eceefbbcde7 |
children | e3694f1cb928 f1d13e615070 |
comparison
equal
deleted
inserted
replaced
74154:d629c8e9985d | 74155:8d99b6c54739 |
---|---|
228 | 228 |
229 (defvar gomoku-board nil | 229 (defvar gomoku-board nil |
230 "Vector recording the actual state of the Gomoku board.") | 230 "Vector recording the actual state of the Gomoku board.") |
231 | 231 |
232 (defvar gomoku-vector-length nil | 232 (defvar gomoku-vector-length nil |
233 "Length of gomoku-board vector.") | 233 "Length of `gomoku-board' vector.") |
234 | 234 |
235 (defvar gomoku-draw-limit nil | 235 (defvar gomoku-draw-limit nil |
236 ;; This is usually set to 70% of the number of squares. | 236 ;; This is usually set to 70% of the number of squares. |
237 "After how many moves will Emacs offer a draw?") | 237 "After how many moves will Emacs offer a draw?") |
238 | 238 |
248 (defun gomoku-index-to-y (index) | 248 (defun gomoku-index-to-y (index) |
249 "Return corresponding y-coord of board INDEX." | 249 "Return corresponding y-coord of board INDEX." |
250 (/ index (1+ gomoku-board-width))) | 250 (/ index (1+ gomoku-board-width))) |
251 | 251 |
252 (defun gomoku-init-board () | 252 (defun gomoku-init-board () |
253 "Create the gomoku-board vector and fill it with initial values." | 253 "Create the `gomoku-board' vector and fill it with initial values." |
254 (setq gomoku-board (make-vector gomoku-vector-length 0)) | 254 (setq gomoku-board (make-vector gomoku-vector-length 0)) |
255 ;; Every square is 0 (i.e. empty) except padding squares: | 255 ;; Every square is 0 (i.e. empty) except padding squares: |
256 (let ((i 0) (ii (1- gomoku-vector-length))) | 256 (let ((i 0) (ii (1- gomoku-vector-length))) |
257 (while (<= i gomoku-board-width) ; The squares in [0..width] and in | 257 (while (<= i gomoku-board-width) ; The squares in [0..width] and in |
258 (aset gomoku-board i -1) ; [length - width - 1..length - 1] | 258 (aset gomoku-board i -1) ; [length - width - 1..length - 1] |
669 ((eq result 'emacs-won) | 669 ((eq result 'emacs-won) |
670 (setq gomoku-number-of-emacs-wins (1+ gomoku-number-of-emacs-wins)) | 670 (setq gomoku-number-of-emacs-wins (1+ gomoku-number-of-emacs-wins)) |
671 (cond ((< gomoku-number-of-moves 20) | 671 (cond ((< gomoku-number-of-moves 20) |
672 "This was a REALLY QUICK win.") | 672 "This was a REALLY QUICK win.") |
673 (gomoku-human-refused-draw | 673 (gomoku-human-refused-draw |
674 "I won... Too bad you refused my offer of a draw!") | 674 "I won... Too bad you refused my offer of a draw!") |
675 (gomoku-human-took-back | 675 (gomoku-human-took-back |
676 "I won... Taking moves back will not help you!") | 676 "I won... Taking moves back will not help you!") |
677 ((not gomoku-emacs-played-first) | 677 ((not gomoku-emacs-played-first) |
678 "I won... Playing first did not help you much!") | 678 "I won... Playing first did not help you much!") |
679 ((and (zerop gomoku-number-of-human-wins) | 679 ((and (zerop gomoku-number-of-human-wins) |
680 (zerop gomoku-number-of-draws) | 680 (zerop gomoku-number-of-draws) |
681 (> gomoku-number-of-emacs-wins 1)) | 681 (> gomoku-number-of-emacs-wins 1)) |
682 "I'm becoming tired of winning...") | 682 "I'm becoming tired of winning...") |
683 ("I won."))) | 683 ("I won."))) |
873 (gomoku-prompt-for-other-game)) | 873 (gomoku-prompt-for-other-game)) |
874 (t | 874 (t |
875 (let (square score) | 875 (let (square score) |
876 (setq square (gomoku-point-square)) | 876 (setq square (gomoku-point-square)) |
877 (cond ((null square) | 877 (cond ((null square) |
878 (error "Your point is not on a square. Retry!")) | 878 (error "Your point is not on a square. Retry!")) |
879 ((not (zerop (aref gomoku-board square))) | 879 ((not (zerop (aref gomoku-board square))) |
880 (error "Your point is not on a free square. Retry!")) | 880 (error "Your point is not on a free square. Retry!")) |
881 (t | 881 (t |
882 (setq score (aref gomoku-score-table square)) | 882 (setq score (aref gomoku-score-table square)) |
883 (gomoku-play-move square 1) | 883 (gomoku-play-move square 1) |
884 (cond ((and (>= score gomoku-loosing-threshold) | 884 (cond ((and (>= score gomoku-loosing-threshold) |
885 ;; Just testing SCORE > THRESHOLD is not enough for | 885 ;; Just testing SCORE > THRESHOLD is not enough for |
900 ((not gomoku-game-in-progress) | 900 ((not gomoku-game-in-progress) |
901 (message "Too late for taking back...") | 901 (message "Too late for taking back...") |
902 (sit-for 4) | 902 (sit-for 4) |
903 (gomoku-prompt-for-other-game)) | 903 (gomoku-prompt-for-other-game)) |
904 ((zerop gomoku-number-of-human-moves) | 904 ((zerop gomoku-number-of-human-moves) |
905 (message "You have not played yet... Your move?")) | 905 (message "You have not played yet... Your move?")) |
906 (t | 906 (t |
907 (message "One moment, please...") | 907 (message "One moment, please...") |
908 ;; It is possible for the user to let Emacs play several consecutive | 908 ;; It is possible for the user to let Emacs play several consecutive |
909 ;; moves, so that the best way to know when to stop taking back moves is | 909 ;; moves, so that the best way to know when to stop taking back moves is |
910 ;; to count the number of human moves: | 910 ;; to count the number of human moves: |
935 ;;; | 935 ;;; |
936 | 936 |
937 (defun gomoku-prompt-for-move () | 937 (defun gomoku-prompt-for-move () |
938 "Display a message asking for Human's move." | 938 "Display a message asking for Human's move." |
939 (message (if (zerop gomoku-number-of-human-moves) | 939 (message (if (zerop gomoku-number-of-human-moves) |
940 "Your move? (move to a free square and hit X, RET ...)" | 940 "Your move? (Move to a free square and hit X, RET ...)" |
941 "Your move?")) | 941 "Your move?")) |
942 ;; This may seem silly, but if one omits the following line (or a similar | 942 ;; This may seem silly, but if one omits the following line (or a similar |
943 ;; one), the cursor may very well go to some place where POINT is not. | 943 ;; one), the cursor may very well go to some place where POINT is not. |
944 (save-excursion (set-buffer (other-buffer)))) | 944 (save-excursion (set-buffer (other-buffer)))) |
945 | 945 |
949 (gomoku gomoku-board-width gomoku-board-height) | 949 (gomoku gomoku-board-width gomoku-board-height) |
950 (error "Chicken!"))) | 950 (error "Chicken!"))) |
951 | 951 |
952 (defun gomoku-offer-a-draw () | 952 (defun gomoku-offer-a-draw () |
953 "Offer a draw and return t if Human accepted it." | 953 "Offer a draw and return t if Human accepted it." |
954 (or (y-or-n-p "I offer you a draw. Do you accept it? ") | 954 (or (y-or-n-p "I offer you a draw. Do you accept it? ") |
955 (not (setq gomoku-human-refused-draw t)))) | 955 (not (setq gomoku-human-refused-draw t)))) |
956 | 956 |
957 ;;; | 957 ;;; |
958 ;;; DISPLAYING THE BOARD. | 958 ;;; DISPLAYING THE BOARD. |
959 ;;; | 959 ;;; |