summaryrefslogtreecommitdiff
path: root/web/dartboat_wasm.c
diff options
context:
space:
mode:
Diffstat (limited to 'web/dartboat_wasm.c')
-rw-r--r--web/dartboat_wasm.c28
1 files changed, 25 insertions, 3 deletions
diff --git a/web/dartboat_wasm.c b/web/dartboat_wasm.c
index d52f15f..0e59312 100644
--- a/web/dartboat_wasm.c
+++ b/web/dartboat_wasm.c
@@ -82,7 +82,8 @@ EMSCRIPTEN_KEEPALIVE void draw_match() {
EM_ASM({drawVisit($0, $1, $2, $3, $4, $5)},
"0", "", "501", "", "501", "");
- int n_visits = l1->n_visits > l2->n_visits ? l1->n_visits : l2->n_visits;
+ //int n_visits = l1->n_visits > l2->n_visits ? l1->n_visits : l2->n_visits;
+ int n_visits = l1->n_visits;
for (int i = 0; i < n_visits; ++i) {
sprintf(visit_no, "%d", i + 1);
@@ -223,7 +224,7 @@ EMSCRIPTEN_KEEPALIVE bool user_visit(int points) {
EM_ASM({clearVisits()});
draw_match();
- if (!is_match_over()) {
+ if (!is_match_over() && l->n_visits > state->l2->n_visits) {
set_boat_active();
boat_visit();
}
@@ -236,6 +237,27 @@ EMSCRIPTEN_KEEPALIVE void user_visit_to_rem(int rem) {
user_visit(state->l1->rem - rem);
}
+EMSCRIPTEN_KEEPALIVE bool user_undo() {
+ if (!state->l1->n_visits) {
+ EM_ASM(oi());
+ return false;
+ }
+
+ struct leg *l = state->l1;
+ struct visit *v = l->visits + --l->n_visits;
+ l->rem += v->points;
+
+ EM_ASM({updatePlayerAvg($0, $1)}, P_USER,
+ l->n_visits ? (double)(l->start-l->rem)/l->n_visits : 0);
+
+ memcpy(v, 0, sizeof(*v));
+
+ EM_ASM({clearVisits()});
+ draw_match();
+
+ return true;
+}
+
EMSCRIPTEN_KEEPALIVE void draw_boat_throwing(int pts, char *str) {
char buf[10];
sprintf(buf, "%d", pts);
@@ -298,7 +320,7 @@ EMSCRIPTEN_KEEPALIVE void start_match() {
if (state) free_match();
init_boat();
- state = calloc(1, sizeof(struct match_state));
+ state = calloc(1, sizeof(*state));
state->l1 = leg_init(501, "User");
state->l2 = leg_init(501, "Bot");