~subsetpark/whist

69ca04ef437a418fb7f3758b3deb1a07bb93e064 — Zach Smith 6 months ago e6f6b42
Integrate cards into lit
1 files changed, 14 insertions(+), 0 deletions(-)

A test/support.janet
A test/support.janet => test/support.janet +14 -0
@@ 0,0 1,14 @@
(defmacro intern-cards! []
  # Easily generate card structs.
  (def suits {"D" "diamonds" "S" "spades" "C" "clubs" "H" "hearts"})
  (def ranks {"1" 1 "A" 1 "2" 2 "3" 3 "4" 4 "5" 5 "6" 6 "7" 7 "8" 8 "9" 9 "T" 10 "J" 11 "Q" 12 "K" 13})

  (var defs @[])
  (loop [suit :in ["D" "S" "C" "H"]
	 rank :in ["A" "2" "3" "4" "5" "6" "7" "8" "9" "T" "J" "Q" "K"]]
    (let [sym (symbol suit rank)]
      (array/push defs ~(def ,sym @{:suit ,(in suits suit) :rank ,(in ranks rank)}))))
  (loop [rank :in ["1" "2"]]
    (let [sym (symbol "J" rank)]
      (array/push defs ~(def ,sym @{:suit "joker" :rank ,(in ranks rank)}))))
  (do ;defs))