chironaut 0.3.5

A poker game library for Texas Hold'em and other poker variants
Documentation
use chironaut::{
    action::Action,
    game::Game,
    rules::GameRules,
    game::GameStage,
};

#[test]
fn test_basic_game_flow() {
    // Create a new game with 3 players
    let rules = GameRules::nlhe(10, 20);
    let mut game = Game::new(rules);
    
    // Add players to specific seats
    game.add_player_to_seat("Player 1".to_string(), 1000, 0).unwrap();
    game.add_player_to_seat("Player 2".to_string(), 1000, 1).unwrap();
    game.add_player_to_seat("Player 3".to_string(), 1000, 2).unwrap();
    
    // Start a hand
    game.start_hand().unwrap();
    
    // Print state information for debugging
    println!("\nInitial game state:");
    println!("Dealer position: {}", game.dealer_position);
    println!("SB position: {}", (game.dealer_position + 1) % 3);
    println!("BB position: {}", (game.dealer_position + 2) % 3);
    println!("UTG position: {}", (game.dealer_position + 3) % 3);
    println!("Current position: {}", game.current_position);
    
    // UTG player (first to act) calls
    println!("\nUTG calls:");
    println!("Player at position {}: {}", game.current_position, 
             game.players[game.current_position].name);
    
    game.handle_action(Action::Bet(20)).unwrap();
    println!("Pot: {}", game.pot);
    
    // SB player (now next to act) raises
    println!("\nSB raises:");
    println!("Player at position {}: {}", game.current_position, 
             game.players[game.current_position].name);
    
    game.handle_action(Action::Bet(40)).unwrap(); // 10 (SB) + 40 = 50
    println!("Pot: {}", game.pot);
    
    // BB player (next to act) calls
    println!("\nBB calls:");
    println!("Player at position {}: {}", game.current_position, 
             game.players[game.current_position].name);
    
    game.handle_action(Action::Bet(30)).unwrap(); // 20 (BB) + 30 = 50
    println!("Pot: {}", game.pot);
    
    // UTG player now facing a raise, calls
    println!("\nUTG calls the raise:");
    println!("Player at position {}: {}", game.current_position, 
             game.players[game.current_position].name);
    
    game.handle_action(Action::Bet(30)).unwrap(); // 20 + 30 = 50
    println!("Pot: {}", game.pot);
    
    // Print the current state
    println!("Game stage: {:?}, is_round_complete: {}", 
             game.stage, game.is_round_complete());
    
    // Manually move to the flop
    println!("\nMoving to flop");
    if game.stage == GameStage::Preflop {
        game.next_street().unwrap();
    }
    
    assert_eq!(game.stage, GameStage::Flop);
    assert_eq!(game.community_cards.len(), 3);
    println!("Community cards: {} {} {}", 
             game.community_cards[0], 
             game.community_cards[1], 
             game.community_cards[2]);
    
    // Print current position info at flop
    println!("Current position at flop: {} ({})", 
             game.current_position, 
             game.players[game.current_position].name);
    
    // First player checks
    game.handle_action(Action::Bet(0)).unwrap();
    
    // Second player bets
    println!("\nSecond player bets:");
    println!("Player at position {}: {}", game.current_position, 
             game.players[game.current_position].name);
    
    game.handle_action(Action::Bet(50)).unwrap();
    println!("Pot: {}", game.pot);
    
    // Third player folds
    println!("\nThird player folds:");
    println!("Player at position {}: {}", game.current_position, 
             game.players[game.current_position].name);
    
    game.handle_action(Action::Fold).unwrap();
    
    // First player calls
    println!("\nFirst player calls:");
    println!("Player at position {}: {}", game.current_position, 
             game.players[game.current_position].name);
    
    game.handle_action(Action::Bet(50)).unwrap();
    println!("Pot: {}", game.pot);
    
    // Print current state
    println!("Game stage: {:?}, is_round_complete: {}", 
             game.stage, game.is_round_complete());
    
    // Manually move to the turn
    println!("\nManually moving to turn");
    if game.stage == GameStage::Flop {
        game.next_street().unwrap();
    }
    
    // Verify the pot size
    println!("\nPot after flop: {}", game.pot);
    
    // Complete the hand to showdown
    println!("\nCompleting hand to showdown");
    
    // Players check through the turn
    for _ in 0..2 { // Only 2 players left
        println!("Player at position {}: {}", game.current_position, 
                game.players[game.current_position].name);
        game.handle_action(Action::Bet(0)).unwrap();
    }
    
    // Manually move to the river
    println!("\nManually moving to river");
    if game.stage == GameStage::Turn {
        game.next_street().unwrap();
    }
    
    // Players check through the river
    for _ in 0..2 { // Only 2 players left
        println!("Player at position {}: {}", game.current_position, 
                game.players[game.current_position].name);
        game.handle_action(Action::Bet(0)).unwrap();
    }
    
    // Manually move to showdown
    println!("\nManually moving to showdown");
    if game.stage == GameStage::River {
        game.stage = GameStage::Showdown;
        game.evaluate_winner();
    }
    
    // Verify final state
    println!("\nFinal state:");
    println!("Stage: {:?}", game.stage);
    println!("Pot: {}", game.pot);
    println!("Community cards: {} {} {} {} {}", 
             game.community_cards[0], 
             game.community_cards[1], 
             game.community_cards[2],
             game.community_cards[3],
             game.community_cards[4]);
    
    // Verify players' states
    for (i, player) in game.players.iter().enumerate() {
        println!("Player {}: {}, Chips: {}, Folded: {}, All-in: {}", 
                 i, player.name, player.chips, player.is_folded, player.is_all_in);
    }
}