~subsetpark/whist

ref: 6c4b421ce2c269a6a4a4048cb7cd6f0712ff3c7e whist/game/discard.janet -rw-r--r-- 992 bytes
6c4b421c — Zach Smith Bug fix play->play transition, and dont emit discard event 7 months 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
27
28
(import events)
(import bids)

(defn- make-full-bid [high-bid second-bid bidder]
  (merge high-bid second-bid {:player bidder}))

(defn discard-phase
  ```
  The bidder has named their full contract. 

  They pick up the kitty, and are then prompted to discard 6 cards.

  Expected metadata:
  - `high_bid`: The winning bid in the auction.
  Provides:
  - `bid`: The full bid for the hand. 
  ```
  [{:meta {:high_bid {:bid high-bid}}} players {:player bidder :value second-bid}]
  (let [full-bid (make-full-bid high-bid second-bid bidder)
	full-bid-text (string (bids/to-text high-bid) ": " (bids/to-text second-bid bids/second-bids))] 
       # State: Discard -> Begin Play
       [{:phase "begin_play" :meta {:bid full-bid}}
	(array/concat
	 (map |(events/clear-decoration ($0 :id) "bid") players)
	 (map |(events/clear-decoration ($0 :id) "bid_action") players)
	 [(events/add-decoration bidder "high_bid" full-bid-text)
	  (events/draw bidder 6)
	  (events/prompt-discard bidder 6)])]))