pub struct ConnectFour { /* private fields */ }
Expand description
Implementation of the Connect Four game. The board is implemented as to 64 bit masks. It allows for fast checking of winning conditions and legal moves. Apart from being able to play connect four, this type also features some utility functions which can help with implementations of heuristics and solvers.
Implementations§
Source§impl ConnectFour
impl ConnectFour
Sourcepub fn new() -> ConnectFour
pub fn new() -> ConnectFour
Create an empty board
Sourcepub fn play(&mut self, column: Column) -> bool
pub fn play(&mut self, column: Column) -> bool
Inserts a stone for the current player. true
if move has been legal
Sourcepub fn is_legal_move(&self, column: Column) -> bool
pub fn is_legal_move(&self, column: Column) -> bool
true
if the column is not full.
Sourcepub fn from_move_list(move_list: &str) -> ConnectFour
pub fn from_move_list(move_list: &str) -> ConnectFour
Create a game state from a sequence of moves. Each move represented as a number from 1 to 7 standing for the column the player put in their stones.
Sourcepub fn print_to(&self, out: impl Write) -> Result<()>
pub fn print_to(&self, out: impl Write) -> Result<()>
Prints out a text representation of a board to out
pub fn legal_moves(&self) -> impl Iterator<Item = Column> + use<'_>
Sourcepub fn is_victory(&self) -> bool
pub fn is_victory(&self) -> bool
true
if the player which did insert the last stone has won the game.
Sourcepub fn can_win_in_next_move(&self) -> bool
pub fn can_win_in_next_move(&self) -> bool
true
if the current player has winning moves available
Sourcepub fn non_loosing_moves(&self) -> impl Iterator<Item = Column>
pub fn non_loosing_moves(&self) -> impl Iterator<Item = Column>
List all moves, which prevent the opponet from winning immediately. Only gives valid results
if Self::can_win_in_next_move
is false
.
Trait Implementations§
Source§impl Clone for ConnectFour
impl Clone for ConnectFour
Source§fn clone(&self) -> ConnectFour
fn clone(&self) -> ConnectFour
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more