From 9c4a31022c04488734596a8b193497c0e07ea142 Mon Sep 17 00:00:00 2001 From: bkushigian Date: Wed, 21 Aug 2024 11:30:14 -0700 Subject: [PATCH] Tmp commit --- examples/file_io_debug.rs | 18 ++++++++++-------- src/file.rs | 2 +- src/game/base.rs | 31 +++++++++++++++++++++++++------ src/game/interpreter.rs | 2 +- 4 files changed, 37 insertions(+), 16 deletions(-) diff --git a/examples/file_io_debug.rs b/examples/file_io_debug.rs index d5a625f..598af23 100644 --- a/examples/file_io_debug.rs +++ b/examples/file_io_debug.rs @@ -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!( @@ -127,6 +127,8 @@ fn print_strats_at_current_node( println!("{}", action_frequencies.join(" ")); } } + + println!(); } fn main() { @@ -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()); @@ -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]); diff --git a/src/file.rs b/src/file.rs index b4e64ef..6cd2a1d 100644 --- a/src/file.rs +++ b/src/file.rs @@ -166,7 +166,7 @@ pub fn load_data_from_std_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")?; diff --git a/src/game/base.rs b/src/game/base.rs index 53dcc9a..26f19e2 100644 --- a/src/game/base.rs +++ b/src/game/base.rs @@ -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}; @@ -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, 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 @@ -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); diff --git a/src/game/interpreter.rs b/src/game/interpreter.rs index 34bb2c7..f61bb82 100644 --- a/src/game/interpreter.rs +++ b/src/game/interpreter.rs @@ -1005,7 +1005,7 @@ impl PostFlopGame { /// Returns the reference to the current node. #[inline] - fn node(&self) -> MutexGuardLike { + pub fn node(&self) -> MutexGuardLike { self.node_arena[self.node_history.last().cloned().unwrap_or(0)].lock() }