-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add counterfactual regret minimization node and state
Summary: - Add CFR game state tree that uses a vec as an allocation arena. Test Plan: - Added a test.
- Loading branch information
1 parent
60063d4
commit b130fb5
Showing
7 changed files
with
347 additions
and
17 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
mod node; | ||
mod state; | ||
|
||
pub use node::{Node, NodeData, PlayerData, TerminalData}; | ||
pub use state::CFRState; | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use std::vec; | ||
|
||
use crate::arena::game_state::{Round, RoundData}; | ||
|
||
use crate::arena::GameState; | ||
use crate::core::{Hand, PlayerBitSet}; | ||
|
||
#[test] | ||
fn test_should_fold_all_in() { | ||
let num_agents = 2; | ||
let hand_zero = Hand::new_from_str("AsKsKcAcTh4d8d").unwrap(); | ||
let hand_one = Hand::new_from_str("JdTcKcAcTh4d8d").unwrap(); | ||
|
||
// The board is the last 5 cards of the hand | ||
let board = hand_zero.iter().skip(2).copied().collect(); | ||
// Zero is all in. | ||
let stacks: Vec<f32> = vec![0.0, 900.0]; | ||
let player_bet = vec![1000.0, 100.0]; | ||
// Create a game state where player 0 is all in and player 1 should make a | ||
// decision to call or fold | ||
let round_data = RoundData::new(num_agents, 100.0, PlayerBitSet::new(num_agents), 1); | ||
let _game_state = GameState::new( | ||
Round::River, | ||
round_data, | ||
board, | ||
vec![hand_zero, hand_one], | ||
stacks, | ||
player_bet, | ||
5.0, | ||
0.0, | ||
0.0, | ||
0, | ||
); | ||
} | ||
} |
Oops, something went wrong.