Skip to content
[OPEN_POKER]

Claude या GPT-4 को अपने Poker Bot का Brain बनाएं (Working Code)

JJoão Carvalho||5 min read

आप Claude या GPT-4 को poker bot से करीब 80 lines Python में connect कर सकते हैं। LLM your_turn message पढ़ता है, decide करता है क्या करना है, और आपका bot action execute करता है। Claude Haiku से roughly $0.30 per 100 hands cost आता है, decisions 600-900ms में लेता है, और calling station को आसानी से beat करता है। Tuned heuristic bot को नहीं beat करेगा, लेकिन functional decision engine का सबसे तेज़ रास्ता है।

LLM को poker bot decision engine क्यों बनाएं?

तीन reasons, importance के order में।

Iteration speed। Heuristic bot को tune करने में weeks लगते हैं। LLM bot को बस एक prompt चाहिए। Early-stage development के लिए 10x speedup।

Novel spots पर natural-language reasoning। Poker में long-tail situations होती हैं जो heuristic bots बुरी तरह handle करते हैं। LLM ने काफी poker content पढ़ा है और आपकी hardcoded logic ने जो anticipate नहीं किया उन spots में reasonable decision ले सकता है।

Free baseline improvement। Modern LLMs "competent intermediate" level पर play कर सकते हैं। $0.003 per decision में किसी और का strategy work मिल जाता है।

Catch: LLMs slow हैं (600-1500ms per decision), scale पर expensive, और well-tuned heuristic bot जितने sharp नहीं। Starting point की तरह use करें, endpoint की तरह नहीं।

Minimum LLM bot setup क्या है?

तीन pieces: Open Poker WebSocket connection, LLM API client, और prompt जो your_turn message को model के answer करने लायक question में बदले।

pip install websockets anthropic

दो environment variables set करें: OPEN_POKER_API_KEY और ANTHROPIC_API_KEY। Full bot:

import asyncio
import json
import os
import websockets
from anthropic import AsyncAnthropic
 
API_KEY = os.environ["OPEN_POKER_API_KEY"]
WS_URL = "wss://openpoker.ai/ws"
client = AsyncAnthropic()
 
PROMPT = """You are playing 6-max No-Limit Hold'em at 10/20 blinds.
Decide what action to take based on the game state below.
 
Your hole cards: {hole_cards}
Community cards: {community_cards}
Pot size: {pot}
Your stack: {my_stack}
Your current bet: {my_bet}
Position (0=BTN, 1=SB, 2=BB, 3=UTG, etc): {seat}
Valid actions: {valid_actions}
 
Respond with ONLY a JSON object: {{"action": "fold|check|call|raise|all_in", "amount": <int or 0>}}
For raise, amount is the raise-to total (not increment). For check/call/fold, amount is 0.
"""
 
async def decide_action(state, hole_cards):
    prompt = PROMPT.format(
        hole_cards=hole_cards or "unknown",
        community_cards=state.get("community_cards", []),
        pot=state.get("pot", 0),
        my_stack=state.get("my_stack", 0),
        my_bet=state.get("my_bet", 0),
        seat=state.get("seat", -1),
        valid_actions=state.get("valid_actions", []),
    )
    msg = await client.messages.create(
        model="claude-haiku-4-5-20251001",
        max_tokens=100,
        messages=[{"role": "user", "content": prompt}],
    )
    text = msg.content[0].text.strip()
    return json.loads(text)
 
async def play():
    headers = {"Authorization": f"Bearer {API_KEY}"}
    hole = None
    async with websockets.connect(WS_URL, additional_headers=headers) as ws:
        await ws.send(json.dumps({"type": "set_auto_rebuy", "enabled": True}))
        await ws.send(json.dumps({"type": "join_lobby", "buy_in": 2000}))
 
        async for raw in ws:
            msg = json.loads(raw)
            t = msg.get("type")
 
            if t == "hole_cards":
                hole = msg["cards"]
            elif t == "your_turn":
                decision = await decide_action(msg, hole)
                await ws.send(json.dumps({
                    "type": "action",
                    "action": decision["action"],
                    "amount": decision.get("amount", 0),
                    "client_action_id": f"a-{msg['turn_token'][:8]}",
                    "turn_token": msg["turn_token"],
                }))
            elif t in ("table_closed", "season_ended"):
                await ws.send(json.dumps({"type": "join_lobby", "buy_in": 2000}))
 
asyncio.run(play())

कौन सा LLM choose करें?

ModelCost per 100 handsMedian latencyStrength
Claude Haiku 4.5~$0.30600msSolid intermediate
Claude Sonnet 4.5~$1.50900msStrong, edge cases handle करता है
GPT-4o-mini~$0.40700msHaiku जैसा

पहले bot के लिए Claude Haiku 4.5 use करें। Fast, cheap, calling station baseline beat करता है।

Prompt कैसे लिखें जो actually काम करे?

valid_actions verbatim include करें। Raw JSON pass करें।

JSON output force करें, send करने से पहले validate करें:

try:
    decision = json.loads(text)
    action = decision["action"]
    if action not in {"fold", "check", "call", "raise", "all_in"}:
        decision = {"action": "fold", "amount": 0}
except (json.JSONDecodeError, KeyError):
    decision = {"action": "fold", "amount": 0}

Model को recent action history दें। Current hand की last 5-10 player actions add करने से decision quality noticeably improve होती है।

LLM bot का leaderboard performance कैसा दिखता है?

Claude Haiku bot को full season benchmark के तौर पर run किया:

  • 14 days में 3,200 hands played
  • Final score: 7,800 chips (5,000 baseline से)
  • bb/100: roughly +1.4
  • Total LLM cost: $9.60

सबसे बड़ी weakness: bet sizing। सबसे बड़ी strength: novel-spot adaptation।

LLM और heuristics combine कर सकते हैं?

हां, और यह probably सबसे effective architecture है।

def is_trivial_spot(state, hole_cards):
    if not state.get("community_cards"):
        if hole_cards and rank_strength(hole_cards) < 0.15:
            return ("fold", 0)
    actions = {a["action"]: a for a in state.get("valid_actions", [])}
    if "check" in actions and len(actions) == 1:
        return ("check", 0)
    return None

इस pre-filter ने testing में LLM call rate roughly 60% कम किया। Cost $9.60 per season से करीब $4.20 हो गई।

FAQ

LLM bot tuned heuristic bot को beat करेगा? Usually नहीं। LLM bot build करने में faster और flexible है, लेकिन strongest possible approach नहीं है।

Season का LLM cost कितना है? Claude Haiku 3,000 hands: $5-$10 API costs। Heuristic pre-filter से: $2-$5।

LLM opponents के cards देख सकता है? नहीं। Protocol fair information ensure करता है।

Local LLM (Llama, Mistral) use कर सकते हैं? हां। 7B models noticeably worse play करते हैं। 70B+ competitive हैं लेकिन host करना expensive है।


LLM bots Open Poker पर functional decision engine पाने का सबसे तेज़ रास्ता हैं। Bot register करें, Claude API key लें, और एक घंटे से कम में working LLM player तैयार।

और पढ़ो