Golf: 8-card grids, chosen openers, final putt, end-of-hole score card

- An 8-card variant, laid out as two rows of four. The existing column
  scoring covers it without change.

- Opening cards are now chosen rather than dealt face up. Nothing starts
  revealed; each player in turn turns over their allowance, and the hole
  begins once everyone has picked. This needed a new SETUP phase in the
  engine, since it is a real decision and has to be validated like any
  other move rather than being decided at deal time.

- "Line up the final putt", off by default: throw a drawn card away
  without turning your last face-down card over, so you are not forced to
  close the hole on a card you did not choose. Only offered on the last
  face-down card. Because a whole table could otherwise decline forever,
  two full laps of nothing but thrown cards calls the hole and scores it
  where it stands.

- The end of a hole now shows a score card — every player's strokes for
  the hole and their running total, lowest first — and the next hole is
  not dealt until it is dismissed. MatchController gained a general
  awaitsConfirmation hook for this, so any game wanting a scoreboard
  between rounds can stop the table the same way. Only the host waits;
  clients render what they are sent.

Nine more Golf tests, covering the 8-card layout, the opening choice,
when the putt option is and is not offered, and that a table refusing to
putt out still finishes.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_015qjfMiPUDshdKEUa6vxqzN
This commit is contained in:
Claude
2026-08-06 03:59:53 +00:00
parent 532c3ea48a
commit d989907d7e
9 changed files with 458 additions and 52 deletions
@@ -47,6 +47,12 @@ class MatchController<S : Any, M : Any>(
* next card lands on top of it.
*/
private val holdBeforeNextMove: (S) -> Long = { 0L },
/**
* States that should not advance on their own — an end-of-round scoreboard
* the players need to read before the next deal. The controller stops and
* waits for [confirmAdvance].
*/
private val awaitsConfirmation: (S) -> Boolean = { false },
) {
enum class Role { HOST, CLIENT }
@@ -65,6 +71,11 @@ class MatchController<S : Any, M : Any>(
private val _notice = MutableStateFlow<String?>(null)
val notice: StateFlow<String?> = _notice.asStateFlow()
private val _awaitingConfirmation = MutableStateFlow(false)
/** True while a scoreboard is up and the table is waiting to be released. */
val awaitingConfirmation: StateFlow<Boolean> = _awaitingConfirmation.asStateFlow()
/** Host only: the true state. Clients never see this. */
private var authoritative: S? = null
private val lock = Mutex()
@@ -198,6 +209,12 @@ class MatchController<S : Any, M : Any>(
val seat = rules.currentSeat(current)
if (seat == null) {
// Nobody on the clock: a hand has been scored, or the game ended.
if (role == Role.HOST && awaitsConfirmation(current)) {
// Hold here until a player has read the scoreboard. Only the
// host waits; clients simply render what they were sent.
_awaitingConfirmation.value = true
return
}
delay(aiThinkingMillis() * 2)
val advanced = advanceIdle(current)
if (advanced == null) {
@@ -261,6 +278,18 @@ class MatchController<S : Any, M : Any>(
}
}
/**
* Releases a table stopped on a scoreboard. A no-op anywhere else, and on a
* client — where the host owns the decision — it does nothing but clear the
* local flag.
*/
fun confirmAdvance() {
if (!_awaitingConfirmation.value) return
_awaitingConfirmation.value = false
if (role != Role.HOST) return
scope.launch { driveIdleSeats() }
}
fun close() {
peers.values.forEach { runCatching { it.close() } }
peers.clear()