Advertisement
Guest User

Untitled

a guest
Jul 27th, 2020
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 0.75 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* ((player (gethash ,player ,game))
  12.           (opponent (gethash (not ,player) ,game)))
  13.      (declare (ignorable player))
  14.      (declare (ignorable opponent))
  15.      (macrolet ((hand (p) `(gethash "hand" (gethash ,p ,,game)))
  16.                 (deck (p) `(gethash "deck" (gethash ,p ,,game))))
  17.        ,@body)))
  18.  
  19. (let-game (x t) (print (deck t)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement