From 28235dad1e08afa6bcbf794238b3b242ca6f401e Mon Sep 17 00:00:00 2001 From: Jani Nikula Date: Sat, 3 Dec 2022 15:10:13 +0200 Subject: [PATCH] fix frame end handling Detect winners/losers during breaks to clarify what's going to happen. End frame on last black foul. Automatically respot black on equal score at end of frame. Log frame stats at end of frame, not at beginning of new frame. --- docs/manual.rst | 7 +++++-- src/lib/State.ts | 16 ++++++++++++---- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/docs/manual.rst b/docs/manual.rst index de3af83..568d08a 100644 --- a/docs/manual.rst +++ b/docs/manual.rst @@ -89,8 +89,7 @@ Press the snooker ball buttons to pot (numbers **1-7** on the keyboard). the number of balls left on the `Edit Page`_. * If, after all balls have been potted, two (or all) players have equal points, - increase the number of balls left on the `Edit Page`_ to add black as the - respotted black. + the game continues with a re-spotted black. Press the foul ball buttons to enter fouls (**f** key immediately followed by numbers **4-7** on the keyboard). @@ -104,6 +103,10 @@ numbers **4-7** on the keyboard). * If the previous player committed a foul, you can request them to play again using the **PLAY AGAIN** button. +* If there's a foul with just the last black remaining, the frame ends. If two + (or all) players have equal points, the game continues with a re-spotted + black. + Press the **END TURN** button to end turn (space bar on the beyboard). Fouls end turn automatically. diff --git a/src/lib/State.ts b/src/lib/State.ts index d6af1fb..a84d81c 100644 --- a/src/lib/State.ts +++ b/src/lib/State.ts @@ -337,6 +337,12 @@ class State { this.cur_pid = player.pid; this.cur_pos = player.pos; } + + // end frame or respot black? + if (this._is_frame_over()) + this._end_frame(); + else if (this.num_colors() === 0) + this._num_balls++; } _pot_points(points: number): void { @@ -345,9 +351,10 @@ class State { let p: Player = this.current_player(); p.pot_points(points); - // game over if (this.num_points() === 0) this._end_turn(); + else + this._detect_win_lose(); } _can_pot_red(): boolean { @@ -423,6 +430,10 @@ class State { player.log_foul(value); + // foul on last black, drop ball count to zero to cause end frame + if (this.num_colors() === 1) + this._num_balls--; + this._end_turn(); this.foul = true; @@ -454,9 +465,6 @@ class State { } new_frame(): void { - // FIXME: this should happen earlier, when frame is over - this._end_frame(); - // game this.cur_perm++; if (this.cur_perm >= permutations.length)