~subsetpark/whist

ref: b0f715a90af4b24daa3c892ceb00f7eb78478281 whist/bids.janet -rw-r--r-- 2.0 KiB
b0f715a9 — Zach Smith Add some explanatory text 6 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
## bids.janet
## All Bids
(def-
  bids
  [[{:count 3 :direction "up"} "3 Uptown"]
   [{:count 3 :direction "down"} "3 Downtown"]
   [{:count 3 :suit "no_trumps"} "3 No-Trumps"]
   [{:count 4 :direction "up"} "4 Uptown"]
   [{:count 4 :direction "down"} "4 Downtown"]
   [{:count 4 :suit "no_trumps"} "4 No-Trumps"]
   [{:count 5 :direction "up"} "5 Uptown"]
   [{:count 5 :direction "down"} "5 Downtown"]
   [{:count 5 :suit "no_trumps"} "5 No-Trumps"]
   [{:count 6 :direction "up"} "6 Uptown"]
   [{:count 6 :direction "down"} "6 Downtown"]
   [{:count 6 :suit "no_trumps"} "6 No-Trumps"]
   [{:count 7 :direction "up"} "7 Uptown"]
   [{:count 7 :direction "down"} "7 Downtown"]
   [{:count 7 :suit "no_trumps"} "7 No-Trumps"]])

## Second Bids
(def- direction [[{:direction "up"} "Uptown"]
		[{:direction "down"} "Downtown"]])

(def- suit [[{:suit "hearts"} "Hearts"]
	   [{:suit "spades"} "Spades"]
	   [{:suit "diamonds"} "Diamonds"]
	   [{:suit "clubs"} "Clubs"]])

(def second-bids (array/concat @[] direction suit))

(defn- no-trumps? [bid] (= (bid :suit) "no_trumps"))

(defn second-bid
  [bid]
  (if (no-trumps? bid) direction suit))

(defn- find-row-index [bid source] (find-index |(= ($0 0) bid) source))

(defn to-text
  [bid &opt source]
  (default source bids)
  (if-let [ind (find-row-index (freeze bid) source)
	   row (source ind)]
    (row 1)
    (error (string "Not found: " (string/format "%q" bid) " in " (string/format "%q" source)))))
## Available Bids
(defn- no-trumps? [bid] (= (bid :suit) "no_trumps"))

(defn available-bids
  [&opt high-bid]
  (case high-bid
    nil (array ;bids ["pass" "Pass"])
    (if-let [minimum-bid (if (no-trumps? high-bid)
		 	   {:count (inc (high-bid :count)) :direction "up"} 
			   {:count (high-bid :count) :suit "no_trumps"})
	     minimum-bid-ind (find-row-index minimum-bid bids)]
      (array/push (array/slice bids minimum-bid-ind) ["pass" "Pass"])
      @[["pass" "Pass"]])))

(defn force-bid
  "The bidder can't pass; they can only select an actual bid."
  []
  (array ;bids))