From: Ian Jackson Date: Sat, 20 Mar 2021 21:37:45 +0000 (+0000) Subject: clock: Tidying, refactor, introduce initial() X-Git-Tag: otter-0.5.0~610 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=56652cf343354cbe54a42f099496c9f86ca6df83;p=otter.git clock: Tidying, refactor, introduce initial() Signed-off-by: Ian Jackson --- diff --git a/src/clock.rs b/src/clock.rs index 3f3acd39..44888a5f 100644 --- a/src/clock.rs +++ b/src/clock.rs @@ -56,6 +56,15 @@ struct Running { impl Spec { fn initial_time(&self) -> TimeSpec { TVL::seconds(self.time.into()) } fn per_move(&self) -> TimeSpec { TVL::seconds(self.per_move.into()) } + fn initial(&self) -> [TimeSpec; N] { + // White is player Y, and they will ge to go first, so the clock + // will go from stopped to Y, and then later when it's X's turn + // X will get an extra per_move. Y therefore needs per_move too. + [ + self.initial_time(), + self.initial_time() + self.per_move(), + ] + } } impl State { @@ -66,14 +75,9 @@ impl State { } fn reset(&mut self, spec: &Spec) { - for ust in &mut self.users { - ust.remaining = spec.initial_time(); + for (ust, t) in izip!(&mut self.users, spec.initial().iter().copied()) { + ust.remaining = t; } - // White is player Y, and they will ge to go first, so the clock - // will go from stopped to Y, and then later when it's X's turn - // X will get an extra per_move. Y therefore needs per_move too. - let y_remaining = &mut self.users[USERS[0]].remaining; - *y_remaining = *y_remaining + spec.per_move(); } fn implies_running(&self, held: Option) -> Option {