summaryrefslogtreecommitdiff
path: root/web/web_match.c
diff options
context:
space:
mode:
authorDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2022-05-18 16:43:03 -0700
committerDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2022-05-18 16:43:03 -0700
commit3fda7193b52eed1c724b6d5e5b8373c0a3fbf963 (patch)
treee6916ee48ade665f70b9316c34b9755671c422a7 /web/web_match.c
parentde975396fe9eccd8f54c798b082c3d690b05c524 (diff)
downloaddartboat-3fda7193b52eed1c724b6d5e5b8373c0a3fbf963.tar.gz
dartboat-3fda7193b52eed1c724b6d5e5b8373c0a3fbf963.tar.xz
web: move match info funcs to match file
Diffstat (limited to 'web/web_match.c')
-rw-r--r--web/web_match.c47
1 files changed, 45 insertions, 2 deletions
diff --git a/web/web_match.c b/web/web_match.c
index 432808d..aabea4d 100644
--- a/web/web_match.c
+++ b/web/web_match.c
@@ -24,6 +24,11 @@ void match_opts_free()
match_opts = NULL;
}
+struct leg *state_active_leg()
+{
+ return state->legs[state->active_player - 1];
+}
+
int match_num_players()
{
if (state->mode == M_P)
@@ -47,7 +52,45 @@ bool match_is_over()
return match_winning_player() != -1;
}
-struct leg *state_active_leg()
+int match_prev_player()
{
- return state->legs[state->active_player - 1];
+ if (state->active_player == 1)
+ return match_num_players();
+ else
+ return state->active_player - 1;
+}
+
+int match_next_player()
+{
+ if (state->active_player == match_num_players())
+ return 1;
+ else
+ return state->active_player + 1;
+}
+
+int match_prev_throw_player()
+{
+ if (match_is_over())
+ return state->active_player;
+
+ return match_prev_player();
+}
+
+bool match_player_is_comp(int pn)
+{
+ return state->mode == M_PVC && pn == 2;
+}
+
+bool match_first_user_has_thrown()
+{
+ for (int i = 0, np = match_num_players(); i < np; ++i) {
+ int pn = match_opts->throws_first + i;
+ if (pn > np)
+ pn -= np;
+
+ if (!match_player_is_comp(pn))
+ return !!state->legs[pn - 1]->n_visits;
+ }
+
+ return false;
}