~subsetpark/whist

ref: 18a5446a58efa8d6444719443d57c93ffa5bcaa9 whist/game/discard.janet -rw-r--r-- 1.1 KiB
18a5446a — Zach Smith Incorporate lit through discard 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
29
30
31
32
# game/discard.janet
(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))]))