Turning Robots Into Life with the LOOP facility
robots.lisp game:classic → Conway's game of life with the wreckage.
Start The Game
Aside: We have to help more itch.io people to see Common Lisp Always Just Works (And Always Has).
Anywy my friend mdh was giving me their hot insider gamedev tips. Scheme lisp and common lisp are s-expression buddies after all; anyway he uses arrays kinda like my robots.lisp on the cons for a lot of classic 80s rpg videogames.
(* mdh → https://mdhughes.itch.io/)
Actually Playing Robots: Classic
I had two unsophistications. One ways that my array was *just* a 2-array of *just* literal characters. Game logic consists of looking at a few characters, and deciding visually what happens. You, dear friend know this recipe spells W-O-L-F-R-A-M. Robowreckage as mazecetric:
Since we were looking at neighbors anyhoo, here's the whole thing:
(defun automata-rule (grid &key live die) (let ((tmp-array (make-array (array-dimensions grid)))) (loop for r from 2 below (1- (1- (array-dimension tmp-array 0))) do (loop for c from 2 below (1- (1- (array-dimension tmp-array 1))) for tile = (aref grid r c) for neighbors = (claustrophobia grid r c) do (setf (aref tmp-array r c) (cond ((member neighbors live) *wreckage*) ((member neighbors die) *ground*) (t tile)))) finally (loop for r from 1 below (1- (array-dimension tmp-array 0)) do (loop for c from 1 below (1- (array-dimension tmp-array 1)) for tmp = (aref tmp-array r c) for ori = (aref grid r c) when (and (member tmp (list *wreckage* *ground*)) (member ori (list *wreckage* *ground*))) do (setf (aref grid r c) tmp))))))
Do you think I managed to squeeze my codes enough itch.io isn't going to Line Wrap them on me?
Oh, claustrophobia just counts neighbors:
(defun claustrophobia (grid row col) (loop for mr from -1 to +1 summing (loop for mc from -1 to +1 unless (and (zerop mr) (zerop mc)) sum (if (equal *wreckage* (aref grid (+ row mr) (+ col mc))) 1 0))))
Oh we better change to game of life.
Here's the whole change:
From
(let ((frame *application-frame*)) (with-slots (grid) frame (automata-rule grid :live '(3) :die '(5 6 7 8))))
to
(let ((frame *application-frame*)) (with-slots (grid) frame (automata-rule grid :live '(3) :die '(0 1 4 5 6 7 8))))
Bee tee dubs I added this automata because someone asked for it. Ask by friendstering me on https://mastodon.sdf.org/@screwtape/ https://toobnix.org/c/screwtape_channel https://lispy-gopher-show.itch.io/ or as a reply on my devlogs.
Files
Get LISP GAME SOFT CONS
LISP GAME SOFT CONS
Forming a committee to spec a lisp game software console
More posts
- Install the-cons, game cartridges using git now plzJun 25, 2024
- PAINSTAKING SOURCE COMPARISON vidak's robots vs screwlisp'sJun 16, 2024
- What I learned from example and tictactoeJun 13, 2024
- 40min copy+paste video example-game to make tictactoeJun 13, 2024
- Lisp soft console example game #firstJun 11, 2024
- livecode videos for days. hotloading clim gui deltas.Jun 09, 2024
- Cautionary Tales: Incompatible ECL SFFI SDL2 C/C++ LISPJun 06, 2024
- How to program iJun 05, 2024
Leave a comment
Log in with itch.io to leave a comment.