From 46d5c38b80b2e5f6b237ea0313ba23c408bdf7fe Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Wed, 18 May 2022 02:04:55 -0700 Subject: web: support first-visit undo when player 2 throws first --- web/static/sw.js | 2 +- web/web_control.c | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) (limited to 'web') diff --git a/web/static/sw.js b/web/static/sw.js index 1844274..ac33994 100644 --- a/web/static/sw.js +++ b/web/static/sw.js @@ -1,5 +1,5 @@ const CACHE_PREFIX = 'dartboat-' -const CACHE_VERSION = '14'; +const CACHE_VERSION = '15'; const CACHE_NAME = `${CACHE_PREFIX}${CACHE_VERSION}`; const CACHE_FILES = [ diff --git a/web/web_control.c b/web/web_control.c index fac1d8b..39b92ba 100644 --- a/web/web_control.c +++ b/web/web_control.c @@ -230,10 +230,22 @@ static void undo_active() state->active_leg = state->legs[state->active_player - 1]; } +static bool first_user_has_thrown() { + for (int i = 0, np = num_players(); i < np; ++i) { + int pn = match_opts->throws_first + i; + if (pn > np) + pn -= np; + + if (!player_is_comp(pn)) + return !!state->legs[pn - 1]->n_visits; + } + + return false; +} + void user_undo() { - // FIXME: undo doesn't work for first visit when player 2 throws first - if (!state->legs[0]->n_visits) { + if (!first_user_has_thrown()) { oi(); return; } -- cgit v1.2.3-70-g09d2