Skip to content

Commit

Permalink
Tmp commit
Browse files Browse the repository at this point in the history
  • Loading branch information
bkushigian committed Aug 21, 2024
1 parent a5dc463 commit 9c4a310
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 16 deletions.
18 changes: 10 additions & 8 deletions examples/file_io_debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ fn print_strats_at_current_node(
.zip(weights2.iter().zip(strat2))
{
let hole_cards = hole_to_string(*cards).unwrap();
print!("\x1B[34;1m{hole_cards}\x1B[0m@({:.2} v {:.2}) ", w1, w2);
print!(" \x1B[34;1m{hole_cards}\x1B[0m@({:.2} v {:.2}) ", w1, w2);
let mut action_frequencies = vec![];
for (a, (freq1, freq2)) in actions.iter().zip(s1.iter().zip(s2)) {
action_frequencies.push(format!(
Expand All @@ -127,6 +127,8 @@ fn print_strats_at_current_node(
println!("{}", action_frequencies.join(" "));
}
}

println!();
}

fn main() {
Expand Down Expand Up @@ -158,10 +160,10 @@ fn main() {

// save (turn)
game1.set_target_storage_mode(BoardState::Turn).unwrap();
save_data_to_file(&game1, "", "tmpfile.flop", None).unwrap();
save_data_to_file(&game1, "", "tmpfile.pfs", None).unwrap();

// load (turn)
let mut game2: PostFlopGame = load_data_from_file("tmpfile.flop", None).unwrap().0;
let mut game2: PostFlopGame = load_data_from_file("tmpfile.pfs", None).unwrap().0;
// compare_strategies(&mut game, &mut game2, BoardState::Turn);
assert!(game2.rebuild_and_resolve_forgotten_streets().is_ok());

Expand All @@ -174,31 +176,31 @@ fn main() {
actions_so_far.push(game1.available_actions()[0]);
game1.play(0);
game2.play(0);
print_strats_at_current_node(&mut game1, &mut game2, &actions_so_far);
// print_strats_at_current_node(&mut game1, &mut game2, &actions_so_far);

// IP: Check
actions_so_far.push(game1.available_actions()[0]);
game1.play(0);
game2.play(0);
print_strats_at_current_node(&mut game1, &mut game2, &actions_so_far);
// print_strats_at_current_node(&mut game1, &mut game2, &actions_so_far);

// Chance: 2c
actions_so_far.push(game1.available_actions()[0]);
game1.play(0);
game2.play(0);
print_strats_at_current_node(&mut game1, &mut game2, &actions_so_far);
// print_strats_at_current_node(&mut game1, &mut game2, &actions_so_far);

// OOP: CHECK
actions_so_far.push(game1.available_actions()[0]);
game1.play(0);
game2.play(0);
print_strats_at_current_node(&mut game1, &mut game2, &actions_so_far);
// print_strats_at_current_node(&mut game1, &mut game2, &actions_so_far);

// IP: CHECK
actions_so_far.push(game1.available_actions()[0]);
game1.play(0);
game2.play(0);
print_strats_at_current_node(&mut game1, &mut game2, &actions_so_far);
// print_strats_at_current_node(&mut game1, &mut game2, &actions_so_far);

// CHANCE: 0
actions_so_far.push(game1.available_actions()[1]);
Expand Down
2 changes: 1 addition & 1 deletion src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ pub fn load_data_from_std_read<T: FileData, R: Read>(
) -> Result<(T, String), String> {
let magic: u32 = decode_from_std_read(reader, "Failed to read magic number")?;
if magic != MAGIC {
return Err("Magic number is invalid".to_string());
return Err("Unrecognized file format".to_string());
}

let version: u8 = decode_from_std_read(reader, "Failed to read version number")?;
Expand Down
31 changes: 25 additions & 6 deletions src/game/base.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::*;
use crate::bunching::*;
use crate::interface::*;
use crate::solve_with_node_as_root;
use crate::utility::*;
use std::mem::{self, MaybeUninit};

Expand Down Expand Up @@ -880,6 +881,8 @@ impl PostFlopGame {
/// To regain this information we need to resolve each of these subtrees
/// individually. This function collects the index of each such root.
pub fn collect_unsolved_roots_after_reload(&mut self) -> Result<Vec<usize>, String> {
println!("storage_mode: {:?}", self.storage_mode);
println!("target_storage_mode: {:?}", self.target_storage_mode);
match self.storage_mode {
BoardState::Flop => {
let turn_root_nodes = self
Expand Down Expand Up @@ -914,16 +917,32 @@ impl PostFlopGame {

pub fn resolve_reloaded_nodes(
&mut self,
_max_num_iterations: u32,
_target_exploitability: f32,
_print_progress: bool,
max_num_iterations: u32,
target_exploitability: f32,
print_progress: bool,
) -> Result<(), String> {
let nodes_to_solve = self.collect_unsolved_roots_after_reload()?;
self.state = State::MemoryAllocated;
println!("Found {} nodes to solve", nodes_to_solve.len());
for node_idx in nodes_to_solve {
let _node = self.node_arena.get(node_idx).ok_or("Invalid node index")?;
// TODO: Get and Apply History
// TODO: Solve with node as root
let node = self.node_arena.get(node_idx).ok_or("Invalid node index")?;
let history = match node.lock().compute_history_recursive(self) {
Some(history) => history,
None => Err("Couldn't parse history from node")?,
};

self.apply_history(&history);
// NOTE:
// I _think_ this works. We don't actually modify the node, only
// data that is point to by the node.
let n = MutexLike::new(self.node().clone());
solve_with_node_as_root(
self,
n.lock(),
max_num_iterations,
target_exploitability,
print_progress,
);
}
finalize(self);

Expand Down
2 changes: 1 addition & 1 deletion src/game/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1005,7 +1005,7 @@ impl PostFlopGame {

/// Returns the reference to the current node.
#[inline]
fn node(&self) -> MutexGuardLike<PostFlopNode> {
pub fn node(&self) -> MutexGuardLike<PostFlopNode> {
self.node_arena[self.node_history.last().cloned().unwrap_or(0)].lock()
}

Expand Down

0 comments on commit 9c4a310

Please sign in to comment.