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.c24
1 files changed, 18 insertions, 6 deletions
diff --git a/web/dartboat_wasm.c b/web/dartboat_wasm.c
index ede1b59..200621e 100644
--- a/web/dartboat_wasm.c
+++ b/web/dartboat_wasm.c
@@ -20,6 +20,8 @@ struct match_state {
int complete;
};
+int undone_count = 0;
+
struct match_state *state;
void set_user_active() {
@@ -82,8 +84,7 @@ 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;
+ int n_visits = l1->n_visits > l2->n_visits ? l1->n_visits : l2->n_visits;
for (int i = 0; i < n_visits; ++i) {
sprintf(visit_no, "%d", i + 1);
@@ -156,7 +157,7 @@ EMSCRIPTEN_KEEPALIVE void update_boat_rem(int rem) {
get_suggested(rem, P_BOAT);
}
-void end_boat_throwing(int, int); // FIXME
+void end_boat_throwing(int, double); // FIXME
EMSCRIPTEN_KEEPALIVE void boat_visit() {
if (state->l1->rem <= 0 || state->l2->rem <= 0)
@@ -165,7 +166,12 @@ EMSCRIPTEN_KEEPALIVE void boat_visit() {
EM_ASM({promptMsgL($0)}, "Bot is throwing…");
struct leg *l = state->l2;
- comp_visit(l);
+ if (undone_count) {
+ --undone_count;
+ l->rem = l->visits[l->n_visits++].rem;
+ } else {
+ comp_visit(l);
+ }
struct visit *v = l->visits + l->n_visits - 1;
@@ -224,7 +230,7 @@ EMSCRIPTEN_KEEPALIVE bool user_visit(int points) {
EM_ASM({clearVisits()});
draw_match();
- if (!is_match_over() && l->n_visits > state->l2->n_visits) {
+ if (!is_match_over()) {
set_boat_active();
boat_visit();
}
@@ -246,9 +252,15 @@ EMSCRIPTEN_KEEPALIVE bool user_undo() {
struct leg *l = state->l1;
struct visit *v = l->visits + --l->n_visits;
l->rem += v->points;
+ state->l2->rem += state->l2->visits[--state->l2->n_visits].points;
+ ++undone_count;
EM_ASM({updatePlayerAvg($0, $1)}, P_USER,
l->n_visits ? (double)(l->start-l->rem)/l->n_visits : 0);
+ EM_ASM({updatePlayerAvg($0, $1)}, P_BOAT,
+ state->l2->n_visits ? (double)(state->l2->start-state->l2->rem)/state->l2->n_visits : 0);
+ update_user_rem(l->rem);
+ update_boat_rem(state->l2->rem);
memcpy(v, 0, sizeof(*v));
@@ -269,7 +281,7 @@ EMSCRIPTEN_KEEPALIVE void draw_boat_throwing(int pts, char *str) {
EM_ASM({promptMsgR($0)}, str);
}
-EMSCRIPTEN_KEEPALIVE void end_boat_throwing(int rem, int avg) {
+EMSCRIPTEN_KEEPALIVE void end_boat_throwing(int rem, double avg) {
update_boat_rem(rem);
EM_ASM({updatePlayerAvg($0, $1)}, P_BOAT, avg);
EM_ASM({setPromptInput($0)}, "");