Skip to content

Commit

Permalink
Fixed update_exploits (#49)
Browse files Browse the repository at this point in the history
* Fixed update_exploits

* removed iostream

* fixed pre commit

* Fixed auction for real this time.

* precommit
  • Loading branch information
GrahamZugPitt authored Jan 31, 2024
1 parent 3d83398 commit 8b266ad
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 20 deletions.
25 changes: 17 additions & 8 deletions csrc/src/auction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<float>(bid) / static_cast<float>(pot);
float bid_to_pot = static_cast<float>(villain_bid) / static_cast<float>(pot);

if (bid_to_pot < v_pot_percentage_min_max[0]) {
v_pot_percentage_min_max[0] = bid_to_pot;
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion csrc/src/auction.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<card_t>& 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_;
Expand Down
35 changes: 24 additions & 11 deletions csrc/src/auction_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
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);
}

0 comments on commit 8b266ad

Please sign in to comment.