Skip to content

Commit 88b2777

Browse files
Merge pull request #15 from Chia-Network/20240828-demo-panic-ii
20240828 demo panic ii
2 parents 9a6fdb9 + 99ba469 commit 88b2777

22 files changed

+1608
-489
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,4 @@ crate-type = ["cdylib", "rlib"]
5252
[[bin]]
5353
name = "chia-gaming"
5454
path = "src/cmd/main.rs"
55-
required-features = ["simulator"]
55+
required-features = ["simulator"]

clsp/calpoker_generate.clinc

+3-3
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@
135135
seed
136136
pokerc
137137
pokerc_hash
138-
ALICE_COMMIT
138+
(list ALICE_COMMIT local_move)
139139
48
140140
0
141141
(curry calpoker_bob_driver_c seed)
@@ -145,9 +145,9 @@
145145
)
146146

147147
(defun parse_message (message (alice_commit bob_seed) amount)
148-
(assert
148+
(assert
149149
(= (sha256 message) alice_commit)
150-
(make_cards_readable (sha256 message bob_seed amount))
150+
(make_cards_readable (sha256 (substr message 0 16) (substr bob_seed 0 16) amount))
151151
)
152152
)
153153

resources/web/index.css

+80-4
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,99 @@ body {
3737
}
3838

3939
#p1 {
40+
display: inline-block;
41+
top: 0;
4042
margin: 0;
4143
position: relative;
42-
height: 40vh;
43-
width: 98vw;
44+
height: 80vh;
45+
width: 30vw;
4446
background: #fcc;
4547
}
4648

4749
#p2 {
50+
display: inline-block;
51+
top: 0;
4852
margin: 0;
4953
margin-top: 1rem;
5054
position: relative;
51-
height: 40vh;
52-
width: 98vw;
55+
height: 80vh;
56+
width: 30vw;
5357
background: #cfc;
5458
}
5559

5660
.cardspan {
5761
margin-left: 0.5em;
5862
border: 1px solid black;
5963
}
64+
65+
#p1frame {
66+
display: block;
67+
position: relative;
68+
background: #fcc;
69+
left: 0;
70+
top: 0;
71+
width: 30vw;
72+
height: 80vh;
73+
}
74+
75+
#p2frame {
76+
display: block;
77+
position: relative;
78+
background: #cfc;
79+
left: 0;
80+
top: 0;
81+
width: 30vw;
82+
height: 80vh;
83+
}
84+
85+
#player-heading {
86+
margin: 0;
87+
}
88+
89+
#player-info {
90+
position: relative;
91+
}
92+
93+
.player-attr {
94+
margin-left: 1em;
95+
}
96+
97+
#player-body {
98+
font-size: 0.6rem;
99+
overflow-y: auto;
100+
}
101+
102+
.card {
103+
display: inline-block;
104+
width: 3rem;
105+
height: 5rem;
106+
box-sizing: border-box;
107+
background: white;
108+
border: 1px solid black;
109+
border-radius: 0.5em;
110+
font-size: 2rem;
111+
padding-left: 0.5rem;
112+
padding-right: 0.5rem;
113+
cursor: pointer;
114+
}
115+
116+
.selected_true {
117+
background: #aca !important;
118+
}
119+
120+
.card_bot {
121+
width: 100%;
122+
text-align: right;
123+
}
124+
125+
.suit2 {
126+
color: red;
127+
}
128+
129+
.suit4 {
130+
color: red;
131+
}
132+
133+
.sent_picks_true {
134+
display: none;
135+
}

resources/web/index.html

+7-2
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,17 @@
77
<div>
88
<h1 id="heading">Calpoker</h1>
99
<button onclick="exitapp()">Terminate</button>
10+
<button onclick="reset()">Reset Simulator</button>
1011
</div>
1112
<div id="container">
1213
<div id="info"> </div>
1314
<div id="app">
14-
<div id="p1"></div>
15-
<div id="p2"></div>
15+
<div id="p1">
16+
<iframe id="p1frame" src="player.html?id=1"></iframe>
17+
</div>
18+
<div id="p2">
19+
<iframe id="p2frame" src="player.html?id=2"></iframe>
20+
</div>
1621
</div>
1722
</div>
1823
</body>

resources/web/index.js

+25-82
Original file line numberDiff line numberDiff line change
@@ -1,104 +1,47 @@
1-
let all_selected_cards = [{}, {}];
2-
3-
function set_card_properties(who, collection) {
4-
for (let i = 0; i < 8; i++) {
5-
let label = `${who}_card${i}`;
6-
let card = document.getElementById(label);
7-
if (!card) {
8-
continue;
9-
}
10-
let n_string = `_${i}`;
11-
if (collection[n_string]) {
12-
card.style.background = 'green';
13-
} else {
14-
card.style.background = 'white';
15-
}
1+
function clear(elt) {
2+
for (let node = elt.firstChild; node; node = elt.firstChild) {
3+
node.parentNode.removeChild(node);
164
}
175
}
186

7+
function reload() {
8+
window.location.reload();
9+
}
10+
1911
function check() {
2012
return fetch("idle.json", {
2113
"method": "POST"
2214
}).then((response) => {
23-
return response.json();
15+
return response.json().catch((e) => {
16+
return {"error": JSON.stringify(e)};
17+
});
2418
}).then((json) => {
2519
if (json.info) {
2620
const info = document.getElementById('info');
27-
info.innerHTML = json.info;
28-
}
29-
if (json.p1) {
30-
const p1 = document.getElementById('p1');
31-
p1.innerHTML = json.p1;
21+
clear(info);
22+
let keys = Object.keys(json.info);
23+
let ul = document.createElement('ul');
24+
for (let i = 0; i < keys.length; i++) {
25+
let key = keys[i];
26+
let li = document.createElement('li');
27+
let tn = document.createTextNode(`${key}: ${json.info[key]}`);
28+
li.appendChild(tn);
29+
ul.appendChild(li);
30+
}
31+
info.appendChild(ul);
3232
}
33-
if (json.p2) {
34-
const p2 = document.getElementById('p2');
35-
p2.innerHTML = json.p2;
36-
}
37-
38-
set_card_properties('alice', all_selected_cards[0]);
39-
set_card_properties('bob', all_selected_cards[1]);
4033

4134
setTimeout(check, 500);
4235
});
4336
}
4437

45-
function send_alice_word() {
46-
let word = Math.random().toString();
47-
return fetch(`alice_word_hash?word=${word}`, {
48-
"method": "POST"
49-
});
50-
}
51-
52-
function send_bob_word() {
53-
let word = Math.random().toString();
54-
return fetch(`bob_word?word=${word}`, {
55-
"method": "POST"
56-
});
57-
}
58-
59-
function toggle_card(label, selected_cards, n) {
60-
let n_string = `_${n}`;
61-
let card = document.getElementById(label);
62-
if (!card) {
63-
return;
64-
}
65-
if (selected_cards[n_string]) {
66-
card.style.background = 'white';
67-
delete selected_cards[n_string];
68-
} else {
69-
card.style.background = 'green';
70-
selected_cards[n_string] = true;
71-
}
72-
console.log(selected_cards);
73-
}
74-
75-
function alice_toggle(n) {
76-
toggle_card(`alice_card${n}`, all_selected_cards[0], n);
77-
}
78-
79-
function bob_toggle(n) {
80-
toggle_card(`bob_card${n}`, all_selected_cards[1], n);
81-
}
82-
83-
function set_picks(who, id) {
84-
let picks = '';
85-
for (let i = 0; i < 8; i++) {
86-
let n_string = `_${i}`;
87-
picks += (all_selected_cards[id][n_string]) ? '1' : '0';
88-
}
89-
return fetch(`${who}_picks?cards=${picks}`, {
90-
"method": "POST"
38+
function reset() {
39+
return fetch("reset", {"method": "POST"}).then((response) => {
40+
console.log("reset...");
41+
setTimeout(reload, 2000);
9142
});
9243
}
9344

94-
function set_alice_picks() {
95-
set_picks('alice', 0);
96-
}
97-
98-
function set_bob_picks() {
99-
set_picks('bob', 1);
100-
}
101-
10245
function exitapp() {
10346
return fetch("exit", {"method": "POST"}).then((response) => {
10447
console.log("exiting...");

resources/web/player.html

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<html>
2+
<head>
3+
<link rel="stylesheet" href="index.css">
4+
<link rel="stylesheet" href="https://code.jquery.com/ui/1.14.0/themes/base/jquery-ui.css">
5+
</head>
6+
<body id="player-body">
7+
<h1 id="player-heading"></h1>
8+
<div id="player-error"></div>
9+
<h4 id="player-info"></h4>
10+
<div id="playspace"></div>
11+
<script type="text/javascript" src="player.js"></script>
12+
<script src="https://code.jquery.com/jquery-3.7.1.js"></script>
13+
<script src="https://code.jquery.com/ui/1.14.0/jquery-ui.js"></script>
14+
</body>
15+
</html>

0 commit comments

Comments
 (0)