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.c31
1 files changed, 27 insertions, 4 deletions
diff --git a/web/dartboat_wasm.c b/web/dartboat_wasm.c
index 4eaa6ce..b2c306c 100644
--- a/web/dartboat_wasm.c
+++ b/web/dartboat_wasm.c
@@ -63,6 +63,9 @@ EMSCRIPTEN_KEEPALIVE bool user_visit(struct match_state *state, int points) {
v->rem = l->rem;
EM_ASM({updateUserRem($0)}, l->rem);
+ if (v->rem > 0)
+ EM_ASM({updateUserAvg($0)}, (double)(l->start-l->rem)/l->n_visits);
+
return true;
}
@@ -85,11 +88,17 @@ EMSCRIPTEN_KEEPALIVE void boat_visit(struct match_state *state) {
*s2 = v->n_darts > 1 ? segment_name(v->darts[1]) : NULL,
*s3 = v->n_darts > 2 ? segment_name(v->darts[2]) : NULL;
- EM_ASM({boatVisitRes($0, $1, $2, $3, $4, $5, $6, $7)},
+ double avg;
+ if (v->rem > 0)
+ avg = (double)(l->start - l->rem) / l->n_visits;
+ else
+ avg = ((double)l->start / (((l->n_visits - 1) * 3) + v->n_darts)) * 3;
+
+ EM_ASM({boatVisitRes($0, $1, $2, $3, $4, $5, $6, $7, $8)},
l->rem, v->n_darts, segment_points(v->darts[0]),
v->n_darts > 1 ? segment_points(v->darts[1]) : 0,
v->n_darts > 2 ? segment_points(v->darts[2]) : 0,
- s1, s2, s3);
+ s1, s2, s3, avg);
free(s1);
free(s2);
@@ -138,15 +147,29 @@ EMSCRIPTEN_KEEPALIVE void draw_match(struct match_state *state) {
}
if (l1->rem <= 0) {
- EM_ASM({promptMsg($0)}, "You win! :)");
- EM_ASM(matchOver());
+ EM_ASM(promptNumDarts());
+ //EM_ASM({promptMsg($0)}, "You win! :)");
+ //EM_ASM(matchOver());
} else if (l2->rem <= 0) {
EM_ASM({promptMsg($0)}, "Bot wins. :(");
EM_ASM(matchOver());
} else {
EM_ASM({promptMsg($0)}, "Enter points:");
}
+}
+
+EMSCRIPTEN_KEEPALIVE int resp_numdarts(struct match_state *state, int n_darts) {
+ if (n_darts < 1 || n_darts > 4)
+ return 0;
+
+ struct leg *l = state->l1;
+
+ EM_ASM({updateUserAvg($0)},
+ ((double)l->start / (((l->n_visits - 1) * 3) + n_darts)) * 3);
+ EM_ASM({promptMsg($0)}, "You win! :)");
+ EM_ASM(matchOver());
+ return 1;
}
void init_boat() {