|
52 | 52 | (curry calpoker_alice_driver_c PREIMAGE move) PREIMAGE)
|
53 | 53 | )
|
54 | 54 |
|
| 55 | +(defun single-byte (raw-indices) |
| 56 | + (if raw-indices |
| 57 | + (assign |
| 58 | + indices-len (strlen raw-indices) |
| 59 | + (substr raw-indices (- indices-len 1) indices-len) |
| 60 | + ) |
| 61 | + 0x00 |
| 62 | + ) |
| 63 | +) |
| 64 | + |
55 | 65 | (defun bitify (mylist)
|
56 |
| - (if (not mylist) |
57 |
| - 0 |
58 |
| - (logior (f mylist) (lsh (bitify (r mylist)) 1)) |
| 66 | + (single-byte |
| 67 | + (if (not mylist) |
| 68 | + 0 |
| 69 | + (logior (f mylist) (lsh (bitify (r mylist)) 1)) |
| 70 | + ) |
59 | 71 | )
|
60 | 72 | )
|
61 | 73 |
|
|
84 | 96 | (if (not mylist)
|
85 | 97 | 0
|
86 | 98 | (= (f mylist) index)
|
87 |
| - (logior 1 (* 2 (indices_to_bitfield_inner (r mylist) (+ index 1)))) |
88 |
| - (* 2 (indices_to_bitfield_inner mylist (+ index 1))) |
| 99 | + (logior 1 (lsh (indices_to_bitfield_inner (r mylist) (+ index 1)) 1)) |
| 100 | + (lsh (indices_to_bitfield_inner mylist (+ index 1)) 1) |
89 | 101 | )
|
90 | 102 | )
|
91 | 103 |
|
92 | 104 | (defun indices_to_bitfield (mylist)
|
93 |
| - (indices_to_bitfield_inner mylist 0) |
| 105 | + (single-byte (indices_to_bitfield_inner mylist 0)) |
94 | 106 | )
|
95 | 107 |
|
96 | 108 | ; We have composed cards as sublists but need them as pairs.
|
|
108 | 120 | bob_all_cards (map make_card (append bob_cards_bob my_cards_bob))
|
109 | 121 | (my_hand_value my_picks) (handcalc (map card_list_to_pair my_all_cards))
|
110 | 122 | (bob_hand_value bob_picks) (handcalc (map card_list_to_pair bob_all_cards))
|
| 123 | + ;; win_result is 1 if my_hand_value is greater than bob_hand_value |
111 | 124 | win_result (list_compare my_hand_value bob_hand_value)
|
| 125 | + ;; split is captured in a their turn handler below so it's the opposite of what |
| 126 | + ;; this turn would specify. |
112 | 127 | split (if (= win_result 1) 0 (= win_result 0) (lsh amount -1) amount)
|
113 | 128 | (list MAKE_MOVE
|
114 | 129 | (list move (indices_to_bitfield my_picks) (indices_to_bitfield bob_picks)
|
115 | 130 | my_hand_value bob_hand_value win_result)
|
116 |
| - (lambda ((& MY_SALT MY_PICKS split)) (list (concat MY_SALT MY_PICKS) 0 0 0 0 split 0 0) |
| 131 | + (lambda ((& MY_SALT MY_PICKS my_picks split amount)) (list (concat MY_SALT MY_PICKS (single-byte (indices_to_bitfield my_picks))) 0 0 0 0 split 0 0)) |
117 | 132 | 0
|
118 |
| - ) |
119 | 133 | )
|
120 | 134 | )
|
121 | 135 | )
|
|
192 | 206 | pokere
|
193 | 207 | pokere_hash
|
194 | 208 | (list my_move (list ALICE_CARDS BOB_CARDS) ALICE_COMMIT_2)
|
195 |
| - 17 |
| 209 | + 18 |
196 | 210 | 0
|
197 | 211 | calpoker_bob_driver_e
|
198 | 212 | 0
|
|
206 | 220 | (defun calpoker_bob_driver_e (amount (@ state (bob_selects (alice_cards bob_cards) alice_commit_2)) move
|
207 | 221 | validation_program_hash max_move_size split)
|
208 | 222 | (assign
|
209 |
| - alice_selects (substr move 16 (strlen move)) |
210 |
| - (alice_cards_alice alice_cards_bob) (split_cards alice_selects alice_cards) |
| 223 | + alice_my_picks (substr move 16 17) |
| 224 | + alice_selects (substr move 17 (strlen move)) |
| 225 | + (alice_cards_alice alice_cards_bob) (split_cards alice_my_picks alice_cards) |
211 | 226 | (bob_cards_bob bob_cards_alice) (split_cards bob_selects bob_cards)
|
212 | 227 | alice_all_cards (map make_card (append alice_cards_alice bob_cards_alice))
|
213 | 228 | bob_all_cards (map make_card (append bob_cards_bob alice_cards_bob))
|
214 | 229 | (alice_hand_value alice_picks) (handcalc (map card_list_to_pair alice_all_cards))
|
215 | 230 | (bob_hand_value bob_picks) (handcalc (map card_list_to_pair bob_all_cards))
|
216 | 231 | win_result (list_compare alice_hand_value bob_hand_value)
|
| 232 | + ;; win_result 1 means alice wins. |
217 | 233 | correct_split (if (= win_result 1) 0 (= win_result 0) (lsh amount -1) amount)
|
218 | 234 | (if (!= split correct_split)
|
219 | 235 | (list SLASH (indices_to_bitfield bob_picks))
|
220 | 236 | (list MAKE_MOVE
|
221 |
| - (list alice_selects (indices_to_bitfield bob_picks) (indices_to_bitfield alice_picks) |
| 237 | + (list alice_my_picks (indices_to_bitfield bob_picks) (indices_to_bitfield alice_picks) |
222 | 238 | bob_hand_value alice_hand_value split)
|
223 | 239 | )
|
224 | 240 | )
|
|
0 commit comments