~subsetpark/whist

ref: b677ce25024b86d1b5ab62f4a77a8b359a07e8fc whist/test/last-card.janet -rw-r--r-- 1.9 KiB
b677ce25 — Zach Smith Handle last card to trick 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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
(import testament :prefix "")

(import whist)
(import bids)
(import init)
(import cards)

(cards/intern-cards!)

(def- two-cards-left
  [{:hand [C2 CA] :score 0 :team 1 :id "North"}
   {:hand [D2 DA] :score 0 :team 2 :id "East"}
   {:hand [H2 HA] :score 0 :team 1 :id "South"}
   {:hand [S2 SA] :score 0 :team 2 :id "West"}])

(deftest north-takes-the-trick
  (def player-lead {:players two-cards-left
		    :state {:phase "play" :meta {:suit "clubs"
						 :bid {:count 3 :suit "notrumps" :direction "up"}}
			    :stacks {:trick [(merge-into @{:player "East"} CK)
					     (merge-into @{:player "South"} D2)
					     (merge-into @{:player "West"} S3)]}}
		    :action {:player "North" :name "play" :value CA}})
  (def [state events] (whist/next player-lead))
  (def [north-decoration north-add-score north-prompt] events)
  (let [played-card (merge-into @{:player "North"} CA)]
    (is (deep= @{} (state :meta)))
    (is (deep= @{:trick []} (state :stacks))))
  (is (= {:value "played \xE2\x99\xA3Ace" :event "add_decoration" :player "North" :name "play_action"}
	 north-decoration))
  (is (= {:event "add_score" :value 1 :player "North"} north-add-score))
  (is (deep= {:player "North" :event "prompt_play" :count 1 :to "trick" :from [C2 CA]}
	     north-prompt)))

(def- last-cards
  [{:hand [CA] :score 0 :team 1 :id "North"}
   {:hand [DA] :score 0 :team 2 :id "East"}
   {:hand [HA] :score 0 :team 1 :id "South"}
   {:hand [SA] :score 0 :team 2 :id "West"}])

(deftest north-takes-the-last-trick
  (def player-lead {:players last-cards
		    :state {:phase "play" :meta {:suit "clubs"
						 :bid {:count 3 :suit "notrumps" :direction "up"}}
			    :stacks {:trick [(merge-into @{:player "East"} CK)
					     (merge-into @{:player "South"} D2)
					     (merge-into @{:player "West"} S3)]}}
		    :action {:player "North" :name "play" :value CA}})
  (def [state events] (whist/next player-lead))
  # TODO: Test end of hand.
  (def [] events))

(run-tests!)