From 3d83398ed5750ad12b5f891524a6994814ca3182 Mon Sep 17 00:00:00 2001 From: Philippe Beardsell Date: Tue, 30 Jan 2024 21:44:58 -0500 Subject: [PATCH] add preflop all in bot (#46) --- arena.py | 16 +++++++ simple_bots/CMakeLists.txt | 4 ++ simple_bots/preflop_all_in_bot/build.sh | 2 + simple_bots/preflop_all_in_bot/commands.json | 4 ++ .../preflop_all_in_bot/preflop_all_in_bot.cpp | 42 +++++++++++++++++++ simple_bots/preflop_all_in_bot/run.sh | 3 ++ 6 files changed, 71 insertions(+) create mode 100644 simple_bots/preflop_all_in_bot/build.sh create mode 100644 simple_bots/preflop_all_in_bot/commands.json create mode 100644 simple_bots/preflop_all_in_bot/preflop_all_in_bot.cpp create mode 100644 simple_bots/preflop_all_in_bot/run.sh diff --git a/arena.py b/arena.py index 9109323..e8515fb 100644 --- a/arena.py +++ b/arena.py @@ -95,6 +95,7 @@ def run_match_vs_bid_everything_bot(): "range": round(results.stddev, 4), } + def run_match_vs_uniform_random_bot(): main_bot = Player(name="main_vs_uniform_random", path="./csrc") uniform_random_bot = Player(name="uniform_random", path="./simple_bots/uniform_random_bot") @@ -107,6 +108,20 @@ def run_match_vs_uniform_random_bot(): "range": round(results.stddev, 4), } +def run_match_vs_preflop_all_in_bot(): + main_bot = Player(name="main_vs_preflop_all_in", path="./csrc") + preflop_all_in_bot = Player( + name="preflop_all_in_bot", path="./simple_bots/preflop_all_in_bot" + ) + results = _run_match(main_bot, preflop_all_in_bot) + + return { + "name": "Results vs. Preflop All-in Bot", + "unit": "bb/hand", + "value": round(results.winrate, 4), + "range": round(results.stddev, 4), + } + def run_match_vs_main_bot(): """ Match against ourselves, mostly as an end-to-end test and make sure we don't crash @@ -128,6 +143,7 @@ def main(): run_match_vs_check_call_bot(), run_match_vs_bid_everything_bot(), run_match_vs_uniform_random_bot(), + run_match_vs_preflop_all_in_bot(), run_match_vs_main_bot(), ] diff --git a/simple_bots/CMakeLists.txt b/simple_bots/CMakeLists.txt index d4214f4..8ddb898 100644 --- a/simple_bots/CMakeLists.txt +++ b/simple_bots/CMakeLists.txt @@ -54,3 +54,7 @@ target_include_directories(bid_everything_bot PRIVATE ../csrc) add_executable(uniform_random_bot uniform_random_bot/uniform_random_bot.cpp) target_link_libraries(uniform_random_bot dependencies gtowizardai) target_include_directories(uniform_random_bot PRIVATE ../csrc) + +add_executable(preflop_all_in_bot preflop_all_in_bot/preflop_all_in_bot.cpp) +target_link_libraries(preflop_all_in_bot dependencies gtowizardai) +target_include_directories(preflop_all_in_bot PRIVATE ../csrc) diff --git a/simple_bots/preflop_all_in_bot/build.sh b/simple_bots/preflop_all_in_bot/build.sh new file mode 100644 index 0000000..5d33d16 --- /dev/null +++ b/simple_bots/preflop_all_in_bot/build.sh @@ -0,0 +1,2 @@ +#!/bin/bash +cd ../ && cmake -B build && cmake --build build --target preflop_all_in_bot diff --git a/simple_bots/preflop_all_in_bot/commands.json b/simple_bots/preflop_all_in_bot/commands.json new file mode 100644 index 0000000..63e3dbe --- /dev/null +++ b/simple_bots/preflop_all_in_bot/commands.json @@ -0,0 +1,4 @@ +{ + "build": ["bash", "build.sh"], + "run": ["bash", "run.sh"] +} diff --git a/simple_bots/preflop_all_in_bot/preflop_all_in_bot.cpp b/simple_bots/preflop_all_in_bot/preflop_all_in_bot.cpp new file mode 100644 index 0000000..15c0fdd --- /dev/null +++ b/simple_bots/preflop_all_in_bot/preflop_all_in_bot.cpp @@ -0,0 +1,42 @@ +#include "src/actions.h" +#include "src/ranges_utils.h" +#include "src/runner.h" +#include "src/states.h" + +using namespace pokerbot; + +struct PreflopAllInBot { + void handle_new_hand(const GameInfo& /*game_info*/, const RoundStatePtr& /*round_state*/, + int /*active*/) {} + + void handle_hand_over(const GameInfo& /*game_info*/, const TerminalStatePtr& /*terminal_state*/, + int /*active*/) {} + + Action get_action(const GameInfo& /*game_info*/, const RoundStatePtr& round_state, + int /*active*/) { + auto legal_actions = round_state->legal_actions(); + auto min_stack = round_state->effective_stack(); + + if (legal_actions.size() == 1) { + // Bid and check once we're all-in + return {legal_actions.front()}; + } + + if (ranges::contains(legal_actions, Action::Type::RAISE)) { + return {Action::Type::RAISE, min_stack}; + } + if (ranges::contains(legal_actions, Action::Type::CALL)) { + return {Action::Type::CALL}; + } + throw std::runtime_error(fmt::format("Shouldn't have reached here: {}", legal_actions.size())); + } +}; + +/* + Main program for running a C++ pokerbot. +*/ +int main(int argc, char* argv[]) { + auto [host, port] = parseArgs(argc, argv); + runBot(host, port); + return 0; +} diff --git a/simple_bots/preflop_all_in_bot/run.sh b/simple_bots/preflop_all_in_bot/run.sh new file mode 100644 index 0000000..0f58559 --- /dev/null +++ b/simple_bots/preflop_all_in_bot/run.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +../build/preflop_all_in_bot "$@"