Skip to content

Commit

Permalink
add preflop all in bot (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
philqc authored Jan 31, 2024
1 parent ad17729 commit 3d83398
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 0 deletions.
16 changes: 16 additions & 0 deletions arena.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
Expand All @@ -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(),
]

Expand Down
4 changes: 4 additions & 0 deletions simple_bots/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 2 additions & 0 deletions simple_bots/preflop_all_in_bot/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
cd ../ && cmake -B build && cmake --build build --target preflop_all_in_bot
4 changes: 4 additions & 0 deletions simple_bots/preflop_all_in_bot/commands.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"build": ["bash", "build.sh"],
"run": ["bash", "run.sh"]
}
42 changes: 42 additions & 0 deletions simple_bots/preflop_all_in_bot/preflop_all_in_bot.cpp
Original file line number Diff line number Diff line change
@@ -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<PreflopAllInBot>(host, port);
return 0;
}
3 changes: 3 additions & 0 deletions simple_bots/preflop_all_in_bot/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

../build/preflop_all_in_bot "$@"

1 comment on commit 3d83398

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Arena Benchmark'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: 3d83398 Previous: 12b534a Ratio
Results vs. Ourselves -1.5895 bb/hand (3.5993) -5.388 bb/hand (3.564) 3.39

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.