use chironaut::{
action::Action,
game::Game,
rules::{GameRules, GameVariant},
card::Card,
game::GameStage,
};
#[test]
fn test_heads_up_blinds() {
let rules = GameRules::nlhe(10, 20);
let mut game = Game::new(rules);
game.add_player("Small Blind".to_string(), 1000).unwrap();
game.add_player("Big Blind".to_string(), 1000).unwrap();
game.start_hand().unwrap();
let dealer_pos = game.dealer_position;
assert_eq!(game.players[dealer_pos].bet_amount, 10);
let bb_pos = (dealer_pos + 1) % 2;
assert_eq!(game.players[bb_pos].bet_amount, 20);
assert_eq!(game.current_position, dealer_pos);
game.handle_action(Action::Bet(10)).unwrap(); game.handle_action(Action::Bet(0)).unwrap();
println!("Moving to flop - stage before: {:?}", game.stage);
if game.stage == GameStage::Preflop {
game.next_street().unwrap();
}
println!("Stage after moving to flop: {:?}", game.stage);
game.handle_action(Action::Bet(0)).unwrap();
game.handle_action(Action::Bet(0)).unwrap();
println!("Moving to turn - stage before: {:?}", game.stage);
if game.stage == GameStage::Flop {
game.next_street().unwrap();
}
println!("Stage after moving to turn: {:?}", game.stage);
game.handle_action(Action::Bet(0)).unwrap();
game.handle_action(Action::Bet(0)).unwrap();
println!("Moving to river - stage before: {:?}", game.stage);
if game.stage == GameStage::Turn {
game.next_street().unwrap();
}
println!("Stage after moving to river: {:?}", game.stage);
game.handle_action(Action::Bet(0)).unwrap();
game.handle_action(Action::Bet(0)).unwrap();
if game.stage == GameStage::River {
println!("Moving to showdown manually");
game.stage = GameStage::Showdown;
}
assert_eq!(game.stage, GameStage::Showdown);
if game.pot > 0 {
game.evaluate_winner();
}
let total_chips = game.players.iter().map(|p| p.chips).sum::<u32>();
assert_eq!(total_chips, 2000);
}
#[test]
fn test_heads_up_preflop_betting() {
let rules = GameRules::nlhe(10, 20);
let mut game = Game::new(rules);
game.add_player("Button".to_string(), 1000).unwrap();
game.add_player("Big Blind".to_string(), 1000).unwrap();
game.start_hand().unwrap();
game.handle_action(Action::Bet(10)).unwrap();
game.handle_action(Action::Bet(0)).unwrap();
println!("After preflop betting - stage: {:?}, is_round_complete: {}",
game.stage, game.is_round_complete());
assert_eq!(game.pot, 40); }
#[test]
fn test_heads_up_postflop_positions() {
let rules = GameRules::nlhe(10, 20);
let mut game = Game::new(rules);
game.add_player("Button".to_string(), 1000).unwrap();
game.add_player("Big Blind".to_string(), 1000).unwrap();
game.start_hand().unwrap();
game.handle_action(Action::Bet(10)).unwrap(); game.handle_action(Action::Bet(0)).unwrap();
game.next_street().unwrap();
let bb_pos = (game.dealer_position + 1) % 2;
assert_eq!(game.current_position, bb_pos, "BB should act first post-flop in heads-up");
game.handle_action(Action::Bet(40)).unwrap();
let dealer_pos = game.dealer_position;
game.handle_action(Action::Bet(40)).unwrap();
game.next_street().unwrap();
assert_eq!(game.current_position, bb_pos, "BB should act first on turn in heads-up");
}
#[test]
fn test_heads_up_3bet_4bet() {
let rules = GameRules::nlhe(10, 20);
let mut game = Game::new(rules);
game.add_player("Button".to_string(), 2000).unwrap();
game.add_player("Big Blind".to_string(), 2000).unwrap();
game.start_hand().unwrap();
game.handle_action(Action::Bet(60)).unwrap();
game.handle_action(Action::Bet(180)).unwrap();
game.handle_action(Action::Bet(390)).unwrap();
game.handle_action(Action::Bet(260)).unwrap();
println!("After 4bet action - stage: {:?}, is_round_complete: {}",
game.stage, game.is_round_complete());
assert_eq!(game.pot, 920);
assert_eq!(game.players[0].bet_amount, game.players[1].bet_amount);
}
#[test]
fn test_heads_up_allin_confrontation() {
let rules = GameRules::nlhe(10, 20);
let mut game = Game::new(rules);
game.add_player("Button".to_string(), 200).unwrap();
game.add_player("Big Blind".to_string(), 150).unwrap();
game.start_hand().unwrap();
game.players[0].chips = 0;
game.players[0].is_all_in = true;
game.players[0].bet_amount = 200;
game.players[1].chips = 0;
game.players[1].is_all_in = true;
game.players[1].bet_amount = 150;
game.pot = 350;
game.stage = GameStage::Showdown;
while game.community_cards.len() < 5 {
if let Some(card) = game.deck.deal() {
game.community_cards.push(card);
}
}
game.evaluate_winner();
assert_eq!(game.pot, 0);
assert_eq!(game.players[0].chips + game.players[1].chips, 350);
}
#[test]
fn test_button_movement_two_players() {
let rules = GameRules::nlhe(10, 20);
let mut game = Game::new(rules);
game.add_player("Player 1".to_string(), 1000).unwrap();
game.add_player("Player 2".to_string(), 1000).unwrap();
game.start_hand().unwrap();
let first_dealer = game.dealer_position;
game.handle_action(Action::Fold).unwrap();
game.start_hand().unwrap();
let second_dealer = game.dealer_position;
assert_ne!(first_dealer, second_dealer);
game.handle_action(Action::Fold).unwrap();
game.start_hand().unwrap();
assert_eq!(game.dealer_position, first_dealer);
}