// The poker stats a streamer SAYS, read out of the cues by pure code // (release 30, lane P): the frame scan's second, cheap signal. A frame reading // that disagrees with a nearby spoken number is flagged, and a gap the frames // leave is filled from it (poker.ts `derive`). // // The cues are joined into one text so a phrase split across two cues ("eighty // five" | "players left") still reads, every number is normalized to digits // (numberWords.ts), and plain patterns read the fields. A match is dated by the // cue its first character came from. Rule-based: what the patterns do not // cover is not read, never guessed. import { normalizeNumbers } from "./numberWords"; import type { Cue, SpokenReading } from "./types"; type Piece = { at: number; t: number; cue: number }; // The joined, normalized text and where each cue's part of it starts. function joined(cues: readonly Cue[]): { text: string; pieces: Piece[] } { const pieces: Piece[] = []; let text = ""; cues.forEach((c, i) => { pieces.push({ at: text.length, t: c.start, cue: i }); text += `${normalizeNumbers(String(c.text ?? "")).replace(/\s+/g, " ").trim()} `; }); return { text: text.toLowerCase(), pieces }; } function pieceAt(pieces: readonly Piece[], at: number): Piece { let lo = 0; let hi = pieces.length - 1; while (lo < hi) { const mid = (lo + hi + 1) >> 1; if (pieces[mid].at <= at) lo = mid; else hi = mid - 1; } return pieces[lo]; } const N = String.raw`(\d+(?:\.\d+)?)`; const SOFT = String.raw`(?:about |around |like |only |just |roughly |almost |nearly |over |under )?`; // One field's patterns: the first capture group is the value. type Rule = { field: string; re: RegExp; min?: number; max?: number }; const RULES: Rule[] = [ { field: "playersLeft", re: new RegExp(String.raw`\b${N} (?:players|people|runners|entrants|left in the field|of us)(?: are)? (?:left|remaining)\b`, "g"), min: 1, max: 1_000_000 }, { field: "playersLeft", re: new RegExp(String.raw`\b(?:down to|we're at|we are at|there are|there's) ${SOFT}${N} (?:players )?(?:left|remaining)\b`, "g"), min: 1, max: 1_000_000 }, { field: "playersLeft", re: new RegExp(String.raw`\bplace out of ${N} (?:people|players|left)\b`, "g"), min: 1, max: 1_000_000 }, { field: "totalPlayers", re: new RegExp(String.raw`\b${N} (?:entrants|entries|runners|players registered|players total|total players)\b`, "g"), min: 2, max: 1_000_000 }, { field: "averageStack", re: new RegExp(String.raw`\baverage(?: stack| chip stack)?(?: is| was| of|'s)? ${SOFT}${N}\b`, "g"), min: 100 }, // The hero's stack in big blinds: "I'm down to 6 big blinds", "I have 22 bigs". { field: "stackBB", re: new RegExp(String.raw`\b(?:i have|i've got|i got|i'm at|i am at|i'm down to|i am down to|i'm sitting on|i'm sitting at|i'm on|my stack is) ${SOFT}${N} (?:big blinds|bigs|bbs|bb)\b`, "g"), min: 0, max: 100_000 }, // The hero's chips: "I have 233" (said without "thousand" beside an average // said with it: scaled below), "I've got 1500000 chips". { field: "stack", re: new RegExp(String.raw`\b(?:i have|i've got|i got|i'm at|i am at|i'm sitting on|i'm sitting at|my stack is|i'm up to|i'm down to) ${SOFT}${N}(?! (?:big blinds|bigs|bbs|bb|players|people|minutes|seconds|hours|dollars|bucks|percent|hands|cards|outs|times|kings|queens|jacks|aces|tens|nines|eights|sevens|sixes|fives|fours|threes|twos|of)\b)`, "g"), min: 100 }, { field: "buyIn", re: new RegExp(String.raw`\$?${N} (?:dollars? |bucks? )?buy[- ]?in\b`, "g"), min: 0.01 }, // "the buy in is six bucks" — and the ASR's "buying is like five bucks". { field: "buyIn", re: new RegExp(String.raw`\bbuy(?:[- ]?in|ing) (?:is|was|of|for) ${SOFT}\$?${N}\b`, "g"), min: 0.01 }, { field: "firstPrize", re: new RegExp(String.raw`\bfirst place (?:is |gets |pays |is worth |wins )?\$?${N}\b`, "g"), min: 1 }, { field: "prizePool", re: new RegExp(String.raw`\b(?:prize pool|guarantee)(?: is| of) \$?${N}\b`, "g"), min: 1 }, { field: "prizePool", re: new RegExp(String.raw`\$?${N} (?:dollars? |bucks? )?(?:in the |for the )?(?:prize pool|guaranteed?)\b`, "g"), min: 1 }, // The blind level, said as poker says it — never a bare "level N" (a // streamer who games says "a level eighty character" too). { field: "level", re: new RegExp(String.raw`\b(?:blind level|(?:we're|we are|it's|now|we're now) (?:at |on |in )?level) ${N}\b`, "g"), min: 1, max: 200 }, { field: "level", re: new RegExp(String.raw`\blevel ${N} (?:blinds|of the tournament)\b`, "g"), min: 1, max: 200 }, // The hero's place in the field: "I'm in 93rd place", "I moved up to 81st". { field: "position", re: new RegExp(String.raw`\b(?:i'm|i am) (?:in )?${N}(?:st|nd|rd|th)? place\b`, "g"), min: 1, max: 1_000_000 }, { field: "position", re: new RegExp(String.raw`\bmoved (?:up|down) to ${N}(?:st|nd|rd|th)?\b(?! (?:chips|big|bb|bbs|thousand|k)\b)`, "g"), min: 1, max: 1_000_000 }, ]; // The hero's own numbers said as a supposition ("once I'm down to seventy // thousand", "it's not like I'm sitting on fifty k") are not a reading: a // stack, big-blind or place match with one of these words just before it in // the same sentence is left out. const HERO_FIELDS = new Set(["stack", "stackBB", "position"]); const SUPPOSING = /\b(?:if|once|when|till|until|unless|by the time|not like|would|could|should|wanna|want to|gonna)\b[^.!?]*$/; // "blinds are 1500 3000", "blinds 5 10", "1500 3000 blinds": both blinds. const BLINDS = [ new RegExp(String.raw`\bblinds (?:are |at |now |of |going up to |are going up to |up to )?${N}(?: ?/ ?| and | to | )${N}\b`, "g"), new RegExp(String.raw`\b${N}(?: ?/ ?| )${N} blinds\b`, "g"), ]; /** Every spoken poker stat in the cues, in time order. */ export function pokerSpoken(cues: readonly Cue[]): SpokenReading[] { if (!cues.length) return []; const { text, pieces } = joined(cues); const out: SpokenReading[] = []; const at = (index: number) => pieceAt(pieces, index); const words = (p: Piece) => String(cues[p.cue].text ?? "").replace(/\s+/g, " ").trim().slice(0, 160); for (const rule of RULES) { rule.re.lastIndex = 0; let m: RegExpExecArray | null; while ((m = rule.re.exec(text))) { const v = Number(m[1]); if (!Number.isFinite(v)) continue; if (rule.min !== undefined && v < rule.min) continue; if (rule.max !== undefined && v > rule.max) continue; if (HERO_FIELDS.has(rule.field) && SUPPOSING.test(text.slice(Math.max(0, m.index - 40), m.index))) continue; const p = at(m.index); out.push({ t: p.t, field: rule.field, value: v, text: words(p) }); } } for (const re of BLINDS) { re.lastIndex = 0; let m: RegExpExecArray | null; while ((m = re.exec(text))) { const sb = Number(m[1]); const bb = Number(m[2]); // A big blind is the small one's double (or so): anything else is two // numbers that happen to sit beside "blinds". if (!(sb > 0 && bb > sb && bb <= sb * 3)) continue; const p = at(m.index); out.push({ t: p.t, field: "bigBlind", value: bb, text: words(p) }); out.push({ t: p.t, field: "smallBlind", value: sb, text: words(p) }); } } out.sort((a, b) => a.t - b.t || a.field.localeCompare(b.field)); return scaleStacks(dedupe(out)); } // The same field and value said again within 30 s is one reading. function dedupe(rs: SpokenReading[]): SpokenReading[] { const out: SpokenReading[] = []; for (const r of rs) { if (out.some((o) => o.field === r.field && o.value === r.value && Math.abs(o.t - r.t) <= 30)) continue; out.push(r); } return out; } // The magnitude of the average decides only whether a small stack is // thousands; a half hour away it still has the right number of digits. const AVERAGE_WINDOW_S = 1800; // "the average stack is three hundred seventy three thousand… I have two // hundred thirty three": a stack said under 1000 within half an hour of an // average said in the thousands, and within 50× of it once scaled, is // thousands too (marked `approx`). One still under 1000 with no such average // is left out: a tournament stack is rarely that small, and the number is // more likely something else. function scaleStacks(rs: SpokenReading[]): SpokenReading[] { const out: SpokenReading[] = []; for (const r of rs) { if (r.field !== "stack" || r.value >= 1000) { out.push(r); continue; } const avg = rs .filter((o) => o.field === "averageStack" && o.value >= 10_000 && Math.abs(o.t - r.t) <= AVERAGE_WINDOW_S) .sort((a, b) => Math.abs(a.t - r.t) - Math.abs(b.t - r.t))[0]; const scaled = r.value * 1000; if (avg && scaled >= avg.value / 50 && scaled <= avg.value * 50) out.push({ ...r, value: scaled, approx: true }); } return out; }