annotate lisp/play/landmark.el @ 112427:bc872de587fa

* play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672). (lm): Rename to landmark. (lm-test-run): Rename to landmark-test-run.
author Chong Yidong <cyd@stupidchicken.com>
date Sat, 22 Jan 2011 15:12:51 -0500
parents 417b1e4d63cd
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
22388
2d0bece94ee7 Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 21363
diff changeset
1 ;;; landmark.el --- neural-network robot that learns landmarks
18290
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
2
104848
1382a0cd8022 Remove leading * from defcustom and defface docs.
Glenn Morris <rgm@gnu.org>
parents: 104576
diff changeset
3 ;; Copyright (C) 1996, 1997, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
112218
376148b31b5e Add 2011 to FSF/AIST copyright years.
Glenn Morris <rgm@gnu.org>
parents: 111257
diff changeset
4 ;; 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5
38455
802c948ddb3a *** empty log message ***
Pavel Janík <Pavel@Janik.cz>
parents: 38425
diff changeset
6 ;; Author: Terrence Brannon (was: <brannon@rana.usc.edu>)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7 ;; Created: December 16, 1996 - first release to usenet
104576
4b8f024e6993 Kevin Ryde <user42 at zip.com.au>
Glenn Morris <rgm@gnu.org>
parents: 104390
diff changeset
8 ;; Keywords: games, gomoku, neural network, adaptive search, chemotaxis
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9
18290
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
10 ;;;_* Usage
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
11 ;;; Just type
71625
22433275348d Comment munging; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 69895
diff changeset
12 ;;; M-x eval-buffer
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
13 ;;; M-x landmark-test-run
18290
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
14
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
15
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 ;; This file is part of GNU Emacs.
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17
94675
949bd6ad1ba4 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
18 ;; GNU Emacs is free software: you can redistribute it and/or modify
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 ;; it under the terms of the GNU General Public License as published by
94675
949bd6ad1ba4 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
20 ;; the Free Software Foundation, either version 3 of the License, or
949bd6ad1ba4 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
21 ;; (at your option) any later version.
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23 ;; GNU Emacs is distributed in the hope that it will be useful,
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26 ;; GNU General Public License for more details.
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 ;; You should have received a copy of the GNU General Public License
94675
949bd6ad1ba4 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
29 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31
38425
c6e12c6b1498 Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 38076
diff changeset
32 ;;; Commentary:
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
33 ;; Landmark is a relatively non-participatory game in which a robot
111206
56f4300fbd9f * lisp/play/landmark.el: Adjust commenting convention.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110909
diff changeset
34 ;; attempts to maneuver towards a tree at the center of the window
56f4300fbd9f * lisp/play/landmark.el: Adjust commenting convention.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110909
diff changeset
35 ;; based on unique olfactory cues from each of the 4 directions. If
56f4300fbd9f * lisp/play/landmark.el: Adjust commenting convention.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110909
diff changeset
36 ;; the smell of the tree increases, then the weights in the robot's
56f4300fbd9f * lisp/play/landmark.el: Adjust commenting convention.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110909
diff changeset
37 ;; brain are adjusted to encourage this odor-driven behavior in the
56f4300fbd9f * lisp/play/landmark.el: Adjust commenting convention.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110909
diff changeset
38 ;; future. If the smell of the tree decreases, the robots weights are
56f4300fbd9f * lisp/play/landmark.el: Adjust commenting convention.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110909
diff changeset
39 ;; adjusted to discourage a correct move.
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40
111206
56f4300fbd9f * lisp/play/landmark.el: Adjust commenting convention.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110909
diff changeset
41 ;; In laymen's terms, the search space is initially flat. The point
56f4300fbd9f * lisp/play/landmark.el: Adjust commenting convention.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110909
diff changeset
42 ;; of training is to "turn up the edges of the search space" so that
56f4300fbd9f * lisp/play/landmark.el: Adjust commenting convention.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110909
diff changeset
43 ;; the robot rolls toward the center.
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44
111206
56f4300fbd9f * lisp/play/landmark.el: Adjust commenting convention.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110909
diff changeset
45 ;; Further, do not become alarmed if the robot appears to oscillate
56f4300fbd9f * lisp/play/landmark.el: Adjust commenting convention.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110909
diff changeset
46 ;; back and forth between two or a few positions. This simply means
56f4300fbd9f * lisp/play/landmark.el: Adjust commenting convention.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110909
diff changeset
47 ;; it is currently caught in a local minimum and is doing its best to
56f4300fbd9f * lisp/play/landmark.el: Adjust commenting convention.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110909
diff changeset
48 ;; work its way out.
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49
111206
56f4300fbd9f * lisp/play/landmark.el: Adjust commenting convention.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110909
diff changeset
50 ;; The version of this program as described has a small problem. a
56f4300fbd9f * lisp/play/landmark.el: Adjust commenting convention.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110909
diff changeset
51 ;; move in a net direction can produce gross credit assignment. for
56f4300fbd9f * lisp/play/landmark.el: Adjust commenting convention.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110909
diff changeset
52 ;; example, if moving south will produce positive payoff, then, if in
56f4300fbd9f * lisp/play/landmark.el: Adjust commenting convention.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110909
diff changeset
53 ;; a single move, one moves east,west and south, then both east and
56f4300fbd9f * lisp/play/landmark.el: Adjust commenting convention.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110909
diff changeset
54 ;; west will be improved when they shouldn't
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
56 ;; Many thanks to Yuri Pryadkin <yuri@rana.usc.edu> for this
111206
56f4300fbd9f * lisp/play/landmark.el: Adjust commenting convention.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110909
diff changeset
57 ;; concise problem description.
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 ;;;_* Require
30888
e559f0aa6b2d Don't quote lambda.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 30542
diff changeset
60 (eval-when-compile (require 'cl))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 ;;;_* From Gomoku
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63
38425
c6e12c6b1498 Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 38076
diff changeset
64 ;;; Code:
c6e12c6b1498 Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 38076
diff changeset
65
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
66 (defgroup landmark nil
21363
f1fc193b6958 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 18951
diff changeset
67 "Neural-network robot that learns landmarks."
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
68 :prefix "landmark-"
21363
f1fc193b6958 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 18951
diff changeset
69 :group 'games)
f1fc193b6958 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 18951
diff changeset
70
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 ;;;_ + THE BOARD.
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 ;; The board is a rectangular grid. We code empty squares with 0, X's with 1
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 ;; and O's with 6. The rectangle is recorded in a one dimensional vector
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 ;; containing padding squares (coded with -1). These squares allow us to
74157
e56f52b00e2d Space/tab mixup.
Juanma Barranquero <lekktu@gmail.com>
parents: 71625
diff changeset
76 ;; detect when we are trying to move out of the board. We denote a square by
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 ;; its (X,Y) coords, or by the INDEX corresponding to them in the vector. The
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
78 ;; leftmost topmost square has coords (1,1) and index landmark-board-width + 2.
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79 ;; Similarly, vectors between squares may be given by two DX, DY coords or by
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80 ;; one DEPL (the difference between indexes).
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
82 (defvar landmark-board-width nil
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
83 "Number of columns on the Landmark board.")
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
84 (defvar landmark-board-height nil
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
85 "Number of lines on the Landmark board.")
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
87 (defvar landmark-board nil
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
88 "Vector recording the actual state of the Landmark board.")
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
90 (defvar landmark-vector-length nil
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
91 "Length of landmark-board vector.")
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
93 (defvar landmark-draw-limit nil
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94 ;; This is usually set to 70% of the number of squares.
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95 "After how many moves will Emacs offer a draw?")
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
97 (defvar landmark-cx 0
18290
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
98 "This is the x coordinate of the center of the board.")
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
99
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
100 (defvar landmark-cy 0
18290
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
101 "This is the y coordinate of the center of the board.")
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
102
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
103 (defvar landmark-m 0
18290
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
104 "This is the x dimension of the playing board.")
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
105
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
106 (defvar landmark-n 0
18290
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
107 "This is the y dimension of the playing board.")
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
108
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
109
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
110 (defun landmark-xy-to-index (x y)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
111 "Translate X, Y cartesian coords into the corresponding board index."
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
112 (+ (* y landmark-board-width) x y))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
114 (defun landmark-index-to-x (index)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115 "Return corresponding x-coord of board INDEX."
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
116 (% index (1+ landmark-board-width)))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
118 (defun landmark-index-to-y (index)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119 "Return corresponding y-coord of board INDEX."
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
120 (/ index (1+ landmark-board-width)))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
122 (defun landmark-init-board ()
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
123 "Create the landmark-board vector and fill it with initial values."
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
124 (setq landmark-board (make-vector landmark-vector-length 0))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125 ;; Every square is 0 (i.e. empty) except padding squares:
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
126 (let ((i 0) (ii (1- landmark-vector-length)))
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
127 (while (<= i landmark-board-width) ; The squares in [0..width] and in
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
128 (aset landmark-board i -1) ; [length - width - 1..length - 1]
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
129 (aset landmark-board ii -1) ; are padding squares.
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
130 (setq i (1+ i)
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131 ii (1- ii))))
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132 (let ((i 0))
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
133 (while (< i landmark-vector-length)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
134 (aset landmark-board i -1) ; and also all k*(width+1)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
135 (setq i (+ i landmark-board-width 1)))))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136
18290
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
137 ;;;_ + DISPLAYING THE BOARD.
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
138
18290
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
139 ;; You may change these values if you have a small screen or if the squares
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
140 ;; look rectangular, but spacings SHOULD be at least 2 (MUST BE at least 1).
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
142 (defconst landmark-square-width 2
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
143 "*Horizontal spacing between squares on the Landmark board.")
18290
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
144
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
145 (defconst landmark-square-height 1
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
146 "*Vertical spacing between squares on the Landmark board.")
18290
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
147
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
148 (defconst landmark-x-offset 3
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
149 "*Number of columns between the Landmark board and the side of the window.")
18290
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
150
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
151 (defconst landmark-y-offset 1
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
152 "*Number of lines between the Landmark board and the top of the window.")
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
155 ;;;_ + LANDMARK MODE AND KEYMAP.
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
156
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
157 (defcustom landmark-mode-hook nil
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
158 "If non-nil, its value is called on entry to Landmark mode."
21363
f1fc193b6958 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 18951
diff changeset
159 :type 'hook
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
160 :group 'landmark)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
162 (defvar landmark-mode-map
110909
cc035ccb9275 Declare and define in one step various mode maps.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 106815
diff changeset
163 (let ((map (make-sparse-keymap)))
cc035ccb9275 Declare and define in one step various mode maps.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 106815
diff changeset
164 ;; Key bindings for cursor motion.
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
165 (define-key map "y" 'landmark-move-nw) ; y
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
166 (define-key map "u" 'landmark-move-ne) ; u
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
167 (define-key map "b" 'landmark-move-sw) ; b
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
168 (define-key map "n" 'landmark-move-se) ; n
110909
cc035ccb9275 Declare and define in one step various mode maps.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 106815
diff changeset
169 (define-key map "h" 'backward-char) ; h
cc035ccb9275 Declare and define in one step various mode maps.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 106815
diff changeset
170 (define-key map "l" 'forward-char) ; l
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
171 (define-key map "j" 'landmark-move-down) ; j
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
172 (define-key map "k" 'landmark-move-up) ; k
110909
cc035ccb9275 Declare and define in one step various mode maps.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 106815
diff changeset
173
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
174 (define-key map [kp-7] 'landmark-move-nw)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
175 (define-key map [kp-9] 'landmark-move-ne)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
176 (define-key map [kp-1] 'landmark-move-sw)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
177 (define-key map [kp-3] 'landmark-move-se)
110909
cc035ccb9275 Declare and define in one step various mode maps.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 106815
diff changeset
178 (define-key map [kp-4] 'backward-char)
cc035ccb9275 Declare and define in one step various mode maps.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 106815
diff changeset
179 (define-key map [kp-6] 'forward-char)
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
180 (define-key map [kp-2] 'landmark-move-down)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
181 (define-key map [kp-8] 'landmark-move-up)
110909
cc035ccb9275 Declare and define in one step various mode maps.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 106815
diff changeset
182
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
183 (define-key map "\C-n" 'landmark-move-down) ; C-n
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
184 (define-key map "\C-p" 'landmark-move-up) ; C-p
110909
cc035ccb9275 Declare and define in one step various mode maps.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 106815
diff changeset
185
cc035ccb9275 Declare and define in one step various mode maps.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 106815
diff changeset
186 ;; Key bindings for entering Human moves.
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
187 (define-key map "X" 'landmark-human-plays) ; X
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
188 (define-key map "x" 'landmark-human-plays) ; x
110909
cc035ccb9275 Declare and define in one step various mode maps.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 106815
diff changeset
189
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
190 (define-key map " " 'landmark-start-robot) ; SPC
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
191 (define-key map [down-mouse-1] 'landmark-start-robot)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
192 (define-key map [drag-mouse-1] 'landmark-click)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
193 (define-key map [mouse-1] 'landmark-click)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
194 (define-key map [down-mouse-2] 'landmark-click)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
195 (define-key map [mouse-2] 'landmark-mouse-play)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
196 (define-key map [drag-mouse-2] 'landmark-mouse-play)
110909
cc035ccb9275 Declare and define in one step various mode maps.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 106815
diff changeset
197
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
198 (define-key map [remap previous-line] 'landmark-move-up)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
199 (define-key map [remap next-line] 'landmark-move-down)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
200 (define-key map [remap beginning-of-line] 'landmark-beginning-of-line)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
201 (define-key map [remap end-of-line] 'landmark-end-of-line)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
202 (define-key map [remap undo] 'landmark-human-takes-back)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
203 (define-key map [remap advertised-undo] 'landmark-human-takes-back)
110909
cc035ccb9275 Declare and define in one step various mode maps.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 106815
diff changeset
204 map)
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
205 "Local keymap to use in Landmark mode.")
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
208
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
209 (defvar landmark-emacs-won ()
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210 "*For making font-lock use the winner's face for the line.")
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
211
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
212 (defface landmark-font-lock-face-O '((((class color)) :foreground "red")
69895
215057e97d56 (lm-font-lock-face-O, lm-font-lock-face-X): Make them faces.
Richard M. Stallman <rms@gnu.org>
parents: 68866
diff changeset
213 (t :weight bold))
104848
1382a0cd8022 Remove leading * from defcustom and defface docs.
Glenn Morris <rgm@gnu.org>
parents: 104576
diff changeset
214 "Face to use for Emacs' O."
69895
215057e97d56 (lm-font-lock-face-O, lm-font-lock-face-X): Make them faces.
Richard M. Stallman <rms@gnu.org>
parents: 68866
diff changeset
215 :version "22.1"
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
216 :group 'landmark)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
217
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
218 (defface landmark-font-lock-face-X '((((class color)) :foreground "green")
69895
215057e97d56 (lm-font-lock-face-O, lm-font-lock-face-X): Make them faces.
Richard M. Stallman <rms@gnu.org>
parents: 68866
diff changeset
219 (t :weight bold))
104848
1382a0cd8022 Remove leading * from defcustom and defface docs.
Glenn Morris <rgm@gnu.org>
parents: 104576
diff changeset
220 "Face to use for your X."
69895
215057e97d56 (lm-font-lock-face-O, lm-font-lock-face-X): Make them faces.
Richard M. Stallman <rms@gnu.org>
parents: 68866
diff changeset
221 :version "22.1"
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
222 :group 'landmark)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
223
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
224 (defvar landmark-font-lock-keywords
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
225 '(("O" . 'landmark-font-lock-face-O)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
226 ("X" . 'landmark-font-lock-face-X)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
227 ("[-|/\\]" 0 (if landmark-emacs-won
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
228 'landmark-font-lock-face-O
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
229 'landmark-font-lock-face-X)))
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
230 "*Font lock rules for Landmark.")
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
231
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
232 (put 'landmark-mode 'front-sticky
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
233 (put 'landmark-mode 'rear-nonsticky '(intangible)))
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
234 (put 'landmark-mode 'intangible 1)
41317
a33250d752d4 Mark lm-mode as special. Suggested by Klaus Straubinger <ksnetz@arcor.de>
Eli Zaretskii <eliz@gnu.org>
parents: 39866
diff changeset
235 ;; This one is for when they set view-read-only to t: Landmark cannot
a33250d752d4 Mark lm-mode as special. Suggested by Klaus Straubinger <ksnetz@arcor.de>
Eli Zaretskii <eliz@gnu.org>
parents: 39866
diff changeset
236 ;; allow View Mode to be activated in its buffer.
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
237 (put 'landmark-mode 'mode-class 'special)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
238
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
239 (defun landmark-mode ()
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
240 "Major mode for playing Landmark against Emacs.
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
241 You and Emacs play in turn by marking a free square. You mark it with X
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
242 and Emacs marks it with O. The winner is the first to get five contiguous
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
243 marks horizontally, vertically or in diagonal.
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
244
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
245 You play by moving the cursor over the square you choose and hitting \\[landmark-human-plays].
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
246
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
247 Other useful commands:
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
248 \\{landmark-mode-map}
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
249 Entry to this mode calls the value of `landmark-mode-hook' if that value
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
250 is non-nil. One interesting value is `turn-on-font-lock'."
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
251 (interactive)
62770
93e71f3dcd14 * play/5x5.el (5x5-mode):
Lute Kamstra <lute@gnu.org>
parents: 62249
diff changeset
252 (kill-all-local-variables)
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
253 (setq major-mode 'landmark-mode
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
254 mode-name "Landmark")
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
255 (landmark-display-statistics)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
256 (use-local-map landmark-mode-map)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
257 (make-local-variable 'font-lock-defaults)
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
258 (setq font-lock-defaults '(landmark-font-lock-keywords t)
111257
516f3d80dac6 Replace some inappropriate uses of toggle-read-only. (Bug#7292)
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
259 buffer-read-only t)
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
260 (run-mode-hooks 'landmark-mode-hook))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
261
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
262
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
263 ;;;_ + THE SCORE TABLE.
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
264
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
265
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
266 ;; Every (free) square has a score associated to it, recorded in the
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
267 ;; LANDMARK-SCORE-TABLE vector. The program always plays in the square having
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
268 ;; the highest score.
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
269
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
270 (defvar landmark-score-table nil
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
271 "Vector recording the actual score of the free squares.")
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
272
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
273
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
274 ;; The key point point about the algorithm is that, rather than considering
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
275 ;; the board as just a set of squares, we prefer to see it as a "space" of
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
276 ;; internested 5-tuples of contiguous squares (called qtuples).
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
277 ;;
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
278 ;; The aim of the program is to fill one qtuple with its O's while preventing
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
279 ;; you from filling another one with your X's. To that effect, it computes a
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
280 ;; score for every qtuple, with better qtuples having better scores. Of
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
281 ;; course, the score of a qtuple (taken in isolation) is just determined by
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
282 ;; its contents as a set, i.e. not considering the order of its elements. The
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
283 ;; highest score is given to the "OOOO" qtuples because playing in such a
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
284 ;; qtuple is winning the game. Just after this comes the "XXXX" qtuple because
111331
f3a306e9418e landmark: you lose.
Glenn Morris <rgm@gnu.org>
parents: 111262
diff changeset
285 ;; not playing in it is just losing the game, and so on. Note that a
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
286 ;; "polluted" qtuple, i.e. one containing at least one X and at least one O,
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
287 ;; has score zero because there is no more any point in playing in it, from
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
288 ;; both an attacking and a defending point of view.
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
289 ;;
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
290 ;; Given the score of every qtuple, the score of a given free square on the
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
291 ;; board is just the sum of the scores of all the qtuples to which it belongs,
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
292 ;; because playing in that square is playing in all its containing qtuples at
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
293 ;; once. And it is that function which takes into account the internesting of
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
294 ;; the qtuples.
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
295 ;;
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
296 ;; This algorithm is rather simple but anyway it gives a not so dumb level of
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
297 ;; play. It easily extends to "n-dimensional Landmark", where a win should not
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
298 ;; be obtained with as few as 5 contiguous marks: 6 or 7 (depending on n !)
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
299 ;; should be preferred.
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
300
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
301
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
302 ;; Here are the scores of the nine "non-polluted" configurations. Tuning
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
303 ;; these values will change (hopefully improve) the strength of the program
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
304 ;; and may change its style (rather aggressive here).
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
305
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
306 (defconst landmark-nil-score 7 "Score of an empty qtuple.")
111206
56f4300fbd9f * lisp/play/landmark.el: Adjust commenting convention.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110909
diff changeset
307
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
308 (defconst landmark-score-trans-table
111206
56f4300fbd9f * lisp/play/landmark.el: Adjust commenting convention.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110909
diff changeset
309 (let ((Xscore 15) ; Score of a qtuple containing one X.
56f4300fbd9f * lisp/play/landmark.el: Adjust commenting convention.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110909
diff changeset
310 (XXscore 400) ; Score of a qtuple containing two X's.
56f4300fbd9f * lisp/play/landmark.el: Adjust commenting convention.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110909
diff changeset
311 (XXXscore 1800) ; Score of a qtuple containing three X's.
56f4300fbd9f * lisp/play/landmark.el: Adjust commenting convention.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110909
diff changeset
312 (XXXXscore 100000) ; Score of a qtuple containing four X's.
56f4300fbd9f * lisp/play/landmark.el: Adjust commenting convention.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110909
diff changeset
313 (Oscore 35) ; Score of a qtuple containing one O.
56f4300fbd9f * lisp/play/landmark.el: Adjust commenting convention.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110909
diff changeset
314 (OOscore 800) ; Score of a qtuple containing two O's.
56f4300fbd9f * lisp/play/landmark.el: Adjust commenting convention.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110909
diff changeset
315 (OOOscore 15000) ; Score of a qtuple containing three O's.
56f4300fbd9f * lisp/play/landmark.el: Adjust commenting convention.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110909
diff changeset
316 (OOOOscore 800000)) ; Score of a qtuple containing four O's.
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
317
111206
56f4300fbd9f * lisp/play/landmark.el: Adjust commenting convention.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110909
diff changeset
318 ;; These values are not just random: if, given the following situation:
56f4300fbd9f * lisp/play/landmark.el: Adjust commenting convention.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110909
diff changeset
319 ;;
56f4300fbd9f * lisp/play/landmark.el: Adjust commenting convention.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110909
diff changeset
320 ;; . . . . . . . O .
56f4300fbd9f * lisp/play/landmark.el: Adjust commenting convention.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110909
diff changeset
321 ;; . X X a . . . X .
56f4300fbd9f * lisp/play/landmark.el: Adjust commenting convention.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110909
diff changeset
322 ;; . . . X . . . X .
56f4300fbd9f * lisp/play/landmark.el: Adjust commenting convention.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110909
diff changeset
323 ;; . . . X . . . X .
56f4300fbd9f * lisp/play/landmark.el: Adjust commenting convention.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110909
diff changeset
324 ;; . . . . . . . b .
56f4300fbd9f * lisp/play/landmark.el: Adjust commenting convention.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110909
diff changeset
325 ;;
56f4300fbd9f * lisp/play/landmark.el: Adjust commenting convention.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110909
diff changeset
326 ;; you want Emacs to play in "a" and not in "b", then the parameters must
56f4300fbd9f * lisp/play/landmark.el: Adjust commenting convention.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110909
diff changeset
327 ;; satisfy the inequality:
56f4300fbd9f * lisp/play/landmark.el: Adjust commenting convention.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110909
diff changeset
328 ;;
56f4300fbd9f * lisp/play/landmark.el: Adjust commenting convention.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110909
diff changeset
329 ;; 6 * XXscore > XXXscore + XXscore
56f4300fbd9f * lisp/play/landmark.el: Adjust commenting convention.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110909
diff changeset
330 ;;
56f4300fbd9f * lisp/play/landmark.el: Adjust commenting convention.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110909
diff changeset
331 ;; because "a" mainly belongs to six "XX" qtuples (the others are less
56f4300fbd9f * lisp/play/landmark.el: Adjust commenting convention.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110909
diff changeset
332 ;; important) while "b" belongs to one "XXX" and one "XX" qtuples.
56f4300fbd9f * lisp/play/landmark.el: Adjust commenting convention.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110909
diff changeset
333 ;; Other conditions are required to obtain sensible moves, but the
56f4300fbd9f * lisp/play/landmark.el: Adjust commenting convention.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110909
diff changeset
334 ;; previous example should illustrate the point. If you manage to
56f4300fbd9f * lisp/play/landmark.el: Adjust commenting convention.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110909
diff changeset
335 ;; improve on these values, please send me a note. Thanks.
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
336
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
337
111206
56f4300fbd9f * lisp/play/landmark.el: Adjust commenting convention.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110909
diff changeset
338 ;; As we chose values 0, 1 and 6 to denote empty, X and O squares,
56f4300fbd9f * lisp/play/landmark.el: Adjust commenting convention.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110909
diff changeset
339 ;; the contents of a qtuple are uniquely determined by the sum of
56f4300fbd9f * lisp/play/landmark.el: Adjust commenting convention.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110909
diff changeset
340 ;; its elements and we just have to set up a translation table.
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
341 (vector landmark-nil-score Xscore XXscore XXXscore XXXXscore 0
111206
56f4300fbd9f * lisp/play/landmark.el: Adjust commenting convention.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110909
diff changeset
342 Oscore 0 0 0 0 0
56f4300fbd9f * lisp/play/landmark.el: Adjust commenting convention.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110909
diff changeset
343 OOscore 0 0 0 0 0
56f4300fbd9f * lisp/play/landmark.el: Adjust commenting convention.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110909
diff changeset
344 OOOscore 0 0 0 0 0
56f4300fbd9f * lisp/play/landmark.el: Adjust commenting convention.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110909
diff changeset
345 OOOOscore 0 0 0 0 0
56f4300fbd9f * lisp/play/landmark.el: Adjust commenting convention.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110909
diff changeset
346 0))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
347 "Vector associating qtuple contents to their score.")
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
348
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
349
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
350 ;; If you do not modify drastically the previous constants, the only way for a
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
351 ;; square to have a score higher than OOOOscore is to belong to a "OOOO"
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
352 ;; qtuple, thus to be a winning move. Similarly, the only way for a square to
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
353 ;; have a score between XXXXscore and OOOOscore is to belong to a "XXXX"
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
354 ;; qtuple. We may use these considerations to detect when a given move is
111331
f3a306e9418e landmark: you lose.
Glenn Morris <rgm@gnu.org>
parents: 111262
diff changeset
355 ;; winning or losing.
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
356
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
357 (defconst landmark-winning-threshold
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
358 (aref landmark-score-trans-table (+ 6 6 6 6)) ;; OOOOscore
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
359 "Threshold score beyond which an Emacs move is winning.")
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
360
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
361 (defconst landmark-losing-threshold
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
362 (aref landmark-score-trans-table (+ 1 1 1 1)) ;; XXXXscore
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
363 "Threshold score beyond which a human move is winning.")
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
364
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
365
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
366 (defun landmark-strongest-square ()
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
367 "Compute index of free square with highest score, or nil if none."
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
368 ;; We just have to loop other all squares. However there are two problems:
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
369 ;; 1/ The SCORE-TABLE only gives correct scores to free squares. To speed
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
370 ;; up future searches, we set the score of padding or occupied squares
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
371 ;; to -1 whenever we meet them.
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
372 ;; 2/ We want to choose randomly between equally good moves.
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
373 (let ((score-max 0)
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
374 (count 0) ; Number of equally good moves
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
375 (square (landmark-xy-to-index 1 1)) ; First square
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
376 (end (landmark-xy-to-index landmark-board-width landmark-board-height))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
377 best-square score)
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
378 (while (<= square end)
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
379 (cond
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
380 ;; If score is lower (i.e. most of the time), skip to next:
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
381 ((< (aref landmark-score-table square) score-max))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
382 ;; If score is better, beware of non free squares:
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
383 ((> (setq score (aref landmark-score-table square)) score-max)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
384 (if (zerop (aref landmark-board square)) ; is it free ?
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
385 (setq count 1 ; yes: take it !
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
386 best-square square
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
387 score-max score)
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
388 (aset landmark-score-table square -1))) ; no: kill it !
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
389 ;; If score is equally good, choose randomly. But first check freeness:
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
390 ((not (zerop (aref landmark-board square)))
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
391 (aset landmark-score-table square -1))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
392 ((zerop (random (setq count (1+ count))))
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
393 (setq best-square square
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
394 score-max score)))
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
395 (setq square (1+ square))) ; try next square
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
396 best-square))
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
397
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
398 ;;;_ - INITIALIZING THE SCORE TABLE.
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
399
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
400 ;; At initialization the board is empty so that every qtuple amounts for
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
401 ;; nil-score. Therefore, the score of any square is nil-score times the number
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
402 ;; of qtuples that pass through it. This number is 3 in a corner and 20 if you
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
403 ;; are sufficiently far from the sides. As computing the number is time
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
404 ;; consuming, we initialize every square with 20*nil-score and then only
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
405 ;; consider squares at less than 5 squares from one side. We speed this up by
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
406 ;; taking symmetry into account.
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
407 ;; Also, as it is likely that successive games will be played on a board with
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
408 ;; same size, it is a good idea to save the initial SCORE-TABLE configuration.
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
409
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
410 (defvar landmark-saved-score-table nil
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
411 "Recorded initial value of previous score table.")
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
412
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
413 (defvar landmark-saved-board-width nil
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
414 "Recorded value of previous board width.")
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
415
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
416 (defvar landmark-saved-board-height nil
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
417 "Recorded value of previous board height.")
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
418
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
419
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
420 (defun landmark-init-score-table ()
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
421 "Create the score table vector and fill it with initial values."
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
422 (if (and landmark-saved-score-table ; Has it been stored last time ?
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
423 (= landmark-board-width landmark-saved-board-width)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
424 (= landmark-board-height landmark-saved-board-height))
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
425 (setq landmark-score-table (copy-sequence landmark-saved-score-table))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
426 ;; No, compute it:
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
427 (setq landmark-score-table
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
428 (make-vector landmark-vector-length (* 20 landmark-nil-score)))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
429 (let (i j maxi maxj maxi2 maxj2)
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
430 (setq maxi (/ (1+ landmark-board-width) 2)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
431 maxj (/ (1+ landmark-board-height) 2)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
432 maxi2 (min 4 maxi)
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
433 maxj2 (min 4 maxj))
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
434 ;; We took symmetry into account and could use it more if the board
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
435 ;; would have been square and not rectangular !
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
436 ;; In our case we deal with all (i,j) in the set [1..maxi2]*[1..maxj] U
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
437 ;; [maxi2+1..maxi]*[1..maxj2]. Maxi2 and maxj2 are used because the
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
438 ;; board may well be less than 8 by 8 !
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
439 (setq i 1)
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
440 (while (<= i maxi2)
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
441 (setq j 1)
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
442 (while (<= j maxj)
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
443 (landmark-init-square-score i j)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
444 (setq j (1+ j)))
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
445 (setq i (1+ i)))
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
446 (while (<= i maxi)
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
447 (setq j 1)
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
448 (while (<= j maxj2)
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
449 (landmark-init-square-score i j)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
450 (setq j (1+ j)))
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
451 (setq i (1+ i))))
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
452 (setq landmark-saved-score-table (copy-sequence landmark-score-table)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
453 landmark-saved-board-width landmark-board-width
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
454 landmark-saved-board-height landmark-board-height)))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
455
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
456 (defun landmark-nb-qtuples (i j)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
457 "Return the number of qtuples containing square I,J."
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
458 ;; This function is complicated because we have to deal
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
459 ;; with ugly cases like 3 by 6 boards, but it works.
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
460 ;; If you have a simpler (and correct) solution, send it to me. Thanks !
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
461 (let ((left (min 4 (1- i)))
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
462 (right (min 4 (- landmark-board-width i)))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
463 (up (min 4 (1- j)))
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
464 (down (min 4 (- landmark-board-height j))))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
465 (+ -12
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
466 (min (max (+ left right) 3) 8)
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
467 (min (max (+ up down) 3) 8)
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
468 (min (max (+ (min left up) (min right down)) 3) 8)
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
469 (min (max (+ (min right up) (min left down)) 3) 8))))
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
470
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
471 (defun landmark-init-square-score (i j)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
472 "Give initial score to square I,J and to its mirror images."
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
473 (let ((ii (1+ (- landmark-board-width i)))
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
474 (jj (1+ (- landmark-board-height j)))
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
475 (sc (* (landmark-nb-qtuples i j) (aref landmark-score-trans-table 0))))
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
476 (aset landmark-score-table (landmark-xy-to-index i j) sc)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
477 (aset landmark-score-table (landmark-xy-to-index ii j) sc)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
478 (aset landmark-score-table (landmark-xy-to-index i jj) sc)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
479 (aset landmark-score-table (landmark-xy-to-index ii jj) sc)))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
480 ;;;_ - MAINTAINING THE SCORE TABLE.
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
481
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
482
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
483 ;; We do not provide functions for computing the SCORE-TABLE given the
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
484 ;; contents of the BOARD. This would involve heavy nested loops, with time
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
485 ;; proportional to the size of the board. It is better to update the
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
486 ;; SCORE-TABLE after each move. Updating needs not modify more than 36
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
487 ;; squares: it is done in constant time.
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
488
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
489 (defun landmark-update-score-table (square dval)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
490 "Update score table after SQUARE received a DVAL increment."
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
491 ;; The board has already been updated when this function is called.
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
492 ;; Updating scores is done by looking for qtuples boundaries in all four
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
493 ;; directions and then calling update-score-in-direction.
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
494 ;; Finally all squares received the right increment, and then are up to
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
495 ;; date, except possibly for SQUARE itself if we are taking a move back for
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
496 ;; its score had been set to -1 at the time.
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
497 (let* ((x (landmark-index-to-x square))
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
498 (y (landmark-index-to-y square))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
499 (imin (max -4 (- 1 x)))
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
500 (jmin (max -4 (- 1 y)))
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
501 (imax (min 0 (- landmark-board-width x 4)))
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
502 (jmax (min 0 (- landmark-board-height y 4))))
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
503 (landmark-update-score-in-direction imin imax
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
504 square 1 0 dval)
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
505 (landmark-update-score-in-direction jmin jmax
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
506 square 0 1 dval)
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
507 (landmark-update-score-in-direction (max imin jmin) (min imax jmax)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
508 square 1 1 dval)
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
509 (landmark-update-score-in-direction (max (- 1 y) -4
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
510 (- x landmark-board-width))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
511 (min 0 (- x 5)
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
512 (- landmark-board-height y 4))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
513 square -1 1 dval)))
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
514
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
515 (defun landmark-update-score-in-direction (left right square dx dy dval)
18290
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
516 "Update scores for all squares in the qtuples in range.
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
517 That is, those between the LEFTth square and the RIGHTth after SQUARE,
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
518 along the DX, DY direction, considering that DVAL has been added on SQUARE."
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
519 ;; We always have LEFT <= 0, RIGHT <= 0 and DEPL > 0 but we may very well
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
520 ;; have LEFT > RIGHT, indicating that no qtuple contains SQUARE along that
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
521 ;; DX,DY direction.
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
522 (cond
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
523 ((> left right)) ; Quit
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
524 (t ; Else ..
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
525 (let (depl square0 square1 square2 count delta)
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
526 (setq depl (landmark-xy-to-index dx dy)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
527 square0 (+ square (* left depl))
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
528 square1 (+ square (* right depl))
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
529 square2 (+ square0 (* 4 depl)))
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
530 ;; Compute the contents of the first qtuple:
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
531 (setq square square0
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
532 count 0)
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
533 (while (<= square square2)
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
534 (setq count (+ count (aref landmark-board square))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
535 square (+ square depl)))
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
536 (while (<= square0 square1)
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
537 ;; Update the squares of the qtuple beginning in SQUARE0 and ending
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
538 ;; in SQUARE2.
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
539 (setq delta (- (aref landmark-score-trans-table count)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
540 (aref landmark-score-trans-table (- count dval))))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
541 (cond ((not (zerop delta)) ; or else nothing to update
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
542 (setq square square0)
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
543 (while (<= square square2)
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
544 (if (zerop (aref landmark-board square)) ; only for free squares
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
545 (aset landmark-score-table square
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
546 (+ (aref landmark-score-table square) delta)))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
547 (setq square (+ square depl)))))
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
548 ;; Then shift the qtuple one square along DEPL, this only requires
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
549 ;; modifying SQUARE0 and SQUARE2.
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
550 (setq square2 (+ square2 depl)
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
551 count (+ count (- (aref landmark-board square0))
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
552 (aref landmark-board square2))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
553 square0 (+ square0 depl)))))))
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
554
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
555 ;;;
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
556 ;;; GAME CONTROL.
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
557 ;;;
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
558
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
559 ;; Several variables are used to monitor a game, including a GAME-HISTORY (the
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
560 ;; list of all (SQUARE . PREVSCORE) played) that allows to take moves back
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
561 ;; (anti-updating the score table) and to compute the table from scratch in
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
562 ;; case of an interruption.
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
563
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
564 (defvar landmark-game-in-progress nil
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
565 "Non-nil if a game is in progress.")
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
566
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
567 (defvar landmark-game-history nil
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
568 "A record of all moves that have been played during current game.")
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
569
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
570 (defvar landmark-number-of-moves nil
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
571 "Number of moves already played in current game.")
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
572
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
573 (defvar landmark-number-of-human-moves nil
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
574 "Number of moves already played by human in current game.")
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
575
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
576 (defvar landmark-emacs-played-first nil
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
577 "Non-nil if Emacs played first.")
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
578
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
579 (defvar landmark-human-took-back nil
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
580 "Non-nil if Human took back a move during the game.")
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
581
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
582 (defvar landmark-human-refused-draw nil
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
583 "Non-nil if Human refused Emacs offer of a draw.")
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
584
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
585 (defvar landmark-emacs-is-computing nil
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
586 ;; This is used to detect interruptions. Hopefully, it should not be needed.
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
587 "Non-nil if Emacs is in the middle of a computation.")
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
588
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
589
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
590 (defun landmark-start-game (n m)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
591 "Initialize a new game on an N by M board."
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
592 (setq landmark-emacs-is-computing t) ; Raise flag
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
593 (setq landmark-game-in-progress t)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
594 (setq landmark-board-width n
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
595 landmark-board-height m
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
596 landmark-vector-length (1+ (* (+ m 2) (1+ n)))
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
597 landmark-draw-limit (/ (* 7 n m) 10))
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
598 (setq landmark-emacs-won nil
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
599 landmark-game-history nil
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
600 landmark-number-of-moves 0
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
601 landmark-number-of-human-moves 0
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
602 landmark-emacs-played-first nil
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
603 landmark-human-took-back nil
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
604 landmark-human-refused-draw nil)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
605 (landmark-init-display n m) ; Display first: the rest takes time
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
606 (landmark-init-score-table) ; INIT-BOARD requires that the score
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
607 (landmark-init-board) ; table be already created.
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
608 (setq landmark-emacs-is-computing nil))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
609
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
610 (defun landmark-play-move (square val &optional dont-update-score)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
611 "Go to SQUARE, play VAL and update everything."
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
612 (setq landmark-emacs-is-computing t) ; Raise flag
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
613 (cond ((= 1 val) ; a Human move
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
614 (setq landmark-number-of-human-moves (1+ landmark-number-of-human-moves)))
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
615 ((zerop landmark-number-of-moves) ; an Emacs move. Is it first ?
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
616 (setq landmark-emacs-played-first t)))
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
617 (setq landmark-game-history
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
618 (cons (cons square (aref landmark-score-table square))
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
619 landmark-game-history)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
620 landmark-number-of-moves (1+ landmark-number-of-moves))
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
621 (landmark-plot-square square val)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
622 (aset landmark-board square val) ; *BEFORE* UPDATE-SCORE !
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
623 (if dont-update-score nil
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
624 (landmark-update-score-table square val) ; previous val was 0: dval = val
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
625 (aset landmark-score-table square -1))
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
626 (setq landmark-emacs-is-computing nil))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
627
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
628 (defun landmark-take-back ()
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
629 "Take back last move and update everything."
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
630 (setq landmark-emacs-is-computing t)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
631 (let* ((last-move (car landmark-game-history))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
632 (square (car last-move))
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
633 (oldval (aref landmark-board square)))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
634 (if (= 1 oldval)
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
635 (setq landmark-number-of-human-moves (1- landmark-number-of-human-moves)))
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
636 (setq landmark-game-history (cdr landmark-game-history)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
637 landmark-number-of-moves (1- landmark-number-of-moves))
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
638 (landmark-plot-square square 0)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
639 (aset landmark-board square 0) ; *BEFORE* UPDATE-SCORE !
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
640 (landmark-update-score-table square (- oldval))
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
641 (aset landmark-score-table square (cdr last-move)))
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
642 (setq landmark-emacs-is-computing nil))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
643
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
644
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
645 ;;;_ + SESSION CONTROL.
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
646
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
647 (defvar landmark-number-of-trials 0
18290
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
648 "The number of times that landmark has been run.")
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
649
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
650 (defvar landmark-sum-of-moves 0
18290
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
651 "The total number of moves made in all games.")
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
652
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
653 (defvar landmark-number-of-emacs-wins 0
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
654 "Number of games Emacs won in this session.")
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
655
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
656 (defvar landmark-number-of-human-wins 0
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
657 "Number of games you won in this session.")
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
658
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
659 (defvar landmark-number-of-draws 0
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
660 "Number of games already drawn in this session.")
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
661
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
662
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
663 (defun landmark-terminate-game (result)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
664 "Terminate the current game with RESULT."
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
665 (setq landmark-number-of-trials (1+ landmark-number-of-trials))
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
666 (setq landmark-sum-of-moves (+ landmark-sum-of-moves landmark-number-of-moves))
18290
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
667 (if (eq result 'crash-game)
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
668 (message
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
669 "Sorry, I have been interrupted and cannot resume that game..."))
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
670 (landmark-display-statistics)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
671 ;;(ding)
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
672 (setq landmark-game-in-progress nil))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
673
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
674 (defun landmark-crash-game ()
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
675 "What to do when Emacs detects it has been interrupted."
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
676 (setq landmark-emacs-is-computing nil)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
677 (landmark-terminate-game 'crash-game)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
678 (sit-for 4) ; Let's see the message
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
679 (landmark-prompt-for-other-game))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
680
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
681
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
682 ;;;_ + INTERACTIVE COMMANDS.
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
683
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
684 (defun landmark-emacs-plays ()
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
685 "Compute Emacs next move and play it."
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
686 (interactive)
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
687 (landmark-switch-to-window)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
688 (cond
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
689 (landmark-emacs-is-computing
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
690 (landmark-crash-game))
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
691 ((not landmark-game-in-progress)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
692 (landmark-prompt-for-other-game))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
693 (t
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
694 (message "Let me think...")
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
695 (let (square score)
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
696 (setq square (landmark-strongest-square))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
697 (cond ((null square)
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
698 (landmark-terminate-game 'nobody-won))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
699 (t
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
700 (setq score (aref landmark-score-table square))
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
701 (landmark-play-move square 6)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
702 (cond ((>= score landmark-winning-threshold)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
703 (setq landmark-emacs-won t) ; for font-lock
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
704 (landmark-find-filled-qtuple square 6)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
705 (landmark-terminate-game 'emacs-won))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
706 ((zerop score)
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
707 (landmark-terminate-game 'nobody-won))
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
708 ((and (> landmark-number-of-moves landmark-draw-limit)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
709 (not landmark-human-refused-draw)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
710 (landmark-offer-a-draw))
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
711 (landmark-terminate-game 'draw-agreed))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
712 (t
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
713 (landmark-prompt-for-move)))))))))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
714
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
715 ;; For small square dimensions this is approximate, since though measured in
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
716 ;; pixels, event's (X . Y) is a character's top-left corner.
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
717 (defun landmark-click (click)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
718 "Position at the square where you click."
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
719 (interactive "e")
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
720 (and (windowp (posn-window (setq click (event-end click))))
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
721 (numberp (posn-point click))
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
722 (select-window (posn-window click))
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
723 (setq click (posn-col-row click))
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
724 (landmark-goto-xy
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
725 (min (max (/ (+ (- (car click)
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
726 landmark-x-offset
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
727 1)
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
728 (window-hscroll)
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
729 landmark-square-width
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
730 (% landmark-square-width 2)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
731 (/ landmark-square-width 2))
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
732 landmark-square-width)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
733 1)
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
734 landmark-board-width)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
735 (min (max (/ (+ (- (cdr click)
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
736 landmark-y-offset
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
737 1)
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
738 (let ((inhibit-point-motion-hooks t))
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
739 (count-lines 1 (window-start)))
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
740 landmark-square-height
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
741 (% landmark-square-height 2)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
742 (/ landmark-square-height 2))
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
743 landmark-square-height)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
744 1)
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
745 landmark-board-height))))
18290
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
746
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
747 (defun landmark-mouse-play (click)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
748 "Play at the square where you click."
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
749 (interactive "e")
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
750 (if (landmark-click click)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
751 (landmark-human-plays)))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
752
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
753 (defun landmark-human-plays ()
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
754 "Signal to the Landmark program that you have played.
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
755 You must have put the cursor on the square where you want to play.
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
756 If the game is finished, this command requests for another game."
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
757 (interactive)
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
758 (landmark-switch-to-window)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
759 (cond
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
760 (landmark-emacs-is-computing
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
761 (landmark-crash-game))
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
762 ((not landmark-game-in-progress)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
763 (landmark-prompt-for-other-game))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
764 (t
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
765 (let (square score)
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
766 (setq square (landmark-point-square))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
767 (cond ((null square)
65689
96187e7edd1b 2005-09-25 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 65585
diff changeset
768 (error "Your point is not on a square. Retry!"))
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
769 ((not (zerop (aref landmark-board square)))
65689
96187e7edd1b 2005-09-25 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 65585
diff changeset
770 (error "Your point is not on a free square. Retry!"))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
771 (t
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
772 (setq score (aref landmark-score-table square))
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
773 (landmark-play-move square 1)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
774 (cond ((and (>= score landmark-losing-threshold)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
775 ;; Just testing SCORE > THRESHOLD is not enough for
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
776 ;; detecting wins, it just gives an indication that
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
777 ;; we confirm with LANDMARK-FIND-FILLED-QTUPLE.
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
778 (landmark-find-filled-qtuple square 1))
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
779 (landmark-terminate-game 'human-won))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
780 (t
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
781 (landmark-emacs-plays)))))))))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
782
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
783 (defun landmark-human-takes-back ()
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
784 "Signal to the Landmark program that you wish to take back your last move."
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
785 (interactive)
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
786 (landmark-switch-to-window)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
787 (cond
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
788 (landmark-emacs-is-computing
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
789 (landmark-crash-game))
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
790 ((not landmark-game-in-progress)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
791 (message "Too late for taking back...")
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
792 (sit-for 4)
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
793 (landmark-prompt-for-other-game))
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
794 ((zerop landmark-number-of-human-moves)
65689
96187e7edd1b 2005-09-25 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 65585
diff changeset
795 (message "You have not played yet... Your move?"))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
796 (t
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
797 (message "One moment, please...")
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
798 ;; It is possible for the user to let Emacs play several consecutive
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
799 ;; moves, so that the best way to know when to stop taking back moves is
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
800 ;; to count the number of human moves:
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
801 (setq landmark-human-took-back t)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
802 (let ((number landmark-number-of-human-moves))
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
803 (while (= number landmark-number-of-human-moves)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
804 (landmark-take-back)))
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
805 (landmark-prompt-for-move))))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
806
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
807 (defun landmark-human-resigns ()
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
808 "Signal to the Landmark program that you may want to resign."
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
809 (interactive)
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
810 (landmark-switch-to-window)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
811 (cond
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
812 (landmark-emacs-is-computing
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
813 (landmark-crash-game))
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
814 ((not landmark-game-in-progress)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
815 (message "There is no game in progress"))
65689
96187e7edd1b 2005-09-25 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 65585
diff changeset
816 ((y-or-n-p "You mean, you resign? ")
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
817 (landmark-terminate-game 'human-resigned))
65689
96187e7edd1b 2005-09-25 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 65585
diff changeset
818 ((y-or-n-p "You mean, we continue? ")
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
819 (landmark-prompt-for-move))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
820 (t
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
821 (landmark-terminate-game 'human-resigned)))) ; OK. Accept it
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
822
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
823 ;;;_ + PROMPTING THE HUMAN PLAYER.
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
824
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
825 (defun landmark-prompt-for-move ()
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
826 "Display a message asking for Human's move."
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
827 (message (if (zerop landmark-number-of-human-moves)
65689
96187e7edd1b 2005-09-25 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 65585
diff changeset
828 "Your move? (move to a free square and hit X, RET ...)"
111488
721dbc4f6c02 Remove odd code from kandmark, gomoku.
Glenn Morris <rgm@gnu.org>
parents: 111331
diff changeset
829 "Your move?")))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
830
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
831 (defun landmark-prompt-for-other-game ()
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
832 "Ask for another game, and start it."
65689
96187e7edd1b 2005-09-25 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 65585
diff changeset
833 (if (y-or-n-p "Another game? ")
18290
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
834 (if (y-or-n-p "Retain learned weights ")
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
835 (landmark 2)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
836 (landmark 1))
65689
96187e7edd1b 2005-09-25 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 65585
diff changeset
837 (message "Chicken!")))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
838
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
839 (defun landmark-offer-a-draw ()
18290
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
840 "Offer a draw and return t if Human accepted it."
65689
96187e7edd1b 2005-09-25 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 65585
diff changeset
841 (or (y-or-n-p "I offer you a draw. Do you accept it? ")
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
842 (not (setq landmark-human-refused-draw t))))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
843
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
844
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
845 (defun landmark-max-width ()
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
846 "Largest possible board width for the current window."
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
847 (1+ (/ (- (window-width (selected-window))
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
848 landmark-x-offset landmark-x-offset 1)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
849 landmark-square-width)))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
850
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
851 (defun landmark-max-height ()
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
852 "Largest possible board height for the current window."
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
853 (1+ (/ (- (window-height (selected-window))
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
854 landmark-y-offset landmark-y-offset 2)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
855 ;; 2 instead of 1 because WINDOW-HEIGHT includes the mode line !
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
856 landmark-square-height)))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
857
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
858 (defun landmark-point-y ()
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
859 "Return the board row where point is."
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
860 (let ((inhibit-point-motion-hooks t))
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
861 (1+ (/ (- (count-lines 1 (point)) landmark-y-offset (if (bolp) 0 1))
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
862 landmark-square-height))))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
863
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
864 (defun landmark-point-square ()
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
865 "Return the index of the square point is on."
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
866 (let ((inhibit-point-motion-hooks t))
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
867 (landmark-xy-to-index (1+ (/ (- (current-column) landmark-x-offset)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
868 landmark-square-width))
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
869 (landmark-point-y))))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
870
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
871 (defun landmark-goto-square (index)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
872 "Move point to square number INDEX."
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
873 (landmark-goto-xy (landmark-index-to-x index) (landmark-index-to-y index)))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
874
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
875 (defun landmark-goto-xy (x y)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
876 "Move point to square at X, Y coords."
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
877 (let ((inhibit-point-motion-hooks t))
104390
c6ae8d43800c Use forward-line, not goto-line.
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
878 (goto-char (point-min))
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
879 (forward-line (+ landmark-y-offset (* landmark-square-height (1- y)))))
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
880 (move-to-column (+ landmark-x-offset (* landmark-square-width (1- x)))))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
881
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
882 (defun landmark-plot-square (square value)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
883 "Draw 'X', 'O' or '.' on SQUARE depending on VALUE, leave point there."
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
884 (or (= value 1)
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
885 (landmark-goto-square square))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
886 (let ((inhibit-read-only t)
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
887 (inhibit-point-motion-hooks t))
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
888 (insert-and-inherit (cond ((= value 1) ?.)
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
889 ((= value 2) ?N)
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
890 ((= value 3) ?S)
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
891 ((= value 4) ?E)
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
892 ((= value 5) ?W)
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
893 ((= value 6) ?^)))
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
894
30542
f03ab02d1f4e (lm-font-lock-face-O, lm-font-lock-face-X)
Eli Zaretskii <eliz@gnu.org>
parents: 25227
diff changeset
895 (and (zerop value)
38076
30c899dc34c4 (lm-plot-square, lm-init-display): Add help-echo to mouse-highlighted text.
Eli Zaretskii <eliz@gnu.org>
parents: 37840
diff changeset
896 (add-text-properties (1- (point)) (point)
30c899dc34c4 (lm-plot-square, lm-init-display): Add help-echo to mouse-highlighted text.
Eli Zaretskii <eliz@gnu.org>
parents: 37840
diff changeset
897 '(mouse-face highlight
30c899dc34c4 (lm-plot-square, lm-init-display): Add help-echo to mouse-highlighted text.
Eli Zaretskii <eliz@gnu.org>
parents: 37840
diff changeset
898 help-echo "\
30c899dc34c4 (lm-plot-square, lm-init-display): Add help-echo to mouse-highlighted text.
Eli Zaretskii <eliz@gnu.org>
parents: 37840
diff changeset
899 mouse-1: get robot moving, mouse-2: play on this square")))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
900 (delete-char 1)
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
901 (backward-char 1))
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
902 (sit-for 0)) ; Display NOW
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
903
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
904 (defun landmark-init-display (n m)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
905 "Display an N by M Landmark board."
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
906 (buffer-disable-undo (current-buffer))
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
907 (let ((inhibit-read-only t)
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
908 (point 1) opoint
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
909 (intangible t)
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
910 (i m) j x)
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
911 ;; Try to minimize number of chars (because of text properties)
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
912 (setq tab-width
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
913 (if (zerop (% landmark-x-offset landmark-square-width))
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
914 landmark-square-width
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
915 (max (/ (+ (% landmark-x-offset landmark-square-width)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
916 landmark-square-width 1) 2) 2)))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
917 (erase-buffer)
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
918 (newline landmark-y-offset)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
919 (while (progn
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
920 (setq j n
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
921 x (- landmark-x-offset landmark-square-width))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
922 (while (>= (setq j (1- j)) 0)
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
923 (insert-char ?\t (/ (- (setq x (+ x landmark-square-width))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
924 (current-column))
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
925 tab-width))
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
926 (insert-char ? (- x (current-column)))
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
927 (if (setq intangible (not intangible))
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
928 (put-text-property point (point) 'intangible 2))
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
929 (and (zerop j)
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
930 (= i (- m 2))
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
931 (progn
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
932 (while (>= i 3)
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
933 (append-to-buffer (current-buffer) opoint (point))
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
934 (setq i (- i 2)))
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
935 (goto-char (point-max))))
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
936 (setq point (point))
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
937 (insert ?=)
38076
30c899dc34c4 (lm-plot-square, lm-init-display): Add help-echo to mouse-highlighted text.
Eli Zaretskii <eliz@gnu.org>
parents: 37840
diff changeset
938 (add-text-properties point (point)
30c899dc34c4 (lm-plot-square, lm-init-display): Add help-echo to mouse-highlighted text.
Eli Zaretskii <eliz@gnu.org>
parents: 37840
diff changeset
939 '(mouse-face highlight help-echo "\
30c899dc34c4 (lm-plot-square, lm-init-display): Add help-echo to mouse-highlighted text.
Eli Zaretskii <eliz@gnu.org>
parents: 37840
diff changeset
940 mouse-1: get robot moving, mouse-2: play on this square")))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
941 (> (setq i (1- i)) 0))
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
942 (if (= i (1- m))
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
943 (setq opoint point))
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
944 (insert-char ?\n landmark-square-height))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
945 (or (eq (char-after 1) ?.)
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
946 (put-text-property 1 2 'point-entered
39866
a4570786d40d Do not double variables in the lambda-list.
Pavel Janík <Pavel@Janik.cz>
parents: 38455
diff changeset
947 (lambda (x y) (if (bobp) (forward-char)))))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
948 (or intangible
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
949 (put-text-property point (point) 'intangible 2))
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
950 (put-text-property point (point) 'point-entered
39866
a4570786d40d Do not double variables in the lambda-list.
Pavel Janík <Pavel@Janik.cz>
parents: 38455
diff changeset
951 (lambda (x y) (if (eobp) (backward-char))))
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
952 (put-text-property (point-min) (point) 'category 'landmark-mode))
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
953 (landmark-goto-xy (/ (1+ n) 2) (/ (1+ m) 2)) ; center of the board
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
954 (sit-for 0)) ; Display NOW
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
955
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
956 (defun landmark-display-statistics ()
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
957 "Obnoxiously display some statistics about previous games in mode line."
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
958 ;; We store this string in the mode-line-process local variable.
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
959 ;; This is certainly not the cleanest way out ...
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
960 (setq mode-line-process
18290
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
961 (format ": Trials: %d, Avg#Moves: %d"
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
962 landmark-number-of-trials
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
963 (if (zerop landmark-number-of-trials)
18290
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
964 0
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
965 (/ landmark-sum-of-moves landmark-number-of-trials))))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
966 (force-mode-line-update))
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
967
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
968 (defun landmark-switch-to-window ()
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
969 "Find or create the Landmark buffer, and display it."
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
970 (interactive)
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
971 (let ((buff (get-buffer "*Landmark*")))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
972 (if buff ; Buffer exists:
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
973 (switch-to-buffer buff) ; no problem.
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
974 (if landmark-game-in-progress
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
975 (landmark-crash-game)) ; buffer has been killed or something
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
976 (switch-to-buffer "*Landmark*") ; Anyway, start anew.
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
977 (landmark-mode))))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
978
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
979
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
980 ;;;_ + CROSSING WINNING QTUPLES.
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
981
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
982 ;; When someone succeeds in filling a qtuple, we draw a line over the five
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
983 ;; corresponding squares. One problem is that the program does not know which
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
984 ;; squares ! It only knows the square where the last move has been played and
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
985 ;; who won. The solution is to scan the board along all four directions.
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
986
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
987 (defun landmark-find-filled-qtuple (square value)
18290
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
988 "Return t if SQUARE belongs to a qtuple filled with VALUEs."
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
989 (or (landmark-check-filled-qtuple square value 1 0)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
990 (landmark-check-filled-qtuple square value 0 1)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
991 (landmark-check-filled-qtuple square value 1 1)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
992 (landmark-check-filled-qtuple square value -1 1)))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
993
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
994 (defun landmark-check-filled-qtuple (square value dx dy)
18290
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
995 "Return t if SQUARE belongs to a qtuple filled with VALUEs along DX, DY."
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
996 (let ((a 0) (b 0)
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
997 (left square) (right square)
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
998 (depl (landmark-xy-to-index dx dy)))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
999 (while (and (> a -4) ; stretch tuple left
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1000 (= value (aref landmark-board (setq left (- left depl)))))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1001 (setq a (1- a)))
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1002 (while (and (< b (+ a 4)) ; stretch tuple right
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1003 (= value (aref landmark-board (setq right (+ right depl)))))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1004 (setq b (1+ b)))
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1005 (cond ((= b (+ a 4)) ; tuple length = 5 ?
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1006 (landmark-cross-qtuple (+ square (* a depl)) (+ square (* b depl))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1007 dx dy)
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1008 t))))
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1009
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1010 (defun landmark-cross-qtuple (square1 square2 dx dy)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1011 "Cross every square between SQUARE1 and SQUARE2 in the DX, DY direction."
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1012 (save-excursion ; Not moving point from last square
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1013 (let ((depl (landmark-xy-to-index dx dy))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1014 (inhibit-read-only t)
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1015 (inhibit-point-motion-hooks t))
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1016 ;; WARNING: this function assumes DEPL > 0 and SQUARE2 > SQUARE1
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1017 (while (/= square1 square2)
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1018 (landmark-goto-square square1)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1019 (setq square1 (+ square1 depl))
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1020 (cond
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1021 ((= dy 0) ; Horizontal
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1022 (forward-char 1)
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1023 (insert-char ?- (1- landmark-square-width) t)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1024 (delete-region (point) (progn
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1025 (skip-chars-forward " \t")
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1026 (point))))
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1027 ((= dx 0) ; Vertical
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1028 (let ((landmark-n 1)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1029 (column (current-column)))
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1030 (while (< landmark-n landmark-square-height)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1031 (setq landmark-n (1+ landmark-n))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1032 (forward-line 1)
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1033 (indent-to column)
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1034 (insert-and-inherit ?|))))
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1035 ((= dx -1) ; 1st Diagonal
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1036 (indent-to (prog1 (- (current-column) (/ landmark-square-width 2))
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1037 (forward-line (/ landmark-square-height 2))))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1038 (insert-and-inherit ?/))
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1039 (t ; 2nd Diagonal
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1040 (indent-to (prog1 (+ (current-column) (/ landmark-square-width 2))
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1041 (forward-line (/ landmark-square-height 2))))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1042 (insert-and-inherit ?\\))))))
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1043 (sit-for 0)) ; Display NOW
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1044
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1045
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1046 ;;;_ + CURSOR MOTION.
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1047
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1048 ;; previous-line and next-line don't work right with intangible newlines
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1049 (defun landmark-move-down ()
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1050 "Move point down one row on the Landmark board."
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1051 (interactive)
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1052 (if (< (landmark-point-y) landmark-board-height)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1053 (forward-line 1)));;; landmark-square-height)))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1054
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1055 (defun landmark-move-up ()
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1056 "Move point up one row on the Landmark board."
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1057 (interactive)
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1058 (if (> (landmark-point-y) 1)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1059 (forward-line (- landmark-square-height))))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1060
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1061 (defun landmark-move-ne ()
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1062 "Move point North East on the Landmark board."
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1063 (interactive)
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1064 (landmark-move-up)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1065 (forward-char))
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1066
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1067 (defun landmark-move-se ()
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1068 "Move point South East on the Landmark board."
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1069 (interactive)
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1070 (landmark-move-down)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1071 (forward-char))
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1072
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1073 (defun landmark-move-nw ()
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1074 "Move point North West on the Landmark board."
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1075 (interactive)
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1076 (landmark-move-up)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1077 (backward-char))
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1078
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1079 (defun landmark-move-sw ()
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1080 "Move point South West on the Landmark board."
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1081 (interactive)
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1082 (landmark-move-down)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1083 (backward-char))
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1084
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1085 (defun landmark-beginning-of-line ()
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1086 "Move point to first square on the Landmark board row."
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1087 (interactive)
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1088 (move-to-column landmark-x-offset))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1089
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1090 (defun landmark-end-of-line ()
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1091 "Move point to last square on the Landmark board row."
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1092 (interactive)
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1093 (move-to-column (+ landmark-x-offset
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1094 (* landmark-square-width (1- landmark-board-width)))))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1095
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1096
18290
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
1097 ;;;_ + Simulation variables
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1098
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1099 ;;;_ - landmark-nvar
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1100 (defvar landmark-nvar 0.0075
18290
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
1101 "Not used.
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
1102 Affects a noise generator which was used in an earlier incarnation of
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
1103 this program to add a random element to the way moves were made.")
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
1104 ;;;_ - lists of cardinal directions
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
1105 ;;;_ :
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1106 (defvar landmark-ns '(landmark-n landmark-s)
18290
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
1107 "Used when doing something relative to the north and south axes.")
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1108 (defvar landmark-ew '(landmark-e landmark-w)
18290
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
1109 "Used when doing something relative to the east and west axes.")
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1110 (defvar landmark-directions '(landmark-n landmark-s landmark-e landmark-w)
18290
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
1111 "The cardinal directions.")
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1112 (defvar landmark-8-directions
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1113 '((landmark-n) (landmark-n landmark-w) (landmark-w) (landmark-s landmark-w)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1114 (landmark-s) (landmark-s landmark-e) (landmark-e) (landmark-n landmark-e))
18290
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
1115 "The full 8 possible directions.")
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1116
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1117 (defvar landmark-number-of-moves
18290
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
1118 "The number of moves made by the robot so far.")
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1119
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1120
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1121 ;;;_* Terry's mods to create lm.el
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1122
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1123 ;;;(setq landmark-debug nil)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1124 (defvar landmark-debug nil
18290
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
1125 "If non-nil, debugging is printed.")
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1126 (defcustom landmark-one-moment-please nil
18290
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
1127 "If non-nil, print \"One moment please\" when a new board is generated.
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
1128 The drawback of this is you don't see how many moves the last run took
21363
f1fc193b6958 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 18951
diff changeset
1129 because it is overwritten by \"One moment please\"."
f1fc193b6958 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 18951
diff changeset
1130 :type 'boolean
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1131 :group 'landmark)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1132 (defcustom landmark-output-moves t
21363
f1fc193b6958 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 18951
diff changeset
1133 "If non-nil, output number of moves so far on a move-by-move basis."
f1fc193b6958 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 18951
diff changeset
1134 :type 'boolean
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1135 :group 'landmark)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1136
18290
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
1137
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1138 (defun landmark-weights-debug ()
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1139 (if landmark-debug
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1140 (progn (landmark-print-wts) (landmark-blackbox) (landmark-print-y-s-noise)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1141 (landmark-print-smell))))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1142
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1143 ;;;_ - Printing various things
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1144 (defun landmark-print-distance-int (direction)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1145 (interactive)
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1146 (insert (format "%S %S " direction (get direction 'distance))))
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1147
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1148
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1149 (defun landmark-print-distance ()
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1150 (insert (format "tree: %S \n" (calc-distance-of-robot-from 'landmark-tree)))
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1151 (mapc 'landmark-print-distance-int landmark-directions))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1152
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1153
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1154 ;;(setq direction 'landmark-n)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1155 ;;(get 'landmark-n 'landmark-s)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1156 (defun landmark-nslify-wts-int (direction)
30888
e559f0aa6b2d Don't quote lambda.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 30542
diff changeset
1157 (mapcar (lambda (target-direction)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1158 (get direction target-direction))
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1159 landmark-directions))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1160
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1161
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1162 (defun landmark-nslify-wts ()
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1163 (interactive)
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1164 (let ((l (apply 'append (mapcar 'landmark-nslify-wts-int landmark-directions))))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1165 (insert (format "set data_value WTS \n %s \n" l))
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1166 (insert (format "/* max: %S min: %S */"
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1167 (eval (cons 'max l)) (eval (cons 'min l))))))
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1168
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1169 (defun landmark-print-wts-int (direction)
30888
e559f0aa6b2d Don't quote lambda.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 30542
diff changeset
1170 (mapc (lambda (target-direction)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1171 (insert (format "%S %S %S "
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1172 direction
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1173 target-direction
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1174 (get direction target-direction))))
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1175 landmark-directions)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1176 (insert "\n"))
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1177
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1178 (defun landmark-print-wts ()
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1179 (interactive)
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1180 (with-current-buffer "*landmark-wts*"
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1181 (insert "==============================\n")
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1182 (mapc 'landmark-print-wts-int landmark-directions)))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1183
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1184 (defun landmark-print-moves (moves)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1185 (interactive)
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1186 (with-current-buffer "*landmark-moves*"
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1187 (insert (format "%S\n" moves))))
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1188
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1189
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1190 (defun landmark-print-y-s-noise-int (direction)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1191 (insert (format "%S:landmark-y %S, s %S, noise %S \n"
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1192 (symbol-name direction)
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1193 (get direction 'y_t)
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1194 (get direction 's)
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1195 (get direction 'noise)
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1196 )))
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1197
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1198 (defun landmark-print-y-s-noise ()
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1199 (interactive)
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1200 (with-current-buffer "*landmark-y,s,noise*"
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1201 (insert "==============================\n")
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1202 (mapc 'landmark-print-y-s-noise-int landmark-directions)))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1203
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1204 (defun landmark-print-smell-int (direction)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1205 (insert (format "%S: smell: %S \n"
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1206 (symbol-name direction)
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1207 (get direction 'smell))))
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1208
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1209 (defun landmark-print-smell ()
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1210 (interactive)
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1211 (with-current-buffer "*landmark-smell*"
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1212 (insert "==============================\n")
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1213 (insert (format "tree: %S \n" (get 'z 't)))
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1214 (mapc 'landmark-print-smell-int landmark-directions)))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1215
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1216 (defun landmark-print-w0-int (direction)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1217 (insert (format "%S: w0: %S \n"
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1218 (symbol-name direction)
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1219 (get direction 'w0))))
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1220
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1221 (defun landmark-print-w0 ()
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1222 (interactive)
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1223 (with-current-buffer "*landmark-w0*"
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1224 (insert "==============================\n")
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1225 (mapc 'landmark-print-w0-int landmark-directions)))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1226
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1227 (defun landmark-blackbox ()
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1228 (with-current-buffer "*landmark-blackbox*"
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1229 (insert "==============================\n")
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1230 (insert "I smell: ")
30888
e559f0aa6b2d Don't quote lambda.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 30542
diff changeset
1231 (mapc (lambda (direction)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1232 (if (> (get direction 'smell) 0)
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1233 (insert (format "%S " direction))))
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1234 landmark-directions)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1235 (insert "\n")
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1236
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1237 (insert "I move: ")
30888
e559f0aa6b2d Don't quote lambda.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 30542
diff changeset
1238 (mapc (lambda (direction)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1239 (if (> (get direction 'y_t) 0)
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1240 (insert (format "%S " direction))))
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1241 landmark-directions)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1242 (insert "\n")
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1243 (landmark-print-wts-blackbox)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1244 (insert (format "z_t-z_t-1: %S" (- (get 'z 't) (get 'z 't-1))))
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1245 (landmark-print-distance)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1246 (insert "\n")))
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1247
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1248 (defun landmark-print-wts-blackbox ()
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1249 (interactive)
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1250 (mapc 'landmark-print-wts-int landmark-directions))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1251
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1252 ;;;_ - learning parameters
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1253 (defcustom landmark-bound 0.005
21363
f1fc193b6958 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 18951
diff changeset
1254 "The maximum that w0j may be."
f1fc193b6958 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 18951
diff changeset
1255 :type 'number
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1256 :group 'landmark)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1257 (defcustom landmark-c 1.0
18290
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
1258 "A factor applied to modulate the increase in wij.
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1259 Used in the function landmark-update-normal-weights."
21363
f1fc193b6958 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 18951
diff changeset
1260 :type 'number
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1261 :group 'landmark)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1262 (defcustom landmark-c-naught 0.5
18290
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
1263 "A factor applied to modulate the increase in w0j.
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1264 Used in the function landmark-update-naught-weights."
21363
f1fc193b6958 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 18951
diff changeset
1265 :type 'number
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1266 :group 'landmark)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1267 (defvar landmark-initial-w0 0.0)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1268 (defvar landmark-initial-wij 0.0)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1269 (defcustom landmark-no-payoff 0
18290
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
1270 "The amount of simulation cycles that have occurred with no movement.
21363
f1fc193b6958 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 18951
diff changeset
1271 Used to move the robot when he is stuck in a rut for some reason."
f1fc193b6958 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 18951
diff changeset
1272 :type 'integer
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1273 :group 'landmark)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1274 (defcustom landmark-max-stall-time 2
18290
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
1275 "The maximum number of cycles that the robot can remain stuck in a place.
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1276 After this limit is reached, landmark-random-move is called to push him out of it."
21363
f1fc193b6958 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 18951
diff changeset
1277 :type 'integer
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1278 :group 'landmark)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1279
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1280
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1281 ;;;_ + Randomizing functions
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1282 ;;;_ - landmark-flip-a-coin ()
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1283 (defun landmark-flip-a-coin ()
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1284 (if (> (random 5000) 2500)
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1285 -1
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1286 1))
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1287 ;;;_ : landmark-very-small-random-number ()
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1288 ;(defun landmark-very-small-random-number ()
18290
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
1289 ; (/
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
1290 ; (* (/ (random 900000) 900000.0) .0001)))
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1291 ;;;_ : landmark-randomize-weights-for (direction)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1292 (defun landmark-randomize-weights-for (direction)
30888
e559f0aa6b2d Don't quote lambda.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 30542
diff changeset
1293 (mapc (lambda (target-direction)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1294 (put direction
18290
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
1295 target-direction
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1296 (* (landmark-flip-a-coin) (/ (random 10000) 10000.0))))
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1297 landmark-directions))
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1298 ;;;_ : landmark-noise ()
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1299 (defun landmark-noise ()
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1300 (* (- (/ (random 30001) 15000.0) 1) landmark-nvar))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1301
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1302 ;;;_ : landmark-fix-weights-for (direction)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1303 (defun landmark-fix-weights-for (direction)
30888
e559f0aa6b2d Don't quote lambda.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 30542
diff changeset
1304 (mapc (lambda (target-direction)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1305 (put direction
18290
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
1306 target-direction
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1307 landmark-initial-wij))
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1308 landmark-directions))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1309
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1310
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1311 ;;;_ + Plotting functions
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1312 ;;;_ - landmark-plot-internal (sym)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1313 (defun landmark-plot-internal (sym)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1314 (landmark-plot-square (landmark-xy-to-index
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1315 (get sym 'x)
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1316 (get sym 'y))
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1317 (get sym 'sym)))
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1318 ;;;_ - landmark-plot-landmarks ()
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1319 (defun landmark-plot-landmarks ()
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1320 (setq landmark-cx (/ landmark-board-width 2))
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1321 (setq landmark-cy (/ landmark-board-height 2))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1322
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1323 (put 'landmark-n 'x landmark-cx)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1324 (put 'landmark-n 'y 1)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1325 (put 'landmark-n 'sym 2)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1326
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1327 (put 'landmark-tree 'x landmark-cx)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1328 (put 'landmark-tree 'y landmark-cy)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1329 (put 'landmark-tree 'sym 6)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1330
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1331 (put 'landmark-s 'x landmark-cx)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1332 (put 'landmark-s 'y landmark-board-height)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1333 (put 'landmark-s 'sym 3)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1334
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1335 (put 'landmark-w 'x 1)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1336 (put 'landmark-w 'y (/ landmark-board-height 2))
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1337 (put 'landmark-w 'sym 5)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1338
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1339 (put 'landmark-e 'x landmark-board-width)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1340 (put 'landmark-e 'y (/ landmark-board-height 2))
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1341 (put 'landmark-e 'sym 4)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1342
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1343 (mapc 'landmark-plot-internal '(landmark-n landmark-s landmark-e landmark-w landmark-tree)))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1344
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1345
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1346
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1347 ;;;_ + Distance-calculation functions
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1348 ;;;_ - square (a)
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1349 (defun square (a)
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1350 (* a a))
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1351
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1352 ;;;_ - distance (x x0 y y0)
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1353 (defun distance (x x0 y y0)
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1354 (sqrt (+ (square (- x x0)) (square (- y y0)))))
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1355
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1356 ;;;_ - calc-distance-of-robot-from (direction)
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1357 (defun calc-distance-of-robot-from (direction)
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1358 (put direction 'distance
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1359 (distance (get direction 'x)
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1360 (landmark-index-to-x (landmark-point-square))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1361 (get direction 'y)
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1362 (landmark-index-to-y (landmark-point-square)))))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1363
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1364 ;;;_ - calc-smell-internal (sym)
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1365 (defun calc-smell-internal (sym)
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1366 (let ((r (get sym 'r))
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1367 (d (calc-distance-of-robot-from sym)))
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1368 (if (> (* 0.5 (- 1 (/ d r))) 0)
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1369 (* 0.5 (- 1 (/ d r)))
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1370 0)))
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1371
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1372
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1373 ;;;_ + Learning (neural) functions
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1374 (defun landmark-f (x)
18290
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
1375 (cond
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1376 ((> x landmark-bound) landmark-bound)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1377 ((< x 0.0) 0.0)
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1378 (t x)))
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1379
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1380 (defun landmark-y (direction)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1381 (let ((noise (put direction 'noise (landmark-noise))))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1382 (put direction 'y_t
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1383 (if (> (get direction 's) 0.0)
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1384 1.0
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1385 0.0))))
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1386
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1387 (defun landmark-update-normal-weights (direction)
30888
e559f0aa6b2d Don't quote lambda.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 30542
diff changeset
1388 (mapc (lambda (target-direction)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1389 (put direction target-direction
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1390 (+
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1391 (get direction target-direction)
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1392 (* landmark-c
18290
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
1393 (- (get 'z 't) (get 'z 't-1))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1394 (get target-direction 'y_t)
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1395 (get direction 'smell)))))
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1396 landmark-directions))
18290
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
1397
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1398 (defun landmark-update-naught-weights (direction)
30888
e559f0aa6b2d Don't quote lambda.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 30542
diff changeset
1399 (mapc (lambda (target-direction)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1400 (put direction 'w0
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1401 (landmark-f
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1402 (+
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1403 (get direction 'w0)
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1404 (* landmark-c-naught
18290
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
1405 (- (get 'z 't) (get 'z 't-1))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1406 (get direction 'y_t))))))
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1407 landmark-directions))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1408
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1409
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1410 ;;;_ + Statistics gathering and creating functions
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1411
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1412 (defun landmark-calc-current-smells ()
30888
e559f0aa6b2d Don't quote lambda.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 30542
diff changeset
1413 (mapc (lambda (direction)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1414 (put direction 'smell (calc-smell-internal direction)))
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1415 landmark-directions))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1416
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1417 (defun landmark-calc-payoff ()
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1418 (put 'z 't-1 (get 'z 't))
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1419 (put 'z 't (calc-smell-internal 'landmark-tree))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1420 (if (= (- (get 'z 't) (get 'z 't-1)) 0.0)
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1421 (incf landmark-no-payoff)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1422 (setf landmark-no-payoff 0)))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1423
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1424 (defun landmark-store-old-y_t ()
30888
e559f0aa6b2d Don't quote lambda.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 30542
diff changeset
1425 (mapc (lambda (direction)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1426 (put direction 'y_t-1 (get direction 'y_t)))
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1427 landmark-directions))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1428
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1429
18290
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
1430 ;;;_ + Functions to move robot
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1431
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1432 (defun landmark-confidence-for (target-direction)
30888
e559f0aa6b2d Don't quote lambda.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 30542
diff changeset
1433 (apply '+
e559f0aa6b2d Don't quote lambda.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 30542
diff changeset
1434 (get target-direction 'w0)
e559f0aa6b2d Don't quote lambda.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 30542
diff changeset
1435 (mapcar (lambda (direction)
e559f0aa6b2d Don't quote lambda.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 30542
diff changeset
1436 (*
e559f0aa6b2d Don't quote lambda.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 30542
diff changeset
1437 (get direction target-direction)
e559f0aa6b2d Don't quote lambda.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 30542
diff changeset
1438 (get direction 'smell)))
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1439 landmark-directions)))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1440
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1441
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1442 (defun landmark-calc-confidences ()
30888
e559f0aa6b2d Don't quote lambda.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 30542
diff changeset
1443 (mapc (lambda (direction)
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1444 (put direction 's (landmark-confidence-for direction)))
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1445 landmark-directions))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1446
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1447 (defun landmark-move ()
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1448 (if (and (= (get 'landmark-n 'y_t) 1.0) (= (get 'landmark-s 'y_t) 1.0))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1449 (progn
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1450 (mapc (lambda (dir) (put dir 'y_t 0)) landmark-ns)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1451 (if landmark-debug
18290
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
1452 (message "n-s normalization."))))
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1453 (if (and (= (get 'landmark-w 'y_t) 1.0) (= (get 'landmark-e 'y_t) 1.0))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1454 (progn
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1455 (mapc (lambda (dir) (put dir 'y_t 0)) landmark-ew)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1456 (if landmark-debug
18290
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
1457 (message "e-w normalization"))))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1458
30888
e559f0aa6b2d Don't quote lambda.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 30542
diff changeset
1459 (mapc (lambda (pair)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1460 (if (> (get (car pair) 'y_t) 0)
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1461 (funcall (car (cdr pair)))))
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1462 '(
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1463 (landmark-n landmark-move-up)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1464 (landmark-s landmark-move-down)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1465 (landmark-e forward-char)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1466 (landmark-w backward-char)))
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1467 (landmark-plot-square (landmark-point-square) 1)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1468 (incf landmark-number-of-moves)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1469 (if landmark-output-moves
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1470 (message "Moves made: %d" landmark-number-of-moves)))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1471
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1472
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1473 (defun landmark-random-move ()
18290
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
1474 (mapc
30888
e559f0aa6b2d Don't quote lambda.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 30542
diff changeset
1475 (lambda (direction) (put direction 'y_t 0))
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1476 landmark-directions)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1477 (dolist (direction (nth (random 8) landmark-8-directions))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1478 (put direction 'y_t 1.0))
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1479 (landmark-move))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1480
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1481 (defun landmark-amble-robot ()
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1482 (interactive)
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1483 (while (> (calc-distance-of-robot-from 'landmark-tree) 0)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1484
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1485 (landmark-store-old-y_t)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1486 (landmark-calc-current-smells)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1487
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1488 (if (> landmark-no-payoff landmark-max-stall-time)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1489 (landmark-random-move)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1490 (progn
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1491 (landmark-calc-confidences)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1492 (mapc 'landmark-y landmark-directions)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1493 (landmark-move)))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1494
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1495 (landmark-calc-payoff)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1496
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1497 (mapc 'landmark-update-normal-weights landmark-directions)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1498 (mapc 'landmark-update-naught-weights landmark-directions)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1499 (if landmark-debug
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1500 (landmark-weights-debug)))
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1501 (landmark-terminate-game nil))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1502
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1503
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1504 ;;;_ - landmark-start-robot ()
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1505 (defun landmark-start-robot ()
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1506 "Signal to the Landmark program that you have played.
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1507 You must have put the cursor on the square where you want to play.
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1508 If the game is finished, this command requests for another game."
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1509 (interactive)
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1510 (landmark-switch-to-window)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1511 (cond
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1512 (landmark-emacs-is-computing
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1513 (landmark-crash-game))
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1514 ((not landmark-game-in-progress)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1515 (landmark-prompt-for-other-game))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1516 (t
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1517 (let (square score)
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1518 (setq square (landmark-point-square))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1519 (cond ((null square)
65689
96187e7edd1b 2005-09-25 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 65585
diff changeset
1520 (error "Your point is not on a square. Retry!"))
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1521 ((not (zerop (aref landmark-board square)))
65689
96187e7edd1b 2005-09-25 Romain Francoise <romain@orebokech.com>
Romain Francoise <romain@orebokech.com>
parents: 65585
diff changeset
1522 (error "Your point is not on a free square. Retry!"))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1523 (t
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1524 (progn
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1525 (landmark-plot-square square 1)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1526
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1527 (landmark-store-old-y_t)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1528 (landmark-calc-current-smells)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1529 (put 'z 't (calc-smell-internal 'landmark-tree))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1530
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1531 (landmark-random-move)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1532
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1533 (landmark-calc-payoff)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1534
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1535 (mapc 'landmark-update-normal-weights landmark-directions)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1536 (mapc 'landmark-update-naught-weights landmark-directions)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1537 (landmark-amble-robot)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1538 )))))))
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1539
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1540
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1541 ;;;_ + Misc functions
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1542 ;;;_ - landmark-init (auto-start save-weights)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1543 (defvar landmark-tree-r "")
18290
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
1544
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1545 (defun landmark-init (auto-start save-weights)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1546
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1547 (setq landmark-number-of-moves 0)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1548
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1549 (landmark-plot-landmarks)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1550
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1551 (if landmark-debug
105829
328150f0cf76 * url-util.el (url-insert-entities-in-string):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 104848
diff changeset
1552 (save-current-buffer
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1553 (set-buffer (get-buffer-create "*landmark-w0*"))
105829
328150f0cf76 * url-util.el (url-insert-entities-in-string):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 104848
diff changeset
1554 (erase-buffer)
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1555 (set-buffer (get-buffer-create "*landmark-moves*"))
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1556 (set-buffer (get-buffer-create "*landmark-wts*"))
105829
328150f0cf76 * url-util.el (url-insert-entities-in-string):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 104848
diff changeset
1557 (erase-buffer)
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1558 (set-buffer (get-buffer-create "*landmark-y,s,noise*"))
105829
328150f0cf76 * url-util.el (url-insert-entities-in-string):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 104848
diff changeset
1559 (erase-buffer)
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1560 (set-buffer (get-buffer-create "*landmark-smell*"))
105829
328150f0cf76 * url-util.el (url-insert-entities-in-string):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 104848
diff changeset
1561 (erase-buffer)
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1562 (set-buffer (get-buffer-create "*landmark-blackbox*"))
105829
328150f0cf76 * url-util.el (url-insert-entities-in-string):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 104848
diff changeset
1563 (erase-buffer)
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1564 (set-buffer (get-buffer-create "*landmark-distance*"))
105829
328150f0cf76 * url-util.el (url-insert-entities-in-string):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 104848
diff changeset
1565 (erase-buffer)))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1566
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1567
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1568 (landmark-set-landmark-signal-strengths)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1569
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1570 (dolist (direction landmark-directions)
105829
328150f0cf76 * url-util.el (url-insert-entities-in-string):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 104848
diff changeset
1571 (put direction 'y_t 0.0))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1572
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1573 (if (not save-weights)
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1574 (progn
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1575 (mapc 'landmark-fix-weights-for landmark-directions)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1576 (dolist (direction landmark-directions)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1577 (put direction 'w0 landmark-initial-w0)))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1578 (message "Weights preserved for this run."))
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1579
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1580 (if auto-start
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1581 (progn
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1582 (landmark-goto-xy (1+ (random landmark-board-width)) (1+ (random landmark-board-height)))
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1583 (landmark-start-robot))))
18290
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
1584
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1585
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1586 ;;;_ - something which doesn't work
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1587 ; no-a-worka!!
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1588 ;(defum landmark-sum-list (list)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1589 ; (if (> (length list) 0)
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1590 ; (+ (car list) (landmark-sum-list (cdr list)))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1591 ; 0))
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1592 ; this a worka!
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1593 ; (eval (cons '+ list))
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1594 ;;;_ - landmark-set-landmark-signal-strengths ()
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1595 ;;; on a screen higher than wide, I noticed that the robot would amble
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1596 ;;; left and right and not move forward. examining *landmark-blackbox*
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1597 ;;; revealed that there was no scent from the north and south
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1598 ;;; landmarks, hence, they need less factoring down of the effect of
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1599 ;;; distance on scent.
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1600
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1601 (defun landmark-set-landmark-signal-strengths ()
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1602 (setq landmark-tree-r (* (sqrt (+ (square landmark-cx) (square landmark-cy))) 1.5))
30888
e559f0aa6b2d Don't quote lambda.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 30542
diff changeset
1603 (mapc (lambda (direction)
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1604 (put direction 'r (* landmark-cx 1.1)))
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1605 landmark-ew)
30888
e559f0aa6b2d Don't quote lambda.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 30542
diff changeset
1606 (mapc (lambda (direction)
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1607 (put direction 'r (* landmark-cy 1.1)))
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1608 landmark-ns)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1609 (put 'landmark-tree 'r landmark-tree-r))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1610
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1611
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1612 ;;;_ + landmark-test-run ()
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1613
18951
a1041ace6786 (landmark-repeat, landmark): New aliases.
Richard M. Stallman <rms@gnu.org>
parents: 18290
diff changeset
1614 ;;;###autoload
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1615 (defalias 'landmark-repeat 'landmark-test-run)
18951
a1041ace6786 (landmark-repeat, landmark): New aliases.
Richard M. Stallman <rms@gnu.org>
parents: 18290
diff changeset
1616 ;;;###autoload
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1617 (defun landmark-test-run ()
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1618 "Run 100 Landmark games, each time saving the weights from the previous game."
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1619 (interactive)
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1620 (landmark 1)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1621 (dotimes (scratch-var 100)
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1622 (landmark 2)))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1623
18951
a1041ace6786 (landmark-repeat, landmark): New aliases.
Richard M. Stallman <rms@gnu.org>
parents: 18290
diff changeset
1624 ;;;###autoload
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1625 (defun landmark (parg)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1626 "Start or resume an Landmark game.
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1627 If a game is in progress, this command allows you to resume it.
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1628 Here is the relation between prefix args and game options:
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1629
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1630 prefix arg | robot is auto-started | weights are saved from last game
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1631 ---------------------------------------------------------------------
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1632 none / 1 | yes | no
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1633 2 | yes | yes
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1634 3 | no | yes
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1635 4 | no | no
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1636
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1637 You start by moving to a square and typing \\[landmark-start-robot],
18951
a1041ace6786 (landmark-repeat, landmark): New aliases.
Richard M. Stallman <rms@gnu.org>
parents: 18290
diff changeset
1638 if you did not use a prefix arg to ask for automatic start.
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1639 Use \\[describe-mode] for more info."
37840
1e7b34ebbb0a (lm): Use "p" not "P" for interactive spec.
Richard M. Stallman <rms@gnu.org>
parents: 34792
diff changeset
1640 (interactive "p")
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1641
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1642 (setf landmark-n nil landmark-m nil)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1643 (landmark-switch-to-window)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1644 (cond
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1645 (landmark-emacs-is-computing
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1646 (landmark-crash-game))
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1647 ((or (not landmark-game-in-progress)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1648 (<= landmark-number-of-moves 2))
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1649 (let ((max-width (landmark-max-width))
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1650 (max-height (landmark-max-height)))
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1651 (or landmark-n (setq landmark-n max-width))
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1652 (or landmark-m (setq landmark-m max-height))
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1653 (cond ((< landmark-n 1)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1654 (error "I need at least 1 column"))
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1655 ((< landmark-m 1)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1656 (error "I need at least 1 row"))
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1657 ((> landmark-n max-width)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1658 (error "I cannot display %d columns in that window" landmark-n)))
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1659 (if (and (> landmark-m max-height)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1660 (not (eq landmark-m landmark-saved-board-height))
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1661 ;; Use EQ because SAVED-BOARD-HEIGHT may be nil
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1662 (not (y-or-n-p (format "Do you really want %d rows? " landmark-m))))
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1663 (setq landmark-m max-height)))
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1664 (if landmark-one-moment-please
18290
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
1665 (message "One moment, please..."))
112427
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1666 (landmark-start-game landmark-n landmark-m)
bc872de587fa * play/landmark.el: Change `lm-' prefix to `landmark-' (Bug#7672).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
1667 (eval (cons 'landmark-init
18290
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
1668 (cond
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
1669 ((= parg 1) '(t nil))
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
1670 ((= parg 2) '(t t))
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
1671 ((= parg 3) '(nil t))
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
1672 ((= parg 4) '(nil nil))
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
1673 (t '(nil t))))))))
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
1674
d87d578b953d (lm-display-statistics): Display stats in mode line.
Karl Heuer <kwzh@gnu.org>
parents: 17970
diff changeset
1675
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1676 ;;;_ + Local variables
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1677
68866
5340157fbfc2 * files.el (safe-local-variable-values): New option.
Chong Yidong <cyd@stupidchicken.com>
parents: 68634
diff changeset
1678 ;;; The following `allout-layout' local variable setting:
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1679 ;;; - closes all topics from the first topic to just before the third-to-last,
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1680 ;;; - shows the children of the third to last (config vars)
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1681 ;;; - and the second to last (code section),
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1682 ;;; - and closes the last topic (this local-variables section).
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1683 ;;;Local variables:
68866
5340157fbfc2 * files.el (safe-local-variable-values): New option.
Chong Yidong <cyd@stupidchicken.com>
parents: 68634
diff changeset
1684 ;;;allout-layout: (0 : -1 -1 0)
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1685 ;;;End:
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1686
76953
417f62c55294 Seed RNG on loading.
Glenn Morris <rgm@gnu.org>
parents: 75347
diff changeset
1687 (random t)
417f62c55294 Seed RNG on loading.
Glenn Morris <rgm@gnu.org>
parents: 75347
diff changeset
1688
25227
d270a933be88 Provide `landmark', not `lm', and just once.
Karl Heuer <kwzh@gnu.org>
parents: 23376
diff changeset
1689 (provide 'landmark)
d270a933be88 Provide `landmark', not `lm', and just once.
Karl Heuer <kwzh@gnu.org>
parents: 23376
diff changeset
1690
17905
07602ad4416d Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1691 ;;; landmark.el ends here