From: Ian Jackson Date: Sat, 20 Mar 2021 21:22:20 +0000 (+0000) Subject: clock: Fix per_move implementation (try to) X-Git-Tag: otter-0.5.0~616 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=151555ca9b21254405cca878b34c3a07bb0dcbca;p=otter.git clock: Fix per_move implementation (try to) This still doesn't work when it needs to because typically the clock is paused in both cases and this function then exits early. Signed-off-by: Ian Jackson --- diff --git a/src/clock.rs b/src/clock.rs index 6ec1912e..b22b5e13 100644 --- a/src/clock.rs +++ b/src/clock.rs @@ -147,7 +147,7 @@ struct UState { #[serde(with="timespec_serde")] remaining: TimeSpec, // -ve means flag } -#[derive(Debug,Copy,Clone,Serialize,Deserialize)] +#[derive(Debug,Copy,Clone,Eq,PartialEq,Serialize,Deserialize)] struct Current { user: User, } @@ -237,7 +237,7 @@ impl Clock { impl State { #[throws(IE)] fn do_start_or_stop(&mut self, piece: PieceId, - _was_current: Option, + was_current: Option, was_implied_running: Option, held: Option, spec: &ChessClock, @@ -256,11 +256,11 @@ impl State { } if_chain! { - if let Some(was_running_user) = was_implied_running; - if let Some(now_running_user) = state.implies_running(held); - if now_running_user != was_running_user; + if let Some(was_current) = was_current; + if let Some(now_current) = state.current; + if now_current != was_current; then { - let remaining = &mut state.users[now_running_user].remaining; + let remaining = &mut state.users[now_current.user].remaining; *remaining = *remaining + TVL::seconds(spec.per_move.into()); } }