|
1 | 1 | ;; Debug game handler
|
| 2 | +;; |
| 3 | +;; The validation info hash result is the sha256 of the concatenation of two |
| 4 | +;; hashes. |
| 5 | +;; |
| 6 | +;; 1 - A program which aborts if the move is a cheat. |
| 7 | +;; 2 - The sha256tree of the program state. |
| 8 | +;; |
| 9 | +;; In the debug game, the whole state is described by the readable move data. |
| 10 | + |
| 11 | +;; Curried = MOD_HASH PUZZLE AMOUNT MY_TURN SLASH_INFO |
| 12 | + |
2 | 13 | (include *standard-cl-23*)
|
3 | 14 |
|
4 | 15 | (import std.curry)
|
5 | 16 | (import std.map)
|
6 | 17 | (import std.shatree)
|
7 | 18 |
|
| 19 | +(defun-inline curried_mod_hash (CURRIED) (f CURRIED)) |
| 20 | +(defun-inline curried_puzzle (CURRIED) (f (r CURRIED))) |
| 21 | +(defun-inline curried_amount (CURRIED) (f (r (r CURRIED)))) |
| 22 | +(defun-inline curried_my_turn (CURRIED) (f (r (r (r CURRIED))))) |
| 23 | +(defun-inline curried_slash_info (CURRIED) (f (r (r (r (r CURRIED)))))) |
| 24 | +(defun-inline curried_other_turn (CURRIED) |
| 25 | + (list |
| 26 | + (curried_mod_hash CURRIED) |
| 27 | + (curried_puzzle CURRIED) |
| 28 | + (curried_amount CURRIED) |
| 29 | + (not (curried_my_turn CURRIED)) |
| 30 | + (curried_slash_info CURRIED) |
| 31 | + ) |
| 32 | + ) |
| 33 | + |
8 | 34 | (defun get-validation-move
|
9 | 35 | (MOVER_PUZZLE_HASH
|
10 | 36 | WAITER_PUZZLE_HASH
|
|
27 | 53 |
|
28 | 54 | (defun validation_program (validation-data)
|
29 | 55 | (assign
|
30 |
| - cheated (substr (get-validation-move validation-data) 0 1) |
| 56 | + cheated (logand (get-validation-move validation-data) 1) |
31 | 57 | (if cheated
|
32 | 58 | (x "validation program cheating" validation-data)
|
33 | 59 | ()
|
34 | 60 | )
|
35 | 61 | )
|
36 | 62 | )
|
37 | 63 |
|
38 |
| -(defun do_my_turn (MOD_HASH PUZZLE AMOUNT MY_TURN SLASH_INFO readable_new_move amount state entropy) |
| 64 | +(defun do_my_turn (CURRIED readable_new_move amount state entropy) |
39 | 65 | (assign
|
40 | 66 |
|
| 67 | + ;; Readable move is a clvm structure that describes the move |
| 68 | + ;; uncompressed. |
41 | 69 | (set_share . set_cheated) readable_new_move
|
42 | 70 |
|
43 |
| - new_validation_program_hash (shatree state "this is not right") ;; XXX just anything |
| 71 | + ;; Validation info |
| 72 | + validation_info readable_new_move |
| 73 | + |
| 74 | + state_hash (shatree state) |
| 75 | + other_turn (curried_other_turn CURRIED) |
| 76 | + |
| 77 | + program-hash |
| 78 | + (curry_unhashed_args |
| 79 | + (curried_mod_hash other_turn) |
| 80 | + other_turn |
| 81 | + ) |
| 82 | + |
| 83 | + new_state |
| 84 | + (logior (logand 1 set_cheated) (ash set_share 1)) |
| 85 | + |
| 86 | + new_validation_program_hash |
| 87 | + (sha256 program-hash (shatree new_state)) |
44 | 88 |
|
45 | 89 | (list
|
46 |
| - (logior (logand 1 set_cheated) (ash set_share 1)) |
| 90 | + new_state |
47 | 91 | validation_program
|
48 | 92 | new_validation_program_hash
|
49 | 93 | (c set_share set_cheated)
|
50 | 94 | 100
|
51 | 95 | set_share
|
52 |
| - (curry PUZZLE MOD_HASH PUZZLE AMOUNT (not MY_TURN) SLASH_INFO) |
| 96 | + (curry (curried_puzzle CURRIED) other_turn) |
53 | 97 | ()
|
54 | 98 | )
|
55 | 99 | )
|
56 | 100 | )
|
57 | 101 |
|
58 |
| -(defun do_their_turn (MOD_HASH PUZZLE AMOUNT MY_TURN SLASH_INFO amount last_state new_move new_validation_info_hash new_max_move_size new_mover_share) |
| 102 | +(defun do_their_turn (CURRIED amount last_state new_move new_validation_info_hash new_max_move_size new_mover_share) |
59 | 103 | (assign
|
60 | 104 | set_cheated (logand new_move 1)
|
| 105 | + other_turn (curried_other_turn CURRIED) |
61 | 106 |
|
62 | 107 | (if set_cheated
|
63 |
| - (c 2 SLASH_INFO) |
| 108 | + (c 2 (curried_slash_info CURRIED)) |
64 | 109 | (list
|
65 | 110 | 0
|
66 | 111 | (c set_cheated (get-move-share new_move)) ;; readable move
|
67 |
| - (curry PUZZLE MOD_HASH PUZZLE AMOUNT (not MY_TURN) SLASH_INFO) |
| 112 | + (curry (curried_puzzle CURRIED) other_turn) |
68 | 113 | "message data"
|
69 | 114 | )
|
70 | 115 | )
|
71 | 116 | )
|
72 | 117 | )
|
73 | 118 |
|
74 | 119 | (export
|
75 |
| - (MOD_HASH PUZZLE AMOUNT MY_TURN SLASH_INFO . args) |
76 |
| - (if MY_TURN |
77 |
| - (do_my_turn MOD_HASH PUZZLE AMOUNT MY_TURN SLASH_INFO &rest args) |
78 |
| - (do_their_turn MOD_HASH PUZZLE AMOUNT MY_TURN SLASH_INFO &rest args) |
| 120 | + (CURRIED . args) |
| 121 | + (if (curried_my_turn CURRIED) |
| 122 | + (do_my_turn CURRIED &rest args) |
| 123 | + (do_their_turn CURRIED &rest args) |
79 | 124 | )
|
80 | 125 | )
|
0 commit comments