gg
As well as this git, you get this document, which is lisp code that generates a lisp system for receiving the Hurkle experience, in the emacs eev style but if you ignore that then it does not matter.
The gist of the game is that you guess squares to check on a grid, and after each guess, you can sense which {e, ne, n, nw, w, sw, s, se}
direction the Hurkle is from you (or you win if you found it).
I am following my own common lisp asdf systems for beginners tutorial for making the hurkle system.
I just wrote a common lisp class that lets you play the game. See the useage below.
Later, I will use this class as a basis for different interfaces.
Edit: I solely learned about Hurkle-the-game by glancing at This historical link when mdh linked it to me.
hurkle
asdf system and class definitions#|
(eepitch-sbcl)
(eepitch-kill)
(eepitch-sbcl)
|#
(ensure-directories-exist #p"~/common-lisp/hurkle/")
(with-open-file (*standard-output*
#p"~/common-lisp/hurkle/hurkle.asd"
:direction :output
:if-does-not-exist :create)
(princ "(defsystem :hurkle :class :package-inferred-system)"))
(with-open-file (*standard-output*
#p"~/common-lisp/hurkle/class.lisp"
:direction :output
:if-does-not-exist :create)
(princ "#|
(eepitch-sbcl)
(eepitch-kill)
(eepitch-sbcl)
|#
(uiop:define-package :hurkle/class
(:export #:? #:game-grid #:look-board #:investigate #:new-game
#:grid #:active #:turn #:max-turns #:hurkle-row-col
#:e #:ne #:n #:nw #:w #:sw #:s #:se))
(in-package :hurkle/class)
"))
I wrote in all my symbol exports below, above.
I am going to write the source not-as-a-string so people who indulge get some syntax highlighting:
(defclass game-grid ()
((grid)
(hurkle-row-col)
(turn :initform 0)
(max-turns :initarg :max-turns)
(active :initform t))
(:default-initargs :max-turns 5))
(defmethod shared-initialize :after
((obj game-grid)
slot-names
&rest initargs
&key (rows 10) (cols 10) &allow-other-keys)
(declare (ignore slot-names initargs))
(with-slots
(grid hurkle-row-col)
obj
(setf grid
(loop
:repeat rows
:collect (loop
:repeat cols
:collect '?))
hurkle-row-col
(list (random rows) (random cols)))))
(defmethod look-board
((obj game-grid) &key (stream t))
(with-slots
(grid)
obj
(format stream "~{~{~3,,1,' @a~}~^~%~}"
(append
(mapcar 'cons
(loop :for x
:below
(length grid)
:collect x)
grid)
`((+ ,@(loop :for x
:below
(length (car grid))
:collect x)))))))
(defun dirang (row col hurkle-row-col &key mirror)
(let ((angle (atan
(if mirror
(- (car hurkle-row-col) row)
(- (- (car hurkle-row-col) row)))
(- (cadr hurkle-row-col) col))))
(cond ((<= 0
angle
(/ pi 8))
'e)
((<= (/ pi 8)
angle
(+ (/ pi 8) (/ pi 4)))
'ne)
((<= (+ (/ pi 8) (/ pi 4))
angle
(+ (/ pi 2) (/ pi 8)))
'n)
((<= (+ (/ pi 2) (/ pi 8))
angle
(- pi (/ pi 8)))
'nw)
((<= (- pi (/ pi 8))
angle)
'w)
(t (case (dirang row col hurkle-row-col
:mirror t)
(e 'e)
(ne 'se)
(n 's)
(nw 'sw)
(w 'w))))))
(defmethod investigate
((obj game-grid) row col &key (stream t))
(with-slots
(grid hurkle-row-col
turn max-turns active)
obj
(when active
(cond
((equal hurkle-row-col (list row col))
(format stream "You found the Hurkle!")
(terpri stream)
(setf (nth col (nth row grid)) 'H
active nil))
(t
(setf
(nth col (nth row grid))
(dirang row col hurkle-row-col)))))
(look-board obj :stream stream)
(when active
(incf turn)
(when (> turn max-turns)
(format stream "~%you ran out of time!~%")
(setf active nil)))))
(defmethod new-game ((obj game-grid) &rest other-args)
(with-slots
(active turn)
obj
(setf active t turn 0)
(apply 'reinitialize-instance obj other-args)))
(eepitch-shell)
mkdir -p ~/common-lisp
cd ~/common-lisp
git clone https://codeberg.org/tfw/hurkle.git
(eepitch-sbcl)
(asdf:load-system :hurkle/class)
(use-package :hurkle/class)
(defparameter *g* (make-instance 'game-grid))
(look-board *g*)
(investigate *g* 4 5)
(investigate *g* 4 2)
(investigate *g* 5 1)
(new-game *g*)
Well I have to say that’s a pretty fun game. I got ±
the wrong way around somewhere so officially we live in a mirror world. Works on my machine.
See you on the mastodon thread and at the show on Wednesday (Tuesday night)!
I should probably thank mdhughes for the link to Albrecht’s Hurkle. How did I do so far?
Edit: mdhughes has some nice screenshots in the mastodon thread, including an extra-big Hurkling.
screwlisp proposes kittens