summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--web/dartboat_wasm.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/web/dartboat_wasm.c b/web/dartboat_wasm.c
index b44a9b8..d9c3540 100644
--- a/web/dartboat_wasm.c
+++ b/web/dartboat_wasm.c
@@ -24,7 +24,7 @@ struct match_state {
struct leg *active_leg;
int active_player;
int boat_undone;
- bool num_darts;
+ int num_darts;
};
struct match_state *state;
@@ -309,6 +309,17 @@ EMSCRIPTEN_KEEPALIVE void user_undo()
return;
}
+ if (state->num_darts) {
+ state->num_darts = 0;
+ EM_ASM({updatePlayerAvg($0, $1)}, state->active_player,
+ ((double)(state->active_leg->start -
+ state->active_leg->visits[
+ state->active_leg->n_visits-2].rem) /
+ (state->active_leg->n_visits-1)));
+ handle_next();
+ return;
+ }
+
if (state->mode == M_PVC) {
set_active_player(1);
} else if (state->mode == M_PVP) {
@@ -322,7 +333,6 @@ EMSCRIPTEN_KEEPALIVE void user_undo()
struct visit *v = l->visits + --l->n_visits;
l->rem += v->points;
memcpy(v, 0, sizeof(*v));
- state->num_darts = 0;
if (state->mode == M_PVC && state->legs[1]->n_visits > l->n_visits) {
state->legs[1]->rem +=