pub struct Computer {
pub search_depth: usize,
pub team: Team,
pub last_node_count: usize,
pub perfect_chance: f64,
}
Expand description
Root-level structure for managing the game as a collection of board states
Fields
search_depth: usize
team: Team
last_node_count: usize
perfect_chance: f64
Implementations
sourceimpl Computer
impl Computer
pub fn new(search_depth: usize, team: Team, perfect_chance: f64) -> Computer
sourcefn available_turns(&self, board: &Board) -> Vec<Move>
fn available_turns(&self, board: &Board) -> Vec<Move>
Get vector of available moves for a given board
sourcefn gen_tree(&mut self, tree: &mut Arena<BoardNode>, board: Board) -> NodeId
fn gen_tree(&mut self, tree: &mut Arena<BoardNode>, board: Board) -> NodeId
Generate tree of boards to given search depth, return root node
sourcefn propagate_scores(tree: Arena<BoardNode>, root: NodeId) -> Arena<BoardNode>
fn propagate_scores(tree: Arena<BoardNode>, root: NodeId) -> Arena<BoardNode>
Propagate scores up the tree employing MiniMax algorithm
sourcefn best_score(board: &Board, children_scores: Vec<isize>) -> isize
fn best_score(board: &Board, children_scores: Vec<isize>) -> isize
Get best of given scores for given team
sourcefn insert_board_scores(
&mut self,
tree: &mut Arena<BoardNode>,
nodes: Vec<NodeId>
)
fn insert_board_scores(
&mut self,
tree: &mut Arena<BoardNode>,
nodes: Vec<NodeId>
)
For given NodeIDs, insert score of board into tree Used for leaf nodes ready for propagating up tree
sourcefn get_leaf_nodes(
&mut self,
tree: &mut Arena<BoardNode>,
root: NodeId
) -> Vec<NodeId>
fn get_leaf_nodes(
&mut self,
tree: &mut Arena<BoardNode>,
root: NodeId
) -> Vec<NodeId>
Traverse tree from given root ID and get NodeIDs of leaf nodes (those without children)
sourcefn expand_layer(
&mut self,
tree: &mut Arena<BoardNode>,
nodes: Vec<NodeId>
) -> Vec<NodeId>
fn expand_layer(
&mut self,
tree: &mut Arena<BoardNode>,
nodes: Vec<NodeId>
) -> Vec<NodeId>
Expand all given nodes and return newly inserted layer of nodes
sourcefn expand_node(
&mut self,
tree: &mut Arena<BoardNode>,
node: NodeId
) -> Vec<NodeId>
fn expand_node(
&mut self,
tree: &mut Arena<BoardNode>,
node: NodeId
) -> Vec<NodeId>
Insert all possible next boards as children of given board node
sourcefn insert_boards(
&mut self,
tree: &mut Arena<BoardNode>,
boards: Vec<BoardNode>
) -> Vec<NodeId>
fn insert_boards(
&mut self,
tree: &mut Arena<BoardNode>,
boards: Vec<BoardNode>
) -> Vec<NodeId>
Insert given boards into tree
sourcefn get_move_boards(&self, board: &BoardNode) -> Vec<BoardNode>
fn get_move_boards(&self, board: &BoardNode) -> Vec<BoardNode>
Get all possible next boards from given board
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Computer
impl Send for Computer
impl Sync for Computer
impl Unpin for Computer
impl UnwindSafe for Computer
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more