A phone on the studio desk at night, screen dark, a notification glowing.
The room from the homepage, with the phone on the desk.

05 · Percival · Discord bot

My friends bet on each other’s games.

Percival is a Discord bot I built. It sets the odds with real math, takes bets in fake money, and pays out when the match ends.

1/9

Percivalthe-loungePercival · prop bets on us, priced by math

Recreation. Percival’s real board runs in a private server, so this channel is rebuilt for this page: the same embed shapes and colours bot.py writes, with stand-in gamertags (LanternJaw77, QuietFox09, NorthPaw21) and illustrative kill averages (λ). No real stats or handles appear (private/roster.json).

One board. Priced to each player.

LanternJaw77Today at 8:04 PM

LanternJaw77 used /session_create

🎯 Prop Board

Session: S-104
Host: LanternJaw77

👤 LanternJaw77
P02 Kills — over 8.5 — 3.03
👤 NorthPaw21
P09 Kills — over 4.5 — 2.71

a 'hard' bet is hard for everyone: a better player has to score more kills (eliminations in the match) to win the same bet · made-up numbers, real format

Poisson prices it.

PercivalBOTToday at 8:06 PM

Percival used /pick

Place Bet

Session: S-104
Player: LanternJaw77
Pick a prop:

Props

🟡 Kills — over 6.5 — 1.90×

012345678910111213141516+
Drag λ, the player’s average kills per match: the bars, the line and the price all redraw from the same three functions board.py uses (CODE 5.1). Keys: ← → step λ.

Poisson is an 1837 formula for how often something happens. Here it sets the number you bet over or under, and what a win pays (the math is in the details below)

No two players get the same board.

LanternJaw77Today at 8:04 PM

🎯 Prop Board

Session: S-104

👤 LanternJaw77
P03 Kills — over 5.5 — 1.35
TF1 Top frag — 63.7% — 2.50
👤 QuietFox09
P06 Kills — over 5.5 — 1.98
BF1 Bottom frag — 26.7% — 3.37

every session deals each player their own mix of easy, medium and hard bets, so you can't only bet on whoever's hot. Numbers made up for the demo

Pick a bet. Never on yourself.

QuietFox09Today at 8:11 PM

QuietFox09 used /bet

bets: P02 20, P06 10

Only you can see this

❌ Cannot bet on your own props (P06).

✅ Bet added: P02 — 20.00 on 🔴 Kills over 8.5.

type a bet code and how much, up to 5 open bets. The bot refuses a bet on your own line

The host reports it. Bets settle.

LanternJaw77Today at 8:41 PM

LanternJaw77 used /report

report_text: “LanternJaw77 12/4 top_frag, QuietFox09 6/6, NorthPaw21 4/9 · WIN”

PercivalBOTToday at 8:41 PM

🏁 Match Settlement

Session S-104 • Outcome FINAL

QuietFox09 • Net +40.60
✅ 🔴 P02 Kills over 8.5 — Stake 20.00 → Returned 60.60

a hit pays stake × odds, a miss pays nothing, a push hands the stake back · settle_all_open_bets_to_db

Fake money. Real bragging rights.

QuietFox09Today at 8:42 PM

bet my whole bank on LanternJaw77’s top frag and it hit 😤

🔥 4💀 2😭 1

nothing real changes hands. It's a running balance between friends, and the group chat does the rest

All the math, written by hand.

0math libraries used. The Poisson formula is typed out by hand, board.py:258-268

no ready-made math library anywhere, and the whole thing is still just Discord commands · 3,261 lines of Python

The Poisson distribution, three functions long.

CODE 5.1percival/board.py:258-268
def poisson_pmf(k: int, lam: float) -> float:
    if k < 0:
        return 0.0
    return math.exp(-lam) * (lam ** k) / math.factorial(k)

def poisson_cdf(k: int, lam: float) -> float:
    return sum(poisson_pmf(i, lam) for i in range(0, k + 1))

def poisson_sf(k: int, lam: float) -> float:
    """P(X >= k)"""
    return 1.0 - poisson_cdf(k - 1, lam)
CODE 5.2percival/board.py:333-340
def sample_poisson(lam: float) -> int:
    L = math.exp(-lam)
    k = 0
    p = 1.0
    while p > L:
        k += 1
        p *= rand.random()
    return k - 1

Knuth’s method: multiply random draws until the product falls below e^−λ. It is the sampler behind every draw in the demo above.

20,000 simulated lobbies, fractional credit on ties.

CODE 5.3percival/board.py:194-219
    def frag_probabilities(self, players, trials: int = 20000):
        top_counts = {str(p.discord_id): 0 for p in players}
        bot_counts = {str(p.discord_id): 0 for p in players}

        ids  = [str(p.discord_id) for p in players]
        lams = [max(0.1, float(p.kills)) for p in players]

        for _ in range(trials):
            samples = [sample_poisson(l) for l in lams]
            mx = max(samples)
            mn = min(samples)

            top_idx = [i for i, v in enumerate(samples) if v == mx]
            bot_idx = [i for i, v in enumerate(samples) if v == mn]

            top_share = 1.0 / len(top_idx)
            bot_share = 1.0 / len(bot_idx)

            for i in top_idx:
                top_counts[ids[i]] += top_share
            for i in bot_idx:
                bot_counts[ids[i]] += bot_share

        top_prob = {pid: top_counts[pid] / trials for pid in ids}
        bot_prob = {pid: bot_counts[pid] / trials for pid in ids}
        return top_prob, bot_prob
CODE 5.4percival/board.py:270-272
def decimal_odds_from_prob(p: float, vig: float = 0.90, min_odds: float = 1.05, max_odds: float = 25.0) -> float:
    p = max(1e-6, min(1 - 1e-6, p))
    return max(min_odds, min(max_odds, (1.0 / p) * vig))

Top and bottom frag have no closed form across a whole lobby, so they’re simulated. The demo above runs a TypeScript port of these functions. Checked against the Python on 23 Sep 2026: for λ = 7.2, 5.4 and 3.8, all nine kills-over lines and prices match pick_kills_over_line_with_band exactly.

Counted, with the date they were counted.

lines of Python across 15 files (wc -l)
3,261as of 22 Sep 2026
lines in bot.py, the Discord layer
1,600as of 22 Sep 2026
simulated lobbies per board
20,000as of 22 Sep 2026
decimal odds clamp
1.05 – 25.0as of 22 Sep 2026
statistics libraries: the Poisson is hand-written
0as of 22 Sep 2026

What I don’t claim.

One bot, one engine, one database.

Private repository. The code samples above are the real thing, copied with their line numbers.

Proves Poisson models and 20,000-trial Monte Carlo simulation, written from the math rather than imported; SurrealDB (résumé → Percival).

Elsewhere in this portfolio

  1. 01 Résumé
  2. 02 Bishop
  3. 03 OTD
  4. 04 dub
  5. 05 Percival
  6. 06 Team game
  7. 07 Audio
  8. 08 Teaching
  9. 09 Sacred Lands
  10. 10 Skills
  11. 11 About