Skip to content

Commit

Permalink
tmp commit for debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
bkushigian committed Aug 24, 2024
1 parent b5c3807 commit 963ed40
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 55 deletions.
57 changes: 5 additions & 52 deletions src/game/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -816,56 +816,9 @@ impl PostFlopGame {

/* REBUILDING AND RESOLVING TREE */

/// Like `init_root`, but applied to a partial save loaded from disk. This
/// reallocates missing `PostFlopNode`s to `node_arena` and reruns
/// `build_tree_recursive`. Rerunning `build_tree_recursive` will not alter
/// nodes loaded from disk.
pub fn reinit_root(&mut self) -> Result<(), String> {
let nodes_per_street = self.count_nodes_per_street();
let total_num_nodes = nodes_per_street[0] + nodes_per_street[1] + nodes_per_street[2];

if total_num_nodes > u32::MAX as u64
|| mem::size_of::<PostFlopNode>() as u64 * total_num_nodes > isize::MAX as u64
{
return Err("Too many nodes".to_string());
}

self.num_nodes_per_street = nodes_per_street;

self.node_arena = (0..total_num_nodes)
.map(|_| MutexLike::new(PostFlopNode::default()))
.collect::<Vec<_>>();
// self.clear_storage();

let mut info = BuildTreeInfo {
turn_index: nodes_per_street[0] as usize,
river_index: (nodes_per_street[0] + nodes_per_street[1]) as usize,
..Default::default()
};

match self.tree_config.initial_state {
BoardState::Flop => info.flop_index += 1,
BoardState::Turn => info.turn_index += 1,
BoardState::River => info.river_index += 1,
}

let mut root = self.node_arena[0].lock();
root.turn = self.card_config.turn;
root.river = self.card_config.river;

self.build_tree_recursive(0, &self.action_root.lock(), &mut info);

self.num_storage = info.num_storage;
self.num_storage_ip = info.num_storage_ip;
self.num_storage_chance = info.num_storage_chance;
self.misc_memory_usage = self.memory_usage_internal();

Ok(())
}

pub fn rebuild_and_resolve_forgotten_streets(&mut self) -> Result<(), String> {
self.check_card_config()?;
self.reinit_root()?;
self.init_root()?;
self.allocate_memory_after_load()?;
self.resolve_reloaded_nodes(1000, 0.01, false)
}
Expand All @@ -889,8 +842,8 @@ impl PostFlopGame {
.enumerate()
.filter(|(_, n)| {
n.lock().turn != NOT_DEALT
&& n.lock().river == NOT_DEALT
&& matches!(n.lock().prev_action, Action::Chance(..))
&& n.lock().river == NOT_DEALT
&& matches!(n.lock().prev_action, Action::Chance(..))
})
.map(|(i, _)| i)
.collect::<Vec<_>>();
Expand All @@ -903,8 +856,8 @@ impl PostFlopGame {
.enumerate()
.filter(|(_, n)| {
n.lock().turn != NOT_DEALT
&& n.lock().river != NOT_DEALT
&& matches!(n.lock().prev_action, Action::Chance(..))
&& n.lock().river != NOT_DEALT
&& matches!(n.lock().prev_action, Action::Chance(..))
})
.map(|(i, _)| i)
.collect::<Vec<_>>();
Expand Down
11 changes: 8 additions & 3 deletions src/game/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,14 @@ impl PostFlopNode {
if self.parent_node_index == usize::MAX {
Some(vec![])
} else {
let p = game.node_arena.get(self.parent_node_index)?;
let mut history = p.lock().compute_history_recursive(game)?;
history.push(p.lock().action_index(self.prev_action)?);
let indx_parent = game.node_arena.get(self.parent_node_index)?;
let node_parent = indx_parent.lock();
let mut history = node_parent.compute_history_recursive(game)?;
let idx = match self.prev_action {
Action::Chance(card_idx) => card_idx as usize,
_ => node_parent.action_index(self.prev_action)?,
};
history.push(idx);
Some(history)
}
}
Expand Down

0 comments on commit 963ed40

Please sign in to comment.