diff options
| author | Stefan Monnier | 2014-06-25 14:11:45 -0400 |
|---|---|---|
| committer | Stefan Monnier | 2014-06-25 14:11:45 -0400 |
| commit | f51e7ac3695f7c86af9e8d9464cf7da092c6e4ce (patch) | |
| tree | f5b8b02a7f0c902f715be74f5520025d6fbaaa4c | |
| parent | 3f107ef79783017ce7ffe7e7477a09524bea1330 (diff) | |
| download | emacs-f51e7ac3695f7c86af9e8d9464cf7da092c6e4ce.tar.gz emacs-f51e7ac3695f7c86af9e8d9464cf7da092c6e4ce.zip | |
* lisp/play/landmark.el: Use lexical-binding and avoid `intangible'.
(landmark--last-pos): New var.
(landmark--intangible-chars): New const.
(landmark--intangible): New function.
(landmark-mode, landmark-move): Use it.
(landmark-mode): Remove properties.
(landmark-plot-square, landmark-point-square, landmark-goto-xy)
(landmark-cross-qtuple):
Don't worry about `intangible' any more.
(landmark-click, landmark-point-y): Same; and don't assume point-min==1.
(landmark-init-display): Don't set `intangible' and `point-entered'.
(square): Remove. Inline it instead.
(landmark--distance): Rename from `distance'.
(landmark-calc-distance-of-robot-from): Rename from
calc-distance-of-robot-from.
(landmark-calc-smell-internal): Rename from calc-smell-internal.
| -rw-r--r-- | lisp/ChangeLog | 19 | ||||
| -rw-r--r-- | lisp/play/landmark.el | 150 |
2 files changed, 96 insertions, 73 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index c3951a08c0a..089749ac028 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,22 @@ | |||
| 1 | 2014-06-25 Stefan Monnier <monnier@iro.umontreal.ca> | ||
| 2 | |||
| 3 | * play/landmark.el: Use lexical-binding and avoid `intangible'. | ||
| 4 | (landmark--last-pos): New var. | ||
| 5 | (landmark--intangible-chars): New const. | ||
| 6 | (landmark--intangible): New function. | ||
| 7 | (landmark-mode, landmark-move): Use it. | ||
| 8 | (landmark-mode): Remove properties. | ||
| 9 | (landmark-plot-square, landmark-point-square, landmark-goto-xy) | ||
| 10 | (landmark-cross-qtuple): | ||
| 11 | Don't worry about `intangible' any more. | ||
| 12 | (landmark-click, landmark-point-y): Same; and don't assume point-min==1. | ||
| 13 | (landmark-init-display): Don't set `intangible' and `point-entered'. | ||
| 14 | (square): Remove. Inline it instead. | ||
| 15 | (landmark--distance): Rename from `distance'. | ||
| 16 | (landmark-calc-distance-of-robot-from): Rename from | ||
| 17 | calc-distance-of-robot-from. | ||
| 18 | (landmark-calc-smell-internal): Rename from calc-smell-internal. | ||
| 19 | |||
| 1 | 2014-06-25 Dmitry Antipov <dmantipov@yandex.ru> | 20 | 2014-06-25 Dmitry Antipov <dmantipov@yandex.ru> |
| 2 | 21 | ||
| 3 | * files.el (dir-locals-find-file, file-relative-name): | 22 | * files.el (dir-locals-find-file, file-relative-name): |
diff --git a/lisp/play/landmark.el b/lisp/play/landmark.el index f1bd87ce847..c1175944917 100644 --- a/lisp/play/landmark.el +++ b/lisp/play/landmark.el | |||
| @@ -1,10 +1,11 @@ | |||
| 1 | ;;; landmark.el --- neural-network robot that learns landmarks | 1 | ;;; landmark.el --- Neural-network robot that learns landmarks -*- lexical-binding:t -*- |
| 2 | 2 | ||
| 3 | ;; Copyright (C) 1996-1997, 2000-2014 Free Software Foundation, Inc. | 3 | ;; Copyright (C) 1996-1997, 2000-2014 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | ;; Author: Terrence Brannon (was: <brannon@rana.usc.edu>) | 5 | ;; Author: Terrence Brannon (was: <brannon@rana.usc.edu>) |
| 6 | ;; Created: December 16, 1996 - first release to usenet | 6 | ;; Created: December 16, 1996 - first release to usenet |
| 7 | ;; Keywords: games, neural network, adaptive search, chemotaxis | 7 | ;; Keywords: games, neural network, adaptive search, chemotaxis |
| 8 | ;; Version: 1.0 | ||
| 8 | 9 | ||
| 9 | ;; This file is part of GNU Emacs. | 10 | ;; This file is part of GNU Emacs. |
| 10 | 11 | ||
| @@ -225,9 +226,6 @@ | |||
| 225 | 'landmark-font-lock-face-X))) | 226 | 'landmark-font-lock-face-X))) |
| 226 | "Font lock rules for Landmark.") | 227 | "Font lock rules for Landmark.") |
| 227 | 228 | ||
| 228 | (put 'landmark-mode 'front-sticky | ||
| 229 | (put 'landmark-mode 'rear-nonsticky '(intangible))) | ||
| 230 | (put 'landmark-mode 'intangible 1) | ||
| 231 | ;; This one is for when they set view-read-only to t: Landmark cannot | 229 | ;; This one is for when they set view-read-only to t: Landmark cannot |
| 232 | ;; allow View Mode to be activated in its buffer. | 230 | ;; allow View Mode to be activated in its buffer. |
| 233 | (define-derived-mode landmark-mode special-mode "Lm" | 231 | (define-derived-mode landmark-mode special-mode "Lm" |
| @@ -244,7 +242,8 @@ Entry to this mode calls the value of `landmark-mode-hook' if that value | |||
| 244 | is non-nil. One interesting value is `turn-on-font-lock'." | 242 | is non-nil. One interesting value is `turn-on-font-lock'." |
| 245 | (landmark-display-statistics) | 243 | (landmark-display-statistics) |
| 246 | (setq-local font-lock-defaults '(landmark-font-lock-keywords t)) | 244 | (setq-local font-lock-defaults '(landmark-font-lock-keywords t)) |
| 247 | (setq buffer-read-only t)) | 245 | (setq buffer-read-only t) |
| 246 | (add-hook 'post-command-hook #'landmark--intangible nil t)) | ||
| 248 | 247 | ||
| 249 | 248 | ||
| 250 | ;;;_ + THE SCORE TABLE. | 249 | ;;;_ + THE SCORE TABLE. |
| @@ -679,8 +678,8 @@ along the DX, DY direction, considering that DVAL has been added on SQUARE." | |||
| 679 | (landmark-prompt-for-other-game)) | 678 | (landmark-prompt-for-other-game)) |
| 680 | (t | 679 | (t |
| 681 | (message "Let me think...") | 680 | (message "Let me think...") |
| 682 | (let (square score) | 681 | (let ((square (landmark-strongest-square)) |
| 683 | (setq square (landmark-strongest-square)) | 682 | score) |
| 684 | (cond ((null square) | 683 | (cond ((null square) |
| 685 | (landmark-terminate-game 'nobody-won)) | 684 | (landmark-terminate-game 'nobody-won)) |
| 686 | (t | 685 | (t |
| @@ -722,8 +721,7 @@ along the DX, DY direction, considering that DVAL has been added on SQUARE." | |||
| 722 | (min (max (/ (+ (- (cdr click) | 721 | (min (max (/ (+ (- (cdr click) |
| 723 | landmark-y-offset | 722 | landmark-y-offset |
| 724 | 1) | 723 | 1) |
| 725 | (let ((inhibit-point-motion-hooks t)) | 724 | (count-lines (point-min) (window-start)) |
| 726 | (count-lines 1 (window-start))) | ||
| 727 | landmark-square-height | 725 | landmark-square-height |
| 728 | (% landmark-square-height 2) | 726 | (% landmark-square-height 2) |
| 729 | (/ landmark-square-height 2)) | 727 | (/ landmark-square-height 2)) |
| @@ -749,8 +747,8 @@ If the game is finished, this command requests for another game." | |||
| 749 | ((not landmark-game-in-progress) | 747 | ((not landmark-game-in-progress) |
| 750 | (landmark-prompt-for-other-game)) | 748 | (landmark-prompt-for-other-game)) |
| 751 | (t | 749 | (t |
| 752 | (let (square score) | 750 | (let ((square (landmark-point-square)) |
| 753 | (setq square (landmark-point-square)) | 751 | score) |
| 754 | (cond ((null square) | 752 | (cond ((null square) |
| 755 | (error "Your point is not on a square. Retry!")) | 753 | (error "Your point is not on a square. Retry!")) |
| 756 | ((not (zerop (aref landmark-board square))) | 754 | ((not (zerop (aref landmark-board square))) |
| @@ -844,16 +842,15 @@ If the game is finished, this command requests for another game." | |||
| 844 | 842 | ||
| 845 | (defun landmark-point-y () | 843 | (defun landmark-point-y () |
| 846 | "Return the board row where point is." | 844 | "Return the board row where point is." |
| 847 | (let ((inhibit-point-motion-hooks t)) | 845 | (1+ (/ (- (count-lines (point-min) (point)) |
| 848 | (1+ (/ (- (count-lines 1 (point)) landmark-y-offset (if (bolp) 0 1)) | 846 | landmark-y-offset (if (bolp) 0 1)) |
| 849 | landmark-square-height)))) | 847 | landmark-square-height))) |
| 850 | 848 | ||
| 851 | (defun landmark-point-square () | 849 | (defun landmark-point-square () |
| 852 | "Return the index of the square point is on." | 850 | "Return the index of the square point is on." |
| 853 | (let ((inhibit-point-motion-hooks t)) | ||
| 854 | (landmark-xy-to-index (1+ (/ (- (current-column) landmark-x-offset) | 851 | (landmark-xy-to-index (1+ (/ (- (current-column) landmark-x-offset) |
| 855 | landmark-square-width)) | 852 | landmark-square-width)) |
| 856 | (landmark-point-y)))) | 853 | (landmark-point-y))) |
| 857 | 854 | ||
| 858 | (defun landmark-goto-square (index) | 855 | (defun landmark-goto-square (index) |
| 859 | "Move point to square number INDEX." | 856 | "Move point to square number INDEX." |
| @@ -861,23 +858,21 @@ If the game is finished, this command requests for another game." | |||
| 861 | 858 | ||
| 862 | (defun landmark-goto-xy (x y) | 859 | (defun landmark-goto-xy (x y) |
| 863 | "Move point to square at X, Y coords." | 860 | "Move point to square at X, Y coords." |
| 864 | (let ((inhibit-point-motion-hooks t)) | ||
| 865 | (goto-char (point-min)) | 861 | (goto-char (point-min)) |
| 866 | (forward-line (+ landmark-y-offset (* landmark-square-height (1- y))))) | 862 | (forward-line (+ landmark-y-offset (* landmark-square-height (1- y)))) |
| 867 | (move-to-column (+ landmark-x-offset (* landmark-square-width (1- x))))) | 863 | (move-to-column (+ landmark-x-offset (* landmark-square-width (1- x))))) |
| 868 | 864 | ||
| 869 | (defun landmark-plot-square (square value) | 865 | (defun landmark-plot-square (square value) |
| 870 | "Draw 'X', 'O' or '.' on SQUARE depending on VALUE, leave point there." | 866 | "Draw 'X', 'O' or '.' on SQUARE depending on VALUE, leave point there." |
| 871 | (or (= value 1) | 867 | (or (= value 1) |
| 872 | (landmark-goto-square square)) | 868 | (landmark-goto-square square)) |
| 873 | (let ((inhibit-read-only t) | 869 | (let ((inhibit-read-only t)) |
| 874 | (inhibit-point-motion-hooks t)) | 870 | (insert (cond ((= value 1) ?.) |
| 875 | (insert-and-inherit (cond ((= value 1) ?.) | 871 | ((= value 2) ?N) |
| 876 | ((= value 2) ?N) | 872 | ((= value 3) ?S) |
| 877 | ((= value 3) ?S) | 873 | ((= value 4) ?E) |
| 878 | ((= value 4) ?E) | 874 | ((= value 5) ?W) |
| 879 | ((= value 5) ?W) | 875 | ((= value 6) ?^))) |
| 880 | ((= value 6) ?^))) | ||
| 881 | 876 | ||
| 882 | (and (zerop value) | 877 | (and (zerop value) |
| 883 | (add-text-properties (1- (point)) (point) | 878 | (add-text-properties (1- (point)) (point) |
| @@ -892,8 +887,7 @@ mouse-1: get robot moving, mouse-2: play on this square"))) | |||
| 892 | "Display an N by M Landmark board." | 887 | "Display an N by M Landmark board." |
| 893 | (buffer-disable-undo (current-buffer)) | 888 | (buffer-disable-undo (current-buffer)) |
| 894 | (let ((inhibit-read-only t) | 889 | (let ((inhibit-read-only t) |
| 895 | (point 1) opoint | 890 | (point (point-min)) opoint |
| 896 | (intangible t) | ||
| 897 | (i m) j x) | 891 | (i m) j x) |
| 898 | ;; Try to minimize number of chars (because of text properties) | 892 | ;; Try to minimize number of chars (because of text properties) |
| 899 | (setq tab-width | 893 | (setq tab-width |
| @@ -902,7 +896,7 @@ mouse-1: get robot moving, mouse-2: play on this square"))) | |||
| 902 | (max (/ (+ (% landmark-x-offset landmark-square-width) | 896 | (max (/ (+ (% landmark-x-offset landmark-square-width) |
| 903 | landmark-square-width 1) 2) 2))) | 897 | landmark-square-width 1) 2) 2))) |
| 904 | (erase-buffer) | 898 | (erase-buffer) |
| 905 | (newline landmark-y-offset) | 899 | (insert-char ?\n landmark-y-offset) |
| 906 | (while (progn | 900 | (while (progn |
| 907 | (setq j n | 901 | (setq j n |
| 908 | x (- landmark-x-offset landmark-square-width)) | 902 | x (- landmark-x-offset landmark-square-width)) |
| @@ -910,9 +904,7 @@ mouse-1: get robot moving, mouse-2: play on this square"))) | |||
| 910 | (insert-char ?\t (/ (- (setq x (+ x landmark-square-width)) | 904 | (insert-char ?\t (/ (- (setq x (+ x landmark-square-width)) |
| 911 | (current-column)) | 905 | (current-column)) |
| 912 | tab-width)) | 906 | tab-width)) |
| 913 | (insert-char ? (- x (current-column))) | 907 | (insert-char ?\s (- x (current-column))) |
| 914 | (if (setq intangible (not intangible)) | ||
| 915 | (put-text-property point (point) 'intangible 2)) | ||
| 916 | (and (zerop j) | 908 | (and (zerop j) |
| 917 | (= i (- m 2)) | 909 | (= i (- m 2)) |
| 918 | (progn | 910 | (progn |
| @@ -929,14 +921,7 @@ mouse-1: get robot moving, mouse-2: play on this square"))) | |||
| 929 | (if (= i (1- m)) | 921 | (if (= i (1- m)) |
| 930 | (setq opoint point)) | 922 | (setq opoint point)) |
| 931 | (insert-char ?\n landmark-square-height)) | 923 | (insert-char ?\n landmark-square-height)) |
| 932 | (or (eq (char-after 1) ?.) | 924 | (insert-char ?\n)) |
| 933 | (put-text-property 1 2 'point-entered | ||
| 934 | (lambda (_x _y) (if (bobp) (forward-char))))) | ||
| 935 | (or intangible | ||
| 936 | (put-text-property point (point) 'intangible 2)) | ||
| 937 | (put-text-property point (point) 'point-entered | ||
| 938 | (lambda (_x _y) (if (eobp) (backward-char)))) | ||
| 939 | (put-text-property (point-min) (point) 'category 'landmark-mode)) | ||
| 940 | (landmark-goto-xy (/ (1+ n) 2) (/ (1+ m) 2)) ; center of the board | 925 | (landmark-goto-xy (/ (1+ n) 2) (/ (1+ m) 2)) ; center of the board |
| 941 | (sit-for 0)) ; Display NOW | 926 | (sit-for 0)) ; Display NOW |
| 942 | 927 | ||
| @@ -998,8 +983,7 @@ mouse-1: get robot moving, mouse-2: play on this square"))) | |||
| 998 | "Cross every square between SQUARE1 and SQUARE2 in the DX, DY direction." | 983 | "Cross every square between SQUARE1 and SQUARE2 in the DX, DY direction." |
| 999 | (save-excursion ; Not moving point from last square | 984 | (save-excursion ; Not moving point from last square |
| 1000 | (let ((depl (landmark-xy-to-index dx dy)) | 985 | (let ((depl (landmark-xy-to-index dx dy)) |
| 1001 | (inhibit-read-only t) | 986 | (inhibit-read-only t)) |
| 1002 | (inhibit-point-motion-hooks t)) | ||
| 1003 | ;; WARNING: this function assumes DEPL > 0 and SQUARE2 > SQUARE1 | 987 | ;; WARNING: this function assumes DEPL > 0 and SQUARE2 > SQUARE1 |
| 1004 | (while (/= square1 square2) | 988 | (while (/= square1 square2) |
| 1005 | (landmark-goto-square square1) | 989 | (landmark-goto-square square1) |
| @@ -1018,20 +1002,40 @@ mouse-1: get robot moving, mouse-2: play on this square"))) | |||
| 1018 | (setq landmark-n (1+ landmark-n)) | 1002 | (setq landmark-n (1+ landmark-n)) |
| 1019 | (forward-line 1) | 1003 | (forward-line 1) |
| 1020 | (indent-to column) | 1004 | (indent-to column) |
| 1021 | (insert-and-inherit ?|)))) | 1005 | (insert ?|)))) |
| 1022 | ((= dx -1) ; 1st Diagonal | 1006 | ((= dx -1) ; 1st Diagonal |
| 1023 | (indent-to (prog1 (- (current-column) (/ landmark-square-width 2)) | 1007 | (indent-to (prog1 (- (current-column) (/ landmark-square-width 2)) |
| 1024 | (forward-line (/ landmark-square-height 2)))) | 1008 | (forward-line (/ landmark-square-height 2)))) |
| 1025 | (insert-and-inherit ?/)) | 1009 | (insert ?/)) |
| 1026 | (t ; 2nd Diagonal | 1010 | (t ; 2nd Diagonal |
| 1027 | (indent-to (prog1 (+ (current-column) (/ landmark-square-width 2)) | 1011 | (indent-to (prog1 (+ (current-column) (/ landmark-square-width 2)) |
| 1028 | (forward-line (/ landmark-square-height 2)))) | 1012 | (forward-line (/ landmark-square-height 2)))) |
| 1029 | (insert-and-inherit ?\\)))))) | 1013 | (insert ?\\)))))) |
| 1030 | (sit-for 0)) ; Display NOW | 1014 | (sit-for 0)) ; Display NOW |
| 1031 | 1015 | ||
| 1032 | 1016 | ||
| 1033 | ;;;_ + CURSOR MOTION. | 1017 | ;;;_ + CURSOR MOTION. |
| 1034 | 1018 | ||
| 1019 | (defvar-local landmark--last-pos 0) | ||
| 1020 | |||
| 1021 | (defconst landmark--intangible-chars "- \t\n|/\\\\") | ||
| 1022 | |||
| 1023 | (defun landmark--intangible () | ||
| 1024 | (when (or (eobp) | ||
| 1025 | (save-excursion | ||
| 1026 | (not (zerop (skip-chars-forward landmark--intangible-chars))))) | ||
| 1027 | (if (<= landmark--last-pos (point)) ;Moving forward. | ||
| 1028 | (progn | ||
| 1029 | (skip-chars-forward landmark--intangible-chars) | ||
| 1030 | (when (eobp) | ||
| 1031 | (skip-chars-backward landmark--intangible-chars) | ||
| 1032 | (forward-char -1))) | ||
| 1033 | (skip-chars-backward landmark--intangible-chars) | ||
| 1034 | (if (bobp) | ||
| 1035 | (skip-chars-forward landmark--intangible-chars) | ||
| 1036 | (forward-char -1)))) | ||
| 1037 | (setq landmark--last-pos (point))) | ||
| 1038 | |||
| 1035 | ;; previous-line and next-line don't work right with intangible newlines | 1039 | ;; previous-line and next-line don't work right with intangible newlines |
| 1036 | (defun landmark-move-down () | 1040 | (defun landmark-move-down () |
| 1037 | "Move point down one row on the Landmark board." | 1041 | "Move point down one row on the Landmark board." |
| @@ -1138,7 +1142,7 @@ because it is overwritten by \"One moment please\"." | |||
| 1138 | 1142 | ||
| 1139 | 1143 | ||
| 1140 | (defun landmark-print-distance () | 1144 | (defun landmark-print-distance () |
| 1141 | (insert (format "tree: %S \n" (calc-distance-of-robot-from 'landmark-tree))) | 1145 | (insert (format "tree: %S \n" (landmark-calc-distance-of-robot-from 'landmark-tree))) |
| 1142 | (mapc 'landmark-print-distance-int landmark-directions)) | 1146 | (mapc 'landmark-print-distance-int landmark-directions)) |
| 1143 | 1147 | ||
| 1144 | 1148 | ||
| @@ -1303,9 +1307,9 @@ After this limit is reached, landmark-random-move is called to push him out of i | |||
| 1303 | ;;;_ - landmark-plot-internal (sym) | 1307 | ;;;_ - landmark-plot-internal (sym) |
| 1304 | (defun landmark-plot-internal (sym) | 1308 | (defun landmark-plot-internal (sym) |
| 1305 | (landmark-plot-square (landmark-xy-to-index | 1309 | (landmark-plot-square (landmark-xy-to-index |
| 1306 | (get sym 'x) | 1310 | (get sym 'x) |
| 1307 | (get sym 'y)) | 1311 | (get sym 'y)) |
| 1308 | (get sym 'sym))) | 1312 | (get sym 'sym))) |
| 1309 | ;;;_ - landmark-plot-landmarks () | 1313 | ;;;_ - landmark-plot-landmarks () |
| 1310 | (defun landmark-plot-landmarks () | 1314 | (defun landmark-plot-landmarks () |
| 1311 | (setq landmark-cx (/ landmark-board-width 2)) | 1315 | (setq landmark-cx (/ landmark-board-width 2)) |
| @@ -1336,26 +1340,24 @@ After this limit is reached, landmark-random-move is called to push him out of i | |||
| 1336 | 1340 | ||
| 1337 | 1341 | ||
| 1338 | ;;;_ + Distance-calculation functions | 1342 | ;;;_ + Distance-calculation functions |
| 1339 | ;;;_ - square (a) | ||
| 1340 | (defun square (a) | ||
| 1341 | (* a a)) | ||
| 1342 | 1343 | ||
| 1343 | ;;;_ - distance (x x0 y y0) | 1344 | ;;;_ - distance (x x0 y y0) |
| 1344 | (defun distance (x x0 y y0) | 1345 | (defun landmark--distance (x x0 y y0) |
| 1345 | (sqrt (+ (square (- x x0)) (square (- y y0))))) | 1346 | (let ((dx (- x x0)) (dy (- y y0))) |
| 1347 | (sqrt (+ (* dx dx) (* dy dy))))) | ||
| 1346 | 1348 | ||
| 1347 | ;;;_ - calc-distance-of-robot-from (direction) | 1349 | ;;;_ - landmark-calc-distance-of-robot-from (direction) |
| 1348 | (defun calc-distance-of-robot-from (direction) | 1350 | (defun landmark-calc-distance-of-robot-from (direction) |
| 1349 | (put direction 'distance | 1351 | (put direction 'distance |
| 1350 | (distance (get direction 'x) | 1352 | (landmark--distance (get direction 'x) |
| 1351 | (landmark-index-to-x (landmark-point-square)) | 1353 | (landmark-index-to-x (landmark-point-square)) |
| 1352 | (get direction 'y) | 1354 | (get direction 'y) |
| 1353 | (landmark-index-to-y (landmark-point-square))))) | 1355 | (landmark-index-to-y (landmark-point-square))))) |
| 1354 | 1356 | ||
| 1355 | ;;;_ - calc-smell-internal (sym) | 1357 | ;;;_ - landmark-calc-smell-internal (sym) |
| 1356 | (defun calc-smell-internal (sym) | 1358 | (defun landmark-calc-smell-internal (sym) |
| 1357 | (let ((r (get sym 'r)) | 1359 | (let ((r (get sym 'r)) |
| 1358 | (d (calc-distance-of-robot-from sym))) | 1360 | (d (landmark-calc-distance-of-robot-from sym))) |
| 1359 | (if (> (* 0.5 (- 1 (/ d r))) 0) | 1361 | (if (> (* 0.5 (- 1 (/ d r))) 0) |
| 1360 | (* 0.5 (- 1 (/ d r))) | 1362 | (* 0.5 (- 1 (/ d r))) |
| 1361 | 0))) | 1363 | 0))) |
| @@ -1402,12 +1404,12 @@ After this limit is reached, landmark-random-move is called to push him out of i | |||
| 1402 | 1404 | ||
| 1403 | (defun landmark-calc-current-smells () | 1405 | (defun landmark-calc-current-smells () |
| 1404 | (mapc (lambda (direction) | 1406 | (mapc (lambda (direction) |
| 1405 | (put direction 'smell (calc-smell-internal direction))) | 1407 | (put direction 'smell (landmark-calc-smell-internal direction))) |
| 1406 | landmark-directions)) | 1408 | landmark-directions)) |
| 1407 | 1409 | ||
| 1408 | (defun landmark-calc-payoff () | 1410 | (defun landmark-calc-payoff () |
| 1409 | (put 'z 't-1 (get 'z 't)) | 1411 | (put 'z 't-1 (get 'z 't)) |
| 1410 | (put 'z 't (calc-smell-internal 'landmark-tree)) | 1412 | (put 'z 't (landmark-calc-smell-internal 'landmark-tree)) |
| 1411 | (if (= (- (get 'z 't) (get 'z 't-1)) 0.0) | 1413 | (if (= (- (get 'z 't) (get 'z 't-1)) 0.0) |
| 1412 | (cl-incf landmark-no-payoff) | 1414 | (cl-incf landmark-no-payoff) |
| 1413 | (setf landmark-no-payoff 0))) | 1415 | (setf landmark-no-payoff 0))) |
| @@ -1448,8 +1450,9 @@ After this limit is reached, landmark-random-move is called to push him out of i | |||
| 1448 | (message "e-w normalization")))) | 1450 | (message "e-w normalization")))) |
| 1449 | 1451 | ||
| 1450 | (mapc (lambda (pair) | 1452 | (mapc (lambda (pair) |
| 1451 | (if (> (get (car pair) 'y_t) 0) | 1453 | (when (> (get (car pair) 'y_t) 0) |
| 1452 | (funcall (car (cdr pair))))) | 1454 | (funcall (car (cdr pair))) |
| 1455 | (landmark--intangible))) | ||
| 1453 | '( | 1456 | '( |
| 1454 | (landmark-n landmark-move-up) | 1457 | (landmark-n landmark-move-up) |
| 1455 | (landmark-s landmark-move-down) | 1458 | (landmark-s landmark-move-down) |
| @@ -1471,7 +1474,7 @@ After this limit is reached, landmark-random-move is called to push him out of i | |||
| 1471 | 1474 | ||
| 1472 | (defun landmark-amble-robot () | 1475 | (defun landmark-amble-robot () |
| 1473 | (interactive) | 1476 | (interactive) |
| 1474 | (while (> (calc-distance-of-robot-from 'landmark-tree) 0) | 1477 | (while (> (landmark-calc-distance-of-robot-from 'landmark-tree) 0) |
| 1475 | 1478 | ||
| 1476 | (landmark-store-old-y_t) | 1479 | (landmark-store-old-y_t) |
| 1477 | (landmark-calc-current-smells) | 1480 | (landmark-calc-current-smells) |
| @@ -1505,8 +1508,7 @@ If the game is finished, this command requests for another game." | |||
| 1505 | ((not landmark-game-in-progress) | 1508 | ((not landmark-game-in-progress) |
| 1506 | (landmark-prompt-for-other-game)) | 1509 | (landmark-prompt-for-other-game)) |
| 1507 | (t | 1510 | (t |
| 1508 | (let (square) | 1511 | (let ((square (landmark-point-square))) |
| 1509 | (setq square (landmark-point-square)) | ||
| 1510 | (cond ((null square) | 1512 | (cond ((null square) |
| 1511 | (error "Your point is not on a square. Retry!")) | 1513 | (error "Your point is not on a square. Retry!")) |
| 1512 | ((not (zerop (aref landmark-board square))) | 1514 | ((not (zerop (aref landmark-board square))) |
| @@ -1517,7 +1519,7 @@ If the game is finished, this command requests for another game." | |||
| 1517 | 1519 | ||
| 1518 | (landmark-store-old-y_t) | 1520 | (landmark-store-old-y_t) |
| 1519 | (landmark-calc-current-smells) | 1521 | (landmark-calc-current-smells) |
| 1520 | (put 'z 't (calc-smell-internal 'landmark-tree)) | 1522 | (put 'z 't (landmark-calc-smell-internal 'landmark-tree)) |
| 1521 | 1523 | ||
| 1522 | (landmark-random-move) | 1524 | (landmark-random-move) |
| 1523 | 1525 | ||
| @@ -1590,7 +1592,9 @@ If the game is finished, this command requests for another game." | |||
| 1590 | ;; distance on scent. | 1592 | ;; distance on scent. |
| 1591 | 1593 | ||
| 1592 | (defun landmark-set-landmark-signal-strengths () | 1594 | (defun landmark-set-landmark-signal-strengths () |
| 1593 | (setq landmark-tree-r (* (sqrt (+ (square landmark-cx) (square landmark-cy))) 1.5)) | 1595 | (setq landmark-tree-r (* (sqrt (+ (* landmark-cx landmark-cx) |
| 1596 | (* landmark-cy landmark-cy))) | ||
| 1597 | 1.5)) | ||
| 1594 | (mapc (lambda (direction) | 1598 | (mapc (lambda (direction) |
| 1595 | (put direction 'r (* landmark-cx 1.1))) | 1599 | (put direction 'r (* landmark-cx 1.1))) |
| 1596 | landmark-ew) | 1600 | landmark-ew) |
| @@ -1609,7 +1613,7 @@ If the game is finished, this command requests for another game." | |||
| 1609 | "Run 100 Landmark games, each time saving the weights from the previous game." | 1613 | "Run 100 Landmark games, each time saving the weights from the previous game." |
| 1610 | (interactive) | 1614 | (interactive) |
| 1611 | (landmark 1) | 1615 | (landmark 1) |
| 1612 | (dotimes (scratch-var 100) | 1616 | (dotimes (_ 100) |
| 1613 | (landmark 2))) | 1617 | (landmark 2))) |
| 1614 | 1618 | ||
| 1615 | ;;;###autoload | 1619 | ;;;###autoload |