Build a preflop trainer in 50 lines
This guide builds a command-line preflop trainer: it deals you a hand in a chart spot, asks what you do, and grades your answer against the chart. It uses mode "hand" at a table you describe, so you do not need any ranges of your own.
1. Get a key and the SDK
Get a free key on the API page (100 solves a day is plenty here), then install the SDK and set the key.
Shell
pip install anongto export ANONGTO_API_KEY=agto_your_key
2. Describe the table and pick a spot
The table is described in every request: the seats in preflop order with their stacks, the rake, the ante and the straddle. A preflop spot is every action before the player to act, folds included: [] is the first decision, three folds (UTG, HJ, CO) are the button’s open, and those folds, the button’s raise to 2.5 and the small blind’s fold are the big blind facing a button open.
3. The trainer
trainer.py
import random
from anongto import Client
client = Client()
TABLE = {"max_seats": 6, "seats": [{"seat": s, "stack_bb": 100} for s in ("UTG", "HJ", "CO", "BTN", "SB", "BB")],
"rake": {"pct": 5, "cap_bb": 0.6}, "ante_bb": 0, "straddle": False}
fold = lambda seat: {"seat": seat, "type": "fold"}
SPOTS = [
[fold("UTG"), fold("HJ"), fold("CO")], # BTN opens?
[fold("UTG"), fold("HJ"), fold("CO"),
{"seat": "BTN", "type": "raise", "to_bb": 2.5}, fold("SB")], # BB vs a BTN open
[fold("UTG"), fold("HJ")], # CO opens?
]
cache = {}
def spot_answer(preflop):
key = repr(preflop)
if key not in cache: # one solve per spot, not per question
cache[key] = client.solve({"mode": "hand", "table": TABLE,
"streets": {"preflop": preflop}, "detail": "classes"})
return cache[key]
def said(preflop):
return ", ".join(f'{a["seat"]} {a["type"]} {a.get("to_bb", "")}'.strip() for a in preflop if a["type"] != "fold")
while True:
preflop = random.choice(SPOTS)
ans = spot_answer(preflop)
hands = [h for h, v in ans["hands"].items() if v["weight"] is None or v["weight"] > 0]
hand = random.choice(hands)
actions = [a["label"] for a in ans["actions"]]
print(f"\n{ans['to_act']} with {hand} after {said(preflop) or 'folds'}")
for i, a in enumerate(actions, 1):
print(f" {i}. {a}")
pick = actions[int(input("> ")) - 1]
strat = ans["hands"][hand]["strategy"]
best = max(strat, key=strat.get)
print("Chart:", ", ".join(f"{a} {p:.0%}" for a, p in strat.items() if p > 0))
print("Good." if strat.get(pick, 0) >= 0.25 else f"The chart mostly plays {best}.")4. Where to go next
- Add the flop: list the whole preflop line and send "flop": { "cards": [three cards], "actions": [] } for the first flop decision.
- Weight the deal by each hand’s weight so common hands come up more often.
- Move to Builder when friends start using it.