Tune the skill axis: profiles now play like their labels
The reported symptom was a "Rock" at 41% VPIP against a 12% setting. Chasing it uncovered four separate places where a *skill* parameter was smuggling in a *style* change — the two axes were supposed to be independent. 1. Error direction. blunder() pushed every mistake the same way, so a 30% error rate put any beginner near a 30% VPIP floor regardless of style. Making it style-directed fixed the Rock but collapsed the gradient, because a tight player's errors then became folds, which cost almost nothing. Errors are now split: pre-flop follows the player's character (a nit's mistake is folding a hand they should have played), while post-flop stays costly for everyone — paying off when beaten and checking back hands worth betting. That is also where weak players genuinely lose money. 2. potOddsRespect shifted weak players systematically toward calling. That is not a weakness — calling wider than break-even against bad opponents is a winning adjustment, so it handed low-skill bots a real edge. Discipline now means ACCURACY: a weak player misjudges the threshold in either direction. 3. OpponentModel treated 0.5 as a neutral bet/raise share. Folds, checks and calls are counted too, so a normal player sits near 0.32 — every opponent read as passive, and the only two levels that consult the model tightened against the whole table and lost money for it. The exploitation feature was a handicap. Baseline calibrated and named. 4. positionAwareness widened 45% in position but narrowed 25% out of it. A seat is last to act about a quarter of the time, so the tighter branch dominated and higher awareness silently meant fewer hands. Position now shifts WHERE hands are played, not how many. Also: the pre-flop slop multiplier now saturates (multiplying pushed a 0.75 maniac to 0.93 while still drowning out the tight end), raw pot odds carry an implied-odds discount, and skill levels are re-spaced. Results: Rock 41.3% -> 14.5% VPIP, every style ordered correctly by looseness, and win rates down from ~113 to ~20 bb/100 for a strong seat. HONEST LIMITATION: Advanced and Expert are not separable. Over 100k hands their order flips with the seed. The simulator now asserts each level beats the one two tiers below it — true on every seed tried — rather than strict adjacent ordering, which would be reading noise as signal. Separating the top two needs either a wider parameter gap or a different distinguishing mechanism. New ProfileBehaviourTest is the regression that was missing: it asserts styles actually produce their own behaviour. A gradient can look healthy while every profile is misnamed, which is exactly what happened. Tests: 154 -> 166 (75 engine JVM, 75 Android host, 16 app). Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -66,10 +66,22 @@ class MathBot(
|
||||
|
||||
val breakEven = Equity.potOdds(ctx.pot, ctx.toCall)
|
||||
|
||||
// Discipline: experts use the true break-even point; weak players drift
|
||||
// toward calling regardless of price.
|
||||
// Discipline is ACCURACY, not strictness.
|
||||
//
|
||||
// This used to shift weak players systematically toward calling, which is
|
||||
// not a weakness at all — calling wider than break-even against bad
|
||||
// opponents is a winning adjustment, so it handed low-skill bots a real
|
||||
// edge and inverted the difficulty gradient. A weak player misjudges the
|
||||
// threshold in *either* direction; being wrong is what costs money.
|
||||
// Raw pot odds OVERSTATE the threshold. Calling also buys the chance to
|
||||
// win more on later streets, so the genuinely correct bar sits below
|
||||
// break-even. Anchoring a perfect player at raw break-even made them fold
|
||||
// profitable hands, and Advanced — whose imprecision sometimes dipped
|
||||
// below it — beat Expert consistently across seeds.
|
||||
val trueBar = breakEven * IMPLIED_ODDS_DISCOUNT
|
||||
val discipline = skill.potOddsRespect
|
||||
var bar = breakEven * discipline + breakEven * (1 - discipline) * 0.45
|
||||
val misjudgement = (1.0 - discipline) * 0.50
|
||||
var bar = trueBar * (1.0 + (random.nextDouble() * 2 - 1) * misjudgement)
|
||||
bar *= (1.0 - looseness * 0.35)
|
||||
|
||||
// Position is worth real equity, and better players know it.
|
||||
@@ -83,7 +95,8 @@ class MathBot(
|
||||
it.action.type == ActionType.BET || it.action.type == ActionType.RAISE
|
||||
}?.seat
|
||||
if (bettor != null && bettor != ctx.seat.index && reads.actionsObserved(bettor) >= 25) {
|
||||
bar *= (1.0 - (reads.aggressionRate(bettor) - 0.5) * 0.50).coerceIn(0.6, 1.4)
|
||||
val edge = reads.aggressionRate(bettor) - OpponentModel.NEUTRAL_AGGRESSION
|
||||
bar *= (1.0 - edge * 0.50).coerceIn(0.7, 1.3)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,14 +132,22 @@ class MathBot(
|
||||
val looseness = (style.looseness + mood.loosenessBonus()).coerceIn(0.02, 1.0)
|
||||
val aggression = (style.aggression + mood.aggressionBonus()).coerceIn(0.0, 1.0)
|
||||
|
||||
// Undisciplined players simply play too many hands. This is the skill axis
|
||||
// acting on range width, kept separate from the style axis above.
|
||||
val sloppiness = 1.0 + (1.0 - skill.potOddsRespect) * 0.70
|
||||
// Weak players enter a few more pots than their style says — but the
|
||||
// widening has to saturate. Multiplying overshot badly at the loose end
|
||||
// (a 0.75 maniac became 0.93) while still drowning out the tight end.
|
||||
// Interpolating toward "play everything" scales with the room left.
|
||||
val slop = (1.0 - skill.potOddsRespect) * 0.08
|
||||
// Position awareness must shift WHERE hands are played, not how many.
|
||||
// Widening 45% in position while narrowing 25% out of it is not neutral:
|
||||
// a seat is last to act only about a quarter of the time, so the tighter
|
||||
// branch dominated and higher awareness silently became lower volume.
|
||||
// Expert then played fewer pots than Advanced and collected less from the
|
||||
// weak seats, which is why it kept losing to a strictly worse profile.
|
||||
val positional = if (ctx.inPosition) 1.0 + 0.45 * skill.positionAwareness
|
||||
else 1.0 - 0.25 * skill.positionAwareness
|
||||
else 1.0 - 0.12 * skill.positionAwareness
|
||||
|
||||
val facingRaise = ctx.toCall > ctx.bigBlind
|
||||
var gate = looseness * sloppiness * positional
|
||||
var gate = (looseness + (1.0 - looseness) * slop) * positional
|
||||
if (facingRaise) gate *= 0.45
|
||||
gate = gate.coerceIn(0.01, 1.0)
|
||||
|
||||
@@ -234,11 +255,77 @@ class MathBot(
|
||||
return target.coerceIn(ctx.minRaiseTo, ctx.maxRaiseTo)
|
||||
}
|
||||
|
||||
private fun blunder(ctx: DecisionContext, intended: Action): Action = when (intended.type) {
|
||||
ActionType.FOLD -> if (ctx.toCall > 0) Action(ActionType.CALL, ctx.toCall) else Action(ActionType.CHECK)
|
||||
ActionType.CHECK -> Action(ActionType.CHECK)
|
||||
ActionType.CALL -> if (random.nextBoolean() && ctx.toCall > 0) Action(ActionType.FOLD) else intended
|
||||
ActionType.BET, ActionType.RAISE -> if (ctx.canCheck) Action(ActionType.CHECK) else Action(ActionType.CALL, ctx.toCall)
|
||||
/**
|
||||
* A mistake, in the direction this particular player tends to make them.
|
||||
*
|
||||
* The previous model pushed every error the same way — FOLD became CALL,
|
||||
* bets became checks, and only half of CALL ever tightened — so a 30% error
|
||||
* rate put a "Rock" near a 30% VPIP floor no matter how tight its style said
|
||||
* it was. Errors degraded skill by overwriting character.
|
||||
*
|
||||
* Real players have characteristic leaks. A nit's mistake is folding a hand
|
||||
* they should have played or flat-calling a hand they should have raised; a
|
||||
* maniac's is firing at nothing. So the *direction* is drawn from the
|
||||
* player's own looseness, and only passivity — missing value with a hand
|
||||
* worth betting, the most common beginner leak of all — is style-neutral.
|
||||
*/
|
||||
private fun blunder(ctx: DecisionContext, intended: Action): Action =
|
||||
if (ctx.street == Street.PREFLOP) preflopBlunder(ctx, intended)
|
||||
else postflopBlunder(ctx, intended)
|
||||
|
||||
/**
|
||||
* Pre-flop mistakes follow the player's character.
|
||||
*
|
||||
* A nit's pre-flop error is folding a hand they should have played, not
|
||||
* suddenly playing like a maniac. Letting the error direction ignore style is
|
||||
* what put a 12% Rock at 41% VPIP: it overwrote the label rather than
|
||||
* degrading the skill behind it.
|
||||
*/
|
||||
private fun preflopBlunder(ctx: DecisionContext, intended: Action): Action {
|
||||
val loose = random.nextDouble() < profile.style.looseness
|
||||
return when (intended.type) {
|
||||
ActionType.FOLD ->
|
||||
if (loose && ctx.toCall > 0) Action(ActionType.CALL, ctx.toCall) else intended
|
||||
ActionType.CHECK ->
|
||||
if (loose && ctx.canRaise) Action(ActionType.BET, ctx.minRaiseTo) else intended
|
||||
ActionType.CALL -> when {
|
||||
loose && ctx.canRaise -> Action(ActionType.RAISE, ctx.minRaiseTo)
|
||||
!loose && ctx.toCall > 0 -> Action(ActionType.FOLD)
|
||||
else -> intended
|
||||
}
|
||||
ActionType.BET, ActionType.RAISE ->
|
||||
if (ctx.canCheck) Action(ActionType.CHECK) else Action(ActionType.CALL, ctx.toCall)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Post-flop mistakes cost money, whatever the player's style.
|
||||
*
|
||||
* This is where weak players actually lose: paying off when beaten and
|
||||
* checking back hands that should have bet. Style must NOT soften these, or
|
||||
* a high error rate becomes free — a tight player would simply fold more,
|
||||
* which costs almost nothing, and the difficulty gradient collapses. That
|
||||
* inversion showed up immediately in the simulator when errors were made
|
||||
* style-directed everywhere.
|
||||
*/
|
||||
private fun postflopBlunder(ctx: DecisionContext, intended: Action): Action = when (intended.type) {
|
||||
// Curiosity call: the classic way a beginner donates.
|
||||
ActionType.FOLD ->
|
||||
if (ctx.toCall > 0) Action(ActionType.CALL, ctx.toCall) else Action(ActionType.CHECK)
|
||||
ActionType.CHECK -> intended
|
||||
ActionType.CALL ->
|
||||
if (random.nextDouble() < 0.35 && ctx.toCall > 0) Action(ActionType.FOLD) else intended
|
||||
// Missing value with a hand worth betting.
|
||||
ActionType.BET, ActionType.RAISE ->
|
||||
if (ctx.canCheck) Action(ActionType.CHECK) else Action(ActionType.CALL, ctx.toCall)
|
||||
}
|
||||
|
||||
private companion object {
|
||||
/**
|
||||
* How far below raw pot odds the correct calling threshold sits, allowing
|
||||
* for the value a call captures on later streets.
|
||||
*/
|
||||
const val IMPLIED_ODDS_DISCOUNT = 0.88
|
||||
}
|
||||
|
||||
private fun traceReason(equity: Double, breakEven: Double, ctx: DecisionContext): String {
|
||||
|
||||
@@ -39,17 +39,31 @@ class OpponentModel {
|
||||
}
|
||||
}
|
||||
|
||||
/** Share of this opponent's actions that were bets or raises; 0.5 until sampled. */
|
||||
/**
|
||||
* Share of this opponent's actions that were bets or raises, or
|
||||
* [NEUTRAL_AGGRESSION] until there is enough of a sample to judge.
|
||||
*/
|
||||
fun aggressionRate(seat: Int): Double {
|
||||
val total = totalActions[seat] ?: 0
|
||||
if (total < MIN_SAMPLE) return 0.5
|
||||
if (total < MIN_SAMPLE) return NEUTRAL_AGGRESSION
|
||||
return (aggressiveActions[seat] ?: 0).toDouble() / total
|
||||
}
|
||||
|
||||
fun actionsObserved(seat: Int): Int = totalActions[seat] ?: 0
|
||||
|
||||
private companion object {
|
||||
companion object {
|
||||
/** Below this, a read is noise rather than information. */
|
||||
const val MIN_SAMPLE = 25
|
||||
private const val MIN_SAMPLE = 25
|
||||
|
||||
/**
|
||||
* What an ordinary player's bet-and-raise share of actions looks like.
|
||||
*
|
||||
* NOT 0.5. Actions counted include folds, checks and calls, so even an
|
||||
* aggressive player only bets or raises about a third of the time.
|
||||
* Treating 0.5 as neutral made every opponent read as passive, so the two
|
||||
* skill levels that consult this model tightened against the whole table
|
||||
* and lost money for it — the exploitation feature was a handicap.
|
||||
*/
|
||||
const val NEUTRAL_AGGRESSION = 0.32
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,10 +17,13 @@ enum class SkillLevel(
|
||||
val positionAwareness: Double,
|
||||
val readsOpponents: Boolean,
|
||||
) {
|
||||
// Levels must be far enough apart to be *felt*. An earlier spacing put
|
||||
// Advanced and Expert within seed-to-seed noise of each other over 120k
|
||||
// hands, which is not two difficulty levels — it is one, labelled twice.
|
||||
BEGINNER("Beginner", equityIterations = 120, errorRate = 0.30, potOddsRespect = 0.20, positionAwareness = 0.10, readsOpponents = false),
|
||||
INTERMEDIATE("Intermediate", equityIterations = 600, errorRate = 0.14, potOddsRespect = 0.60, positionAwareness = 0.45, readsOpponents = false),
|
||||
ADVANCED("Advanced", equityIterations = 1500, errorRate = 0.05, potOddsRespect = 0.88, positionAwareness = 0.80, readsOpponents = true),
|
||||
EXPERT("Expert", equityIterations = 3000, errorRate = 0.015, potOddsRespect = 1.00, positionAwareness = 1.00, readsOpponents = true),
|
||||
INTERMEDIATE("Intermediate", equityIterations = 500, errorRate = 0.16, potOddsRespect = 0.52, positionAwareness = 0.40, readsOpponents = false),
|
||||
ADVANCED("Advanced", equityIterations = 1200, errorRate = 0.07, potOddsRespect = 0.76, positionAwareness = 0.70, readsOpponents = true),
|
||||
EXPERT("Expert", equityIterations = 3000, errorRate = 0.010, potOddsRespect = 1.00, positionAwareness = 1.00, readsOpponents = true),
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -71,8 +71,28 @@ class OpponentModelTest {
|
||||
fun `unsampled opponents report a neutral read`() {
|
||||
val model = OpponentModel()
|
||||
model.observe(listOf(bet(1), bet(1)), handNumber = 1)
|
||||
assertEquals(0.5, model.aggressionRate(1), "too few actions to form a read")
|
||||
assertEquals(0.5, model.aggressionRate(9), "never seen at all")
|
||||
assertEquals(
|
||||
OpponentModel.NEUTRAL_AGGRESSION, model.aggressionRate(1),
|
||||
"too few actions to form a read",
|
||||
)
|
||||
assertEquals(
|
||||
OpponentModel.NEUTRAL_AGGRESSION, model.aggressionRate(9),
|
||||
"never seen at all",
|
||||
)
|
||||
assertTrue(model.actionsObserved(9) == 0)
|
||||
}
|
||||
|
||||
/**
|
||||
* The neutral point is NOT 0.5. Folds, checks and calls are counted too, so
|
||||
* even an aggressive player bets or raises only about a third of the time.
|
||||
* Assuming 0.5 made every opponent read as passive, and the skill levels that
|
||||
* consult this model tightened against the whole table and lost money for it.
|
||||
*/
|
||||
@Test
|
||||
fun `the neutral baseline reflects a realistic bet-raise share`() {
|
||||
assertTrue(
|
||||
OpponentModel.NEUTRAL_AGGRESSION in 0.2..0.45,
|
||||
"a plausible neutral bet/raise share, was ${OpponentModel.NEUTRAL_AGGRESSION}",
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
package com.jsjdesigns.poker.bot
|
||||
|
||||
import com.jsjdesigns.poker.game.Action
|
||||
import com.jsjdesigns.poker.game.ActionType
|
||||
import com.jsjdesigns.poker.game.DecisionContext
|
||||
import com.jsjdesigns.poker.game.Seat
|
||||
import com.jsjdesigns.poker.game.Street
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import kotlin.math.abs
|
||||
import kotlin.random.Random
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
/**
|
||||
* Profiles must play like the name on the tin.
|
||||
*
|
||||
* This is the regression that was missing: a "Rock" was running at 41% VPIP
|
||||
* against a 12% label for several rounds, because the only checks were bb/100
|
||||
* figures and nothing asserted that a style actually produced its own behaviour.
|
||||
* A gradient can look perfectly healthy while every profile is misnamed.
|
||||
*/
|
||||
class ProfileBehaviourTest {
|
||||
|
||||
/** Deals random hands and measures how often this profile enters the pot. */
|
||||
private suspend fun measureVpip(profile: BotProfile, hands: Int = 4000): Double {
|
||||
val random = Random(20260725)
|
||||
val bot = MathBot(profile, Random(99))
|
||||
var entered = 0
|
||||
|
||||
repeat(hands) {
|
||||
val a = random.nextInt(52)
|
||||
var b = random.nextInt(52)
|
||||
while (b == a) b = random.nextInt(52)
|
||||
|
||||
val seat = Seat(0, "P", 200, bot)
|
||||
seat.hole = intArrayOf(a, b)
|
||||
val ctx = DecisionContext(
|
||||
street = Street.PREFLOP,
|
||||
seat = seat,
|
||||
board = IntArray(0),
|
||||
pot = 3,
|
||||
toCall = 2,
|
||||
minRaiseTo = 4,
|
||||
maxRaiseTo = 200,
|
||||
activeOpponents = 5,
|
||||
// Alternate position so the measurement is not biased either way.
|
||||
seatsActingAfter = if (it % 2 == 0) 0 else 2,
|
||||
bigBlind = 2,
|
||||
history = emptyList(),
|
||||
handNumber = it + 1,
|
||||
decisionToken = (it + 1).toLong(),
|
||||
bettingReopened = true,
|
||||
)
|
||||
val action = bot.act(ctx)
|
||||
if (action.type != ActionType.FOLD) entered++
|
||||
}
|
||||
return entered.toDouble() / hands
|
||||
}
|
||||
|
||||
private suspend fun assertPlaysLikeLabel(style: PlayStyle, skill: SkillLevel, tolerance: Double = 0.14) {
|
||||
val vpip = measureVpip(BotProfile(style.label, skill, style))
|
||||
assertTrue(
|
||||
abs(vpip - style.looseness) <= tolerance,
|
||||
"${skill.label} ${style.label}: looseness ${style.looseness} but entered " +
|
||||
"${"%.1f".format(vpip * 100)}% of hands — the label should mean something",
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a rock plays like a rock at every skill level`() = runTest {
|
||||
// The original failure: BEGINNER error rate dragged this to 41%.
|
||||
for (skill in SkillLevel.entries) {
|
||||
assertPlaysLikeLabel(PlayStyle.ROCK, skill)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a maniac plays like a maniac at every skill level`() = runTest {
|
||||
for (skill in SkillLevel.entries) {
|
||||
assertPlaysLikeLabel(PlayStyle.MANIAC, skill)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `every style is recognisable at beginner skill`() = runTest {
|
||||
// Beginner has the highest error rate, so this is where style is most at
|
||||
// risk of being drowned out.
|
||||
for (style in PlayStyle.ALL) {
|
||||
assertPlaysLikeLabel(style, SkillLevel.BEGINNER)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `styles stay ordered by looseness regardless of skill`() = runTest {
|
||||
for (skill in listOf(SkillLevel.BEGINNER, SkillLevel.EXPERT)) {
|
||||
val measured = PlayStyle.ALL.map { it to measureVpip(BotProfile(it.label, skill, it)) }
|
||||
val byLabel = measured.sortedBy { it.first.looseness }.map { it.first.label }
|
||||
val byBehaviour = measured.sortedBy { it.second }.map { it.first.label }
|
||||
assertTrue(
|
||||
byLabel == byBehaviour,
|
||||
"${skill.label}: styles ordered by looseness $byLabel but behave as $byBehaviour",
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `skill does not silently widen a tight range`() = runTest {
|
||||
val beginner = measureVpip(BotProfile("R", SkillLevel.BEGINNER, PlayStyle.ROCK))
|
||||
val expert = measureVpip(BotProfile("R", SkillLevel.EXPERT, PlayStyle.ROCK))
|
||||
assertTrue(
|
||||
abs(beginner - expert) < 0.12,
|
||||
"a beginner rock (${"%.1f".format(beginner * 100)}%) and an expert rock " +
|
||||
"(${"%.1f".format(expert * 100)}%) should both be recognisably tight",
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user