Skip to content

Commit

Permalink
fix bindi's complaints about gottatry bot (#198)
Browse files Browse the repository at this point in the history
Co-authored-by: Tim Wilson <[email protected]>
  • Loading branch information
tjwilson90 and twilson-palantir authored Nov 19, 2021
1 parent 950fe6d commit 3ab4c19
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions bot/src/gottatry.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{Algorithm, DuckBot};
use rand::Rng;
use turbo_hearts_api::{BotState, Card, Cards, GameEvent, GameState, Rank, Suit};
use turbo_hearts_api::{BotState, Card, Cards, GameEvent, GamePhase, GameState, Rank, Suit};

pub struct GottaTryBot;

Expand Down Expand Up @@ -91,6 +91,10 @@ fn follow(ours: Cards, theirs: Cards, bot_state: &BotState, game_state: &GameSta
let winning = game_state.current_trick.winning_seat(bot_state.seat) == bot_state.seat;
let winning_card = (trick & suit.cards()).max();

if !winning && trick.contains_any(Cards::POINTS) && ours.max() < winning_card {
return ours.max().into();
}

if trick.len() == 4 && can_drain_without_nine(suit, ours, theirs) {
return ours.max().into();
}
Expand All @@ -113,8 +117,16 @@ fn slough(ours: Cards, theirs: Cards, bot_state: &BotState, game_state: &GameSta
let winning = game_state.current_trick.winning_seat(bot_state.seat) == bot_state.seat;
let winning_card = (trick & suit.cards()).max();

if !winning && trick.contains_any(Cards::POINTS) {
return DuckBot.play(bot_state, game_state).into();
}

if Cards::POINTS.contains_all(ours) {
return ours.min().into();
return if winning {
ours.min().into()
} else {
ours.max().into()
};
}

let them = theirs & suit.cards();
Expand All @@ -141,7 +153,13 @@ impl Algorithm for GottaTryBot {
}

fn charge(&mut self, bot_state: &BotState, game_state: &GameState) -> Cards {
(bot_state.post_pass_hand & Cards::CHARGEABLE) - game_state.charges.all_charges()
if game_state.phase == GamePhase::ChargeKeeper1
&& game_state.charges.all_charges().is_empty()
{
Cards::NONE
} else {
(bot_state.post_pass_hand & Cards::CHARGEABLE) - game_state.charges.all_charges()
}
}

fn play(&mut self, bot_state: &BotState, game_state: &GameState) -> Card {
Expand Down

0 comments on commit 3ab4c19

Please sign in to comment.