From 8b266ad0697a162b53d439b46b329d10f287fb8d Mon Sep 17 00:00:00 2001 From: GrahamZugPitt <46653792+GrahamZugPitt@users.noreply.github.com> Date: Wed, 31 Jan 2024 16:59:59 -0500 Subject: [PATCH] Fixed update_exploits (#49) * Fixed update_exploits * removed iostream * fixed pre commit * Fixed auction for real this time. * precommit --- csrc/src/auction.cpp | 25 +++++++++++++++++-------- csrc/src/auction.h | 2 +- csrc/src/auction_test.cpp | 35 ++++++++++++++++++++++++----------- 3 files changed, 42 insertions(+), 20 deletions(-) diff --git a/csrc/src/auction.cpp b/csrc/src/auction.cpp index d917aeb..26f4d50 100644 --- a/csrc/src/auction.cpp +++ b/csrc/src/auction.cpp @@ -56,18 +56,27 @@ int Auctioneer::get_bid(const Range& hero_range, const Range& villain_range, con return default_bid; } -void Auctioneer::update_exploits(const int bid, const int pot) { +void Auctioneer::update_exploits(const int hero_bid, const int villain_bid, + const int bid_plus_pot) { + int pot; + if (hero_bid == villain_bid) { + pot = bid_plus_pot - hero_bid - villain_bid; + } else if (hero_bid > villain_bid) { + pot = bid_plus_pot - villain_bid; + } else { + pot = bid_plus_pot - hero_bid; + } int stack = STARTING_STACK - (pot / 2); - if ((stack - bid) > REASONABLE_DIST_FROM_MAX) { + if ((stack - villain_bid) > REASONABLE_DIST_FROM_MAX) { v_is_excessive_bidder = false; } - if (bid < v_abs_bid_min_max[0]) { - v_abs_bid_min_max[0] = bid; + if (villain_bid < v_abs_bid_min_max[0]) { + v_abs_bid_min_max[0] = villain_bid; } - if (bid > v_abs_bid_min_max[1]) { - v_abs_bid_min_max[1] = bid; + if (villain_bid > v_abs_bid_min_max[1]) { + v_abs_bid_min_max[1] = villain_bid; } - float bid_to_pot = static_cast(bid) / static_cast(pot); + float bid_to_pot = static_cast(villain_bid) / static_cast(pot); if (bid_to_pot < v_pot_percentage_min_max[0]) { v_pot_percentage_min_max[0] = bid_to_pot; @@ -85,7 +94,7 @@ void Auctioneer::receive_bid(Range& hero_range, Range& villain_range, const int return; // We've already been here on the same hand } - update_exploits(villain_bid, pot); + update_exploits(hero_bid, villain_bid, pot); // Update ranges based on who won the bid if (hero_bid == villain_bid) { diff --git a/csrc/src/auction.h b/csrc/src/auction.h index 9663642..2fb1632 100644 --- a/csrc/src/auction.h +++ b/csrc/src/auction.h @@ -28,7 +28,7 @@ class Auctioneer { void receive_bid(Range& hero_range, Range& villain_range, int hero_bid, int villain_bid, const Game& game, const std::vector& board_cards, int pot); - void update_exploits(int bid, int pot); + void update_exploits(const int hero_bid, const int villain_bid, const int bid_plus_pot); private: HandEquitiesThirdCard hand_equities_third_card_; diff --git a/csrc/src/auction_test.cpp b/csrc/src/auction_test.cpp index b1c1340..d0f9ad0 100644 --- a/csrc/src/auction_test.cpp +++ b/csrc/src/auction_test.cpp @@ -47,18 +47,31 @@ TEST_F(AuctionTest, TestReceiveBid) { TEST_F(AuctionTest, TestUpdateExploits) { Auctioneer auctioneer; - int bid = 390; - auctioneer.update_exploits(bid, 10); + int villain_bid = 391; + int hero_bid = 390; + int pot = 10; + auctioneer.update_exploits(hero_bid, villain_bid, pot + hero_bid); ASSERT_TRUE(auctioneer.v_is_excessive_bidder); - ASSERT_EQ(auctioneer.v_abs_bid_min_max[0], 390); - ASSERT_EQ(auctioneer.v_abs_bid_min_max[1], 390); - ASSERT_NEAR(auctioneer.v_pot_percentage_min_max[0], 39.0, TOLERANCE); - ASSERT_NEAR(auctioneer.v_pot_percentage_min_max[1], 39.0, TOLERANCE); - bid = 10; - auctioneer.update_exploits(bid, 10); + ASSERT_EQ(auctioneer.v_abs_bid_min_max[0], 391); + ASSERT_EQ(auctioneer.v_abs_bid_min_max[1], 391); + ASSERT_NEAR(auctioneer.v_pot_percentage_min_max[0], 39.1, TOLERANCE); + ASSERT_NEAR(auctioneer.v_pot_percentage_min_max[1], 39.1, TOLERANCE); + villain_bid = 10; + hero_bid = 11; + pot = 10; + auctioneer.update_exploits(hero_bid, villain_bid, pot + villain_bid); ASSERT_FALSE(auctioneer.v_is_excessive_bidder); ASSERT_EQ(auctioneer.v_abs_bid_min_max[0], 10); - ASSERT_EQ(auctioneer.v_abs_bid_min_max[1], 390); + ASSERT_EQ(auctioneer.v_abs_bid_min_max[1], 391); ASSERT_NEAR(auctioneer.v_pot_percentage_min_max[0], 1.0, TOLERANCE); - ASSERT_NEAR(auctioneer.v_pot_percentage_min_max[1], 39.0, TOLERANCE); -} \ No newline at end of file + ASSERT_NEAR(auctioneer.v_pot_percentage_min_max[1], 39.1, TOLERANCE); + villain_bid = 5; + hero_bid = 5; + pot = 10; + auctioneer.update_exploits(hero_bid, villain_bid, pot + hero_bid + villain_bid); + ASSERT_FALSE(auctioneer.v_is_excessive_bidder); + ASSERT_EQ(auctioneer.v_abs_bid_min_max[0], 5); + ASSERT_EQ(auctioneer.v_abs_bid_min_max[1], 391); + ASSERT_NEAR(auctioneer.v_pot_percentage_min_max[0], .5, TOLERANCE); + ASSERT_NEAR(auctioneer.v_pot_percentage_min_max[1], 39.1, TOLERANCE); +}