~subsetpark/whist

ref: b4197421dcbc4b6877e7b574a1fc6ee2802d1171 whist/test/last-card.janet -rw-r--r-- 2.0 KiB
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
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
54
55
(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"}}
			      :info @{:North_tricks @{:value 0}}
			      :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-prompt] events)
  (let [played-card (merge-into @{:player "North"} CA)]
    (is (deep= @{} (state :meta)))
    (is (deep= @{:trick []} (state :stacks)))
    (is (deep= @{:North_tricks @{:value 1}} (state :info))))
  (is (= {:value "played \xE2\x99\xA3Ace" :event "add_decoration" :player "North" :name "play_action"}
	 north-decoration))
  (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"}}
			      :info @{:North_tricks @{:value 0}}
			      :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!)