[−][src]Struct connect6::game::Game
Implementation of Game Connect6
It defines the game connect6 with some visualization utilities.
Examples
let mut game = Game::new(); let result = game.set((0, 0)); game.print(&mut std::io::stdout()).unwrap(); let winner = game.is_game_end(); assert_eq!(winner, Player::None);
Methods
impl Game[src]
pub fn new() -> Game[src]
Construct a new Game
pub fn set(
&mut self,
pos: (usize, usize)
) -> Result<SetResult, Box<dyn Error + Send>>[src]
&mut self,
pos: (usize, usize)
) -> Result<SetResult, Box<dyn Error + Send>>
Set the stone of current player with given position as zero-indexed (row, col).
Examples
let mut game = Game::new(); let result = game.set((3, 4)); let expected = SetResult{ player: Player::Black, num_remain: 0, position: (3, 4) }; assert_eq!(result.unwrap(), expected);
Errors
- If given position out of board.
- If other stone place already in given position.
pub fn get_board(&self) -> &Board[src]
Return board
pub fn get_turn(&self) -> Player[src]
Return current player
pub fn get_remain(&self) -> i32[src]
Return num_remain
pub fn print(&self, writer: &mut dyn Write) -> Result<usize>[src]
Print the board status
Examples
let mut game = Game::new(); let result = game.set((3, 4)).unwrap(); // black let result = game.set((3, 3)).unwrap(); // white game.print(&mut std::io::stdout());
Expected results
ⓘThis example is not tested
0 A B C D E F G H I J K L M N O a _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ b _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ c _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ d _ _ _ O X _ _ _ _ _ _ _ _ _ _ e _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ f _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ g _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ h _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ i _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ j _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ k _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ l _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ m _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ n _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ o _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
pub fn is_game_end(&self) -> Player[src]
Return game winner if game end, else Player::None
Examples
let mut game = Game::new(); game.set((3, 4)).unwrap(); assert_eq!(game.is_game_end(), Player::None);
Auto Trait Implementations
Blanket Implementations
impl<T> From for T[src]
impl<T, U> Into for T where
U: From<T>, [src]
U: From<T>,
impl<T, U> TryFrom for T where
T: From<U>, [src]
T: From<U>,
type Error = !
🔬 This is a nightly-only experimental API. (
try_from)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T> Borrow for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> BorrowMut for T where
T: ?Sized, [src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T[src]
impl<T, U> TryInto for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
🔬 This is a nightly-only experimental API. (
try_from)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,