Skip to content

fix(chess): flag flag-fall on a running clock in PlayerClock::time_out() - #944

Open
abdulwaarith0 wants to merge 1 commit into
OpenKnight-Foundation:mainfrom
abdulwaarith0:fix/941-timeout-running-clock
Open

fix(chess): flag flag-fall on a running clock in PlayerClock::time_out()#944
abdulwaarith0 wants to merge 1 commit into
OpenKnight-Foundation:mainfrom
abdulwaarith0:fix/941-timeout-running-clock

Conversation

@abdulwaarith0

Copy link
Copy Markdown
Contributor

Summary

PlayerClock::time_out() checked the raw remaining_time field, which is only decremented on stop(). While a clock is_running, elapsed time is not yet reflected in remaining_time, so a player who sits on a running clock past zero on their own turn was never reported as flagged — exactly the case flag-detection must catch.

The clock already has get_real_time_remaining(), which subtracts the running elapsed time. This routes time_out() through it:

pub fn time_out(&self) -> bool {
    self.get_real_time_remaining().is_zero()
}

Tests

Added unit tests in time_control.rs:

  • stopped clock reports timeout only when remaining_time is zero
  • running clock flags when it runs past zero on the mover (raw remaining_time is still non-zero; detection must come from real remaining time)
  • running clock with time left is not flagged

All three pass locally.

Closes #941

time_out() checked the raw remaining_time field, which is only decremented
on stop(). While a clock is_running, elapsed time is not yet reflected there,
so a player who sits on a running clock past zero on their own turn was never
reported as flagged. Route time_out() through get_real_time_remaining(), which
already accounts for the running clock, so on-the-move flag-fall is detected.

Adds unit tests for the stopped, running-past-zero, and running-with-time-left
cases.

Closes OpenKnight-Foundation#941
@abdulwaarith0

Copy link
Copy Markdown
Contributor Author

Heads up for reviewers: the failing Test Backend job is a pre-existing breakage on main, unrelated to this PR. The error is E0283: type annotations needed in modules/service/src/games.rs:616 and :678 (the append_query_results mock API under sea-orm 1.1.20) — my diff only touches backend/modules/chess/src/time_control.rs, which compiles cleanly. The last few Backend CI runs on main show the same failure. Happy to fix the games.rs type annotations in a separate PR if that'd be useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BE: PlayerClock::time_out() ignores a running clock (flag-fall undetected on the mover's turn)

1 participant