From a0451be18b2581f5288e1123ee7bbd2aabccbe52 Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Wed, 10 Feb 2021 01:23:41 +0100 Subject: Use lexical-binding in almost all of play/*.el * lisp/play/5x5.el: Use lexical-binding. (5x5-draw-grid-end, 5x5-draw-grid, 5x5-solver) (5x5-solve-suggest): Silence byte-compiler. * lisp/play/cookie1.el: Use lexical-binding. (cookie-shuffle-vector, cookie-apropos): Silence byte-compiler. * lisp/play/zone.el: Use lexical-binding. (zone): Convert lambda to proper lexical closure. (zone-replace-char, zone-fill-out-screen): Silence byte-compiler. * lisp/play/blackbox.el: * lisp/play/doctor.el: * lisp/play/gametree.el: * lisp/play/hanoi.el: Use lexical-binding. * test/lisp/play/cookie1-resources/cookies: * test/lisp/play/cookie1-tests.el: New files. --- lisp/play/5x5.el | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) (limited to 'lisp/play/5x5.el') diff --git a/lisp/play/5x5.el b/lisp/play/5x5.el index 05e61dfe401..891a5f6cbaa 100644 --- a/lisp/play/5x5.el +++ b/lisp/play/5x5.el @@ -1,4 +1,4 @@ -;;; 5x5.el --- simple little puzzle game +;;; 5x5.el --- simple little puzzle game -*- lexical-binding: t -*- ;; Copyright (C) 1999-2021 Free Software Foundation, Inc. @@ -289,7 +289,7 @@ Quit current game \\[5x5-quit-game]" (defun 5x5-draw-grid-end () "Draw the top/bottom of the grid." (insert "+") - (dotimes (x 5x5-grid-size) + (dotimes (_ 5x5-grid-size) (insert "-" (make-string 5x5-x-scale ?-))) (insert "-+ ")) @@ -297,11 +297,11 @@ Quit current game \\[5x5-quit-game]" "Draw the grids GRIDS into the current buffer." (let ((inhibit-read-only t) grid-org) (erase-buffer) - (dolist (grid grids) (5x5-draw-grid-end)) + (dolist (_ grids) (5x5-draw-grid-end)) (insert "\n") (setq grid-org (point)) (dotimes (y 5x5-grid-size) - (dotimes (lines 5x5-y-scale) + (dotimes (_lines 5x5-y-scale) (dolist (grid grids) (dotimes (x 5x5-grid-size) (insert (if (zerop x) "| " " ") @@ -331,7 +331,7 @@ Quit current game \\[5x5-quit-game]" (forward-char (1+ 5x5-x-scale)))) (forward-line 5x5-y-scale)))) (setq 5x5-solver-output nil))) - (dolist (grid grids) (5x5-draw-grid-end)) + (dolist (_grid grids) (5x5-draw-grid-end)) (insert "\n") (insert (format "On: %d Moves: %d" (5x5-grid-value (car grids)) 5x5-moves)))) @@ -475,11 +475,11 @@ position." "Convert a grid matrix GRID-MATRIX in Calc format to a grid in 5x5 format. See function `5x5-grid-to-vec'." (apply - 'vector + #'vector (mapcar (lambda (x) (apply - 'vector + #'vector (mapcar (lambda (y) (/= (cadr y) 0)) (cdr x)))) @@ -503,7 +503,9 @@ position." Log a matrix VALUE of (mod B 2) forms, only B is output and Scilab matrix notation is used. VALUE is returned so that it is easy to log a value with minimal rewrite of code." - (when (buffer-live-p 5x5-log-buffer) + (when (buffer-live-p 5x5-log-buffer) + (defvar calc-matrix-brackets) + (defvar calc-vector-commas) (let* ((unpacked-value (math-map-vec (lambda (row) (math-map-vec 'cadr row)) @@ -515,7 +517,7 @@ easy to log a value with minimal rewrite of code." (insert name ?= value-to-log ?\n)))) value)) (defsubst 5x5-log-init ()) - (defsubst 5x5-log (name value) value))) + (defsubst 5x5-log (_name value) value))) (declare-function math-map-vec "calc-vec" (f a)) (declare-function math-sub "calc" (a b)) @@ -533,6 +535,10 @@ easy to log a value with minimal rewrite of code." (declare-function calcFunc-mcol "calc-vec" (mat n)) (declare-function calcFunc-vconcat "calc-vec" (a b)) (declare-function calcFunc-index "calc-vec" (n &optional start incr)) +(defvar calc-word-size) +(defvar calc-leading-zeros) +(defvar calc-number-radix) +(defvar calc-command-flags) (defun 5x5-solver (grid) "Return a list of solutions for GRID. @@ -671,16 +677,16 @@ Solutions are sorted from least to greatest Hamming weight." (5x5-log "cb" (math-mul inv-base-change targetv))); CB - (row-1 (math-make-intv 3 1 transferm-kernel-size)) ; 1..2 + ;; (row-1 (math-make-intv 3 1 transferm-kernel-size)) ; 1..2 (row-2 (math-make-intv 1 transferm-kernel-size grid-size-squared)); 3..25 (col-1 (math-make-intv 3 1 (- grid-size-squared transferm-kernel-size))); 1..23 - (col-2 (math-make-intv 1 (- grid-size-squared - transferm-kernel-size) - grid-size-squared)); 24..25 - (ctransferm-1-: (calcFunc-mrow ctransferm row-1)) - (ctransferm-1-1 (calcFunc-mcol ctransferm-1-: col-1)) + ;; (col-2 (math-make-intv 1 (- grid-size-squared + ;; transferm-kernel-size) + ;; grid-size-squared)) ; 24..25 + ;; (ctransferm-1-: (calcFunc-mrow ctransferm row-1)) + ;; (ctransferm-1-1 (calcFunc-mcol ctransferm-1-: col-1)) ;; By construction ctransferm-:-2 = 0, so ctransferm-1-2 = 0 ;; and ctransferm-2-2 = 0. @@ -696,8 +702,8 @@ Solutions are sorted from least to greatest Hamming weight." ;; ;;(ctransferm-2-2 (calcFunc-mcol ctransferm-2-: col-2)) - (ctarget-1 (calcFunc-mrow ctarget row-1)) - (ctarget-2 (calcFunc-mrow ctarget row-2)) + ;; (ctarget-1 (calcFunc-mrow ctarget row-1)) + (ctarget-2 (calcFunc-mrow ctarget row-2)) ;; ctarget-1(2x1) = ctransferm-1-1(2x23) *cx-1(23x1) ;; + ctransferm-1-2(2x2) *cx-2(2x1); @@ -770,7 +776,7 @@ Solutions are sorted from least to greatest Hamming weight." (message "5x5 Solution computation done.") solution-list))) -(defun 5x5-solve-suggest (&optional n) +(defun 5x5-solve-suggest (&optional _n) "Suggest to the user where to click. Argument N is ignored." -- cgit v1.2.3 From 1baadbe060f392253bb4a54ddbdd3870f1d08459 Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Sun, 14 Feb 2021 16:18:39 +0100 Subject: Mark up 5x5 for interactive mode --- lisp/play/5x5.el | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) (limited to 'lisp/play/5x5.el') diff --git a/lisp/play/5x5.el b/lisp/play/5x5.el index 891a5f6cbaa..3630c199bc4 100644 --- a/lisp/play/5x5.el +++ b/lisp/play/5x5.el @@ -179,6 +179,7 @@ GRID is the grid of positions to click.") (define-derived-mode 5x5-mode special-mode "5x5" "A mode for playing `5x5'." + :interactive nil (setq buffer-read-only t truncate-lines t) (buffer-disable-undo)) @@ -221,7 +222,7 @@ Quit current game \\[5x5-quit-game]" (defun 5x5-new-game () "Start a new game of `5x5'." - (interactive) + (interactive nil 5x5-mode) (when (if (called-interactively-p 'interactive) (5x5-y-or-n-p "Start a new game? ") t) (setq 5x5-x-pos (/ 5x5-grid-size 2) @@ -234,7 +235,7 @@ Quit current game \\[5x5-quit-game]" (defun 5x5-quit-game () "Quit the current game of `5x5'." - (interactive) + (interactive nil 5x5-mode) (kill-buffer 5x5-buffer-name)) (defun 5x5-make-new-grid () @@ -782,7 +783,7 @@ Solutions are sorted from least to greatest Hamming weight." Argument N is ignored." ;; For the time being n is ignored, the idea was to use some numeric ;; argument to show a limited amount of positions. - (interactive "P") + (interactive "P" 5x5-mode) (5x5-log-init) (let ((solutions (5x5-solver 5x5-grid))) (setq 5x5-solver-output @@ -805,7 +806,7 @@ list. The list of solution is ordered by number of strokes, so rotating left just after calling `5x5-solve-suggest' will show the solution with second least number of strokes, while rotating right will show the solution with greatest number of strokes." - (interactive "P") + (interactive "P" 5x5-mode) (let ((len (length 5x5-solver-output))) (when (>= len 3) (setq n (if (integerp n) n 1) @@ -839,7 +840,7 @@ right will show the solution with greatest number of strokes." If N is not supplied, rotate by 1. Similar to function `5x5-solve-rotate-left' except that rotation is right instead of lest." - (interactive "P") + (interactive "P" 5x5-mode) (setq n (if (integerp n) (- n) -1)) @@ -851,7 +852,7 @@ lest." (defun 5x5-flip-current () "Make a move on the current cursor location." - (interactive) + (interactive nil 5x5-mode) (setq 5x5-grid (5x5-make-move 5x5-grid 5x5-y-pos 5x5-x-pos)) (5x5-made-move) (unless 5x5-cracking @@ -863,61 +864,61 @@ lest." (defun 5x5-up () "Move up." - (interactive) + (interactive nil 5x5-mode) (unless (zerop 5x5-y-pos) (cl-decf 5x5-y-pos) (5x5-position-cursor))) (defun 5x5-down () "Move down." - (interactive) + (interactive nil 5x5-mode) (unless (= 5x5-y-pos (1- 5x5-grid-size)) (cl-incf 5x5-y-pos) (5x5-position-cursor))) (defun 5x5-left () "Move left." - (interactive) + (interactive nil 5x5-mode) (unless (zerop 5x5-x-pos) (cl-decf 5x5-x-pos) (5x5-position-cursor))) (defun 5x5-right () "Move right." - (interactive) + (interactive nil 5x5-mode) (unless (= 5x5-x-pos (1- 5x5-grid-size)) (cl-incf 5x5-x-pos) (5x5-position-cursor))) (defun 5x5-bol () "Move to beginning of line." - (interactive) + (interactive nil 5x5-mode) (setq 5x5-x-pos 0) (5x5-position-cursor)) (defun 5x5-eol () "Move to end of line." - (interactive) + (interactive nil 5x5-mode) (setq 5x5-x-pos (1- 5x5-grid-size)) (5x5-position-cursor)) (defun 5x5-first () "Move to the first cell." - (interactive) + (interactive nil 5x5-mode) (setq 5x5-x-pos 0 5x5-y-pos 0) (5x5-position-cursor)) (defun 5x5-last () "Move to the last cell." - (interactive) + (interactive nil 5x5-mode) (setq 5x5-x-pos (1- 5x5-grid-size) 5x5-y-pos (1- 5x5-grid-size)) (5x5-position-cursor)) (defun 5x5-randomize () "Randomize the grid." - (interactive) + (interactive nil 5x5-mode) (when (5x5-y-or-n-p "Start a new game with a random grid? ") (setq 5x5-x-pos (/ 5x5-grid-size 2) 5x5-y-pos (/ 5x5-grid-size 2) -- cgit v1.2.3