Expand description
§chipzen-bot
Build, test, and deploy poker bots for the Chipzen competition platform.
Implement the Bot trait, return Actions from Bot::decide,
call run_bot — the SDK handles the WebSocket connection,
the two-layer protocol handshake, ping/pong, request_id echoing,
action_rejected retries, and reconnect.
use chipzen_bot::{Bot, Action, GameState, run_bot, RunBotOptions};
struct MyBot;
#[async_trait::async_trait]
impl Bot for MyBot {
fn decide(&mut self, state: &GameState) -> Action {
if state.valid_actions.iter().any(|a| a == "check") {
Action::Check
} else {
Action::Fold
}
}
}
let url = std::env::var("CHIPZEN_WS_URL").unwrap();
let _match_end = run_bot(&url, MyBot, RunBotOptions::default()).await?;To run a bot on the external-API remote-play path (your machine,
the platform matches and dispatches you), use
run_external_bot with a cz_extbot_ token — see its docs.
See the docs/protocol/ docs in the chipzen-sdk repo for the
full two-layer protocol specification, and the
IP-PROTECTION.md
for what the starter Dockerfile does to your release binary.
Structs§
- Action
History Entry - One entry from
state.action_history. Synthetic blind/ante entries (post_small_blind,post_big_blind,post_ante) appear here too — the server generates them; bots do not submit them. - Card
- A standard playing card.
- Chipzen
Config - Parsed contents of a
chipzen.tomlfile. - Conformance
Check - One conformance scenario’s verdict.
- Connection
Config - Fully-resolved connection parameters ready for
crate::run_external_bot. - Game
State - Built from the server’s
turn_requestmessage. The parser inparse_game_stateconverts the wire-format snake_case to the owned-string fields below. - Match
Result - One per-match result collected during a session.
- Retry
Policy - Backoff knobs applied to reconnect attempts.
- RunBot
Options - Optional knobs for
run_bot. Defaults match the platform’s expectations. - RunConformance
Options - Optional knobs for
run_conformance_checks. - RunExternal
Args - Parsed
run-externalflags, mirroring the Python CLI (--env/--token/--bot-id/--max-matches/--no-safe-mode). - RunExternal
Options - Options for
run_external_bot. Mirrors the Python kwargs. - Session
Context - Opaque per-session bag the session loop threads through. Public so the conformance harness can construct one.
Enums§
- Action
- The action a bot returns from
crate::Bot::decide. - Action
Kind - The five action kinds a bot can take. Matches the wire
actionstrings byte-for-byte. - Conformance
Severity - Severity of a single conformance verdict. Same shape as
chipzen_sdk::Severity; the CLI renders them uniformly. - EnvName
- One of the three recognized Chipzen environments.
- Error
- Top-level error type for SDK operations. Variants describe the failure surface in terms users care about (connect failed, server dropped us mid-handshake, peer sent something unparseable) rather than transport internals.
Constants§
- BOT_
TOKEN_ SUBPROTOCOL - Sentinel subprotocol that marks the
cz_extbot_token in theSec-WebSocket-Protocolheader (CZ issue 2932 moved the token off the query string, where it leaked into proxy access logs). Must match the value the platform’s api gateway expects. - CHIPZEN_
ENV_ VAR - Name of the environment variable consulted when
envis not explicitly passed. - CONFIG_
FILENAME - The config-file name searched for on the discovery path.
- ENV_
NAMES - Recognized environment names. Kept as a constant so error messages can list the valid values and the env-var path can validate at runtime.
- SCENARIO_
NAMES - The set of conformance scenario names registered with
run_conformance_checks. Listed in the order they’re executed. Useful for downstream tooling that wants to enumerate scenarios without parsing CLI output. - SECTION_
NAME - The TOML table the SDK reads its settings from.
- SUPPORTED_
PROTOCOL_ VERSIONS - Protocol versions this client claims to support in the handshake.
Traits§
- Bot
- User-implementable poker bot.
- Message
Reader - Pull-based async iterator over inbound messages. Real impl wraps
tokio_tungstenite::WebSocketStream; the conformance harness provides a scripted impl. - Message
Writer - Push-based async sender for outbound messages.
Functions§
- bot_
token_ subprotocols - Build the
Sec-WebSocket-Protocoloffer that carries the bot token:[sentinel, token]. The sentinel marks “the next value is my bot token”; the api gateway extracts the token from this header (so it never appears in any access log / URL) and echoes the sentinel back on accept. - connect_
to_ chipzen - Resolve a
ConnectionConfigfor the external-API lobby. - default_
retry_ policy - The default
RetryPolicyused when arun_*entry point is called without an explicit policy: 5 attempts, 500ms initial backoff doubling to a 30s cap. - default_
user_ agent - Default
User-Agentheader sent on the WebSocket handshake. A non-default UA also clears the platform’s Cloudflare bot-fight rule (chipzen-ai/chipzen-sdk#46). - discover_
config_ path - Return the first existing
chipzen.tomlon the search path, orNone. - load_
chipzen_ config - Discover and parse a
chipzen.tomlfrom the search path. - parse_
card - Parse a card from its 2-character wire form (e.g.
"Ah"). Mirrors the Python and JavaScript helpers of the same name; equivalent tos.parse::<Card>(). - parse_
game_ state - Parse a
turn_requestenvelope into aGameState. - resolve_
gateway_ url - Resolve the
matched.gateway_ws_urlpath against the lobby origin. - resolve_
token - Return the token to use, honoring precedence:
- resolve_
url - Return the URL override to use, honoring precedence:
- run_bot
- Connect a bot to the Chipzen server and play until the match ends.
- run_
conformance_ checks - Drive
botthrough every conformance scenario and return per-check verdicts. The bot instance is consumed (passed by value) — matches the production usage shape whererun_botalso takes ownership. - run_
external_ bot - Run a bot on the Chipzen external-API remote-play path.
- run_
external_ cli - The Rust equivalent of the
chipzen run-externalCLI: resolve config + env URL + token fromargs(and a discoveredchipzen.toml), then runfactory’s bot viarun_external_bot.