From: Ian Jackson Date: Sat, 20 Mar 2021 21:32:54 +0000 (+0000) Subject: clock: Tidying, introduce ChessClock::per_move() X-Git-Tag: otter-0.5.0~612 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=4b8c6ddd55b8274b24704b0d74ef5d259cc2a0e4;p=otter.git clock: Tidying, introduce ChessClock::per_move() Signed-off-by: Ian Jackson --- diff --git a/src/clock.rs b/src/clock.rs index 604c59db..04ad0d71 100644 --- a/src/clock.rs +++ b/src/clock.rs @@ -54,9 +54,8 @@ struct Running { } impl ChessClock { - fn initial_time(&self) -> TimeSpec { - TVL::seconds(self.time.into()) - } + fn initial_time(&self) -> TimeSpec { TVL::seconds(self.time.into()) } + fn per_move(&self) -> TimeSpec { TVL::seconds(self.per_move.into()) } } impl State { @@ -74,7 +73,7 @@ impl State { // 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 + TVL::seconds(spec.per_move.into()); + *y_remaining = *y_remaining + spec.per_move(); } fn implies_running(&self, held: Option) -> Option { @@ -258,7 +257,7 @@ impl State { if now_current != was_current; then { let remaining = &mut state.users[now_current.user].remaining; - *remaining = *remaining + TVL::seconds(spec.per_move.into()); + *remaining = *remaining + spec.per_move(); } }