Advertisement
Guest User

Untitled

a guest
Jul 27th, 2020
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 0.86 KB | None | 0 0
  1. (defun make-game ()
  2.   (let ((game (make-hash-table :test #'equal)))
  3.     (iter (for p in '(t nil))
  4.       (setf (gethash p game) (make-hash-table :test #'equal))
  5.       (iter (for location in '("deck" "hand"))
  6.         (setf (gethash location (gethash p game)) nil)))
  7.     game))
  8. (defvar x (make-game))
  9. (setf (gethash "deck" (gethash t x)) '(0 1 2 3 4 5 6 7 8 9 10))
  10. (defmacro let-game ((game player) &body body)
  11.   (let ((deck (intern "DECK"))
  12.         (hand (intern "HAND")))
  13.       `(let* ((player (gethash ,player ,game))
  14.            (opponent (gethash (not ,player) ,game)))
  15.            (declare (ignorable player))
  16.            (declare (ignorable opponent))
  17.            (macrolet ((,hand (p) `(gethash "hand" (gethash ,p ,,game)))
  18.                       (,deck (p) `(gethash "deck" (gethash ,p ,,game))))
  19.              ,@body))))
  20.  
  21. (let-game (x t) (print (deck t)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement