summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--match.c23
-rw-r--r--match.h2
-rw-r--r--web/dartboat_wasm.c9
3 files changed, 26 insertions, 8 deletions
diff --git a/match.c b/match.c
index 6bd1426..d8f8a23 100644
--- a/match.c
+++ b/match.c
@@ -34,3 +34,26 @@ void leg_grow_visits(struct leg *l)
l->visits = realloc(l->visits, 2 * bytes);
memset((char *)l->visits + bytes, 0, bytes);
}
+
+bool is_points_valid(int pts, int rem)
+{
+ return pts <= rem &&
+ rem - pts != 1 &&
+ pts >= 0 &&
+ pts <= 180 &&
+ pts != 179 &&
+ pts != 178 &&
+ pts != 176 &&
+ pts != 175 &&
+ pts != 173 &&
+ pts != 172 &&
+ pts != 169 &&
+ pts != 166 &&
+ pts != 163 &&
+ (rem - pts != 0 ||
+ (pts <= 170 &&
+ pts != 168 &&
+ pts != 165 &&
+ pts != 162 &&
+ pts != 159));
+}
diff --git a/match.h b/match.h
index ef75bac..ce52717 100644
--- a/match.h
+++ b/match.h
@@ -23,4 +23,6 @@ struct leg *leg_init(int points, char *name);
void leg_free(struct leg *l);
void leg_grow_visits(struct leg *l);
+bool is_points_valid(int pts, int rem);
+
#endif
diff --git a/web/dartboat_wasm.c b/web/dartboat_wasm.c
index b4d232a..658277d 100644
--- a/web/dartboat_wasm.c
+++ b/web/dartboat_wasm.c
@@ -309,14 +309,7 @@ void update_player_avg(int pn, int n_darts)
EMSCRIPTEN_KEEPALIVE void user_visit(int points)
{
- if (points < 0 || points > state->active_leg->rem ||
- state->active_leg->rem - points == 1 ||
- points > 180 || points == 179 || points == 178 || points == 176 ||
- points == 175 || points == 173 || points == 172 || points == 169 ||
- points == 166 || points == 163 ||
- (state->active_leg->rem - points == 0 &&
- (points > 170 || points == 168 || points == 165 || points == 162 ||
- points == 159))) {
+ if (!is_points_valid(points, state->active_leg->rem)) {
EM_ASM(oi());
return;
}