games: the short stack that could win money it never matched

A review pass, and it found the one that would have cost somebody real chips.

Side pots were only ever cut in runout() — the path taken when the betting
stops because nobody is left able to bet. But a hand reaches a showdown with an
all-in player in it and the betting having finished perfectly normally: a short
stack shoves, two players who still have chips behind call, and then keep
betting past them street after street to the river. Nothing was cut. One pot,
everybody eligible, and the short stack takes the lot — every chip the deep
players put in after they were already all-in, money that could never have been
lost to them. All-in for 100 against two players who each put in 500, and the
best hand collects 1,100 instead of the 300 it was playing for.

Chip conservation never saw it. The chips balance perfectly; they just land in
the wrong seat. And every browser session went through runout(), because a
player shoving is what ends the betting. It took reading the code.

Also from the review: play() dereferenced a table it had just been handed as
null, the top-up button offered chips the wallet could not cover, and the
trainer's ETA was sixty thousand hands optimistic on the first line it printed.

Claude-Session: https://claude.ai/code/session_013M5nD7PgUboJXoDcYHzpuJ
This commit is contained in:
prosolis
2026-07-14 09:16:52 -07:00
parent 903c5accdb
commit b96879d25c
8 changed files with 127 additions and 34 deletions

View File

@@ -158,7 +158,10 @@ func Train(n, workers int, t Tier, minBB, maxBB int64, seed uint64, progress fun
}
for i := 0; i < share; i++ {
tr.iterate(uint64(w)<<40 | uint64(i))
if progress != nil && i%2000 == 0 {
// i+1, not i: the check fired on the very first pass and credited two
// thousand hands before a single one had been walked, which with thirty
// workers made the first ETA sixty thousand hands optimistic.
if progress != nil && (i+1)%2000 == 0 {
done.Lock()
completed += 2000
c := completed
@@ -253,7 +256,7 @@ func (tr *trainer) iterate(id uint64) {
t := tr.tier
t.RakePct = 0
s, err := Open(t, stack, stack, id, tr.rng.Uint64())
s, err := open(t, stack, stack, id, tr.rng.Uint64())
if err != nil {
return
}
@@ -262,7 +265,7 @@ func (tr *trainer) iterate(id uint64) {
tr.have = [2][4]bool{} // one deal, one set of boards, one set of equities
for me := 0; me < 2; me++ {
tr.walk(s.Clone(), me, start, 0)
tr.walk(s.clone(), me, start, 0)
}
}
@@ -337,11 +340,11 @@ func (tr *trainer) walk(s State, me int, start [2]int64, depth int) float64 {
// play applies one abstract action through the real reducer.
func (tr *trainer) play(s State, seat, action int) State {
next, _, err := Step(s.Clone(), s.moveFor(action, seat))
next, _, err := step(s.clone(), s.moveFor(action, seat))
if err != nil {
// The mask and the rules disagreed, which is a bug in one of them. Fold and
// carry on rather than poison the whole run.
next, _, err = Step(s.Clone(), Move{Kind: Fold})
next, _, err = step(s.clone(), Move{Kind: Fold})
if err != nil {
return s
}