~subsetpark/whist

ref: b4197421dcbc4b6877e7b574a1fc6ee2802d1171 whist/game/beginplay.janet -rw-r--r-- 989 bytes
b4197421 — Zach Smith Replace add_score with info boxes 1 year, 1 month ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
(defn- discard [from to-discard]
  (let [new @[]]
    (each in-from from
      (if (not (find |(= in-from $0) to-discard))
	(array/push new in-from)))
    new))

(defn begin-play-phase
  ```
  The bidder has discarded six cards. 

  They may lead any card from their hand.

  Provides:
  - `suit`: The led suit of the current trick.
  ```
  [{:meta meta} players {:player bidder :value to-discard}]
    (let [bidder-record (find |(= ($0 :id) bidder) players)
	  current-hand (in bidder-record :hand)
	  other-players (filter |(not= ($0 :id) bidder) players)]
      [{:phase "play" :meta (merge meta {:suit :null})}
       (array/concat (map |{:event "add_info" :name (keyword ($0 :id) "_tricks") :value 0} other-players)
		     # It's the first trick; bidder gets one trick for the discard.
		     {:event "add_info" :name (keyword bidder "_tricks") :value 1}
		     {:event "discard" :player bidder :value to-discard}
		     {:event "prompt_play" :player bidder :to "trick" :count 1})]))