1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
use std::ops::Index; pub mod ai; mod draw; pub mod movement; pub mod tests; mod tools; pub const IS_DEBUG: bool = false; #[derive(Copy, Clone, Debug)] pub struct GameBoard { row_one: [TileStatus; 3], row_two: [TileStatus; 3], row_three: [TileStatus; 3], } impl Index<usize> for GameBoard { type Output = [TileStatus; 3]; fn index(&self, index: usize) -> &[TileStatus; 3] { match index { 0 => &self.row_one, 1 => &self.row_two, 2 => &self.row_three, _ => panic!("Gameboard can not be indexed for this value."), } } } pub struct MovementReturn { pub game_board: Option<GameBoard>, pub placed: bool, } #[derive(Copy, Clone)] pub enum AiMode { Random, SmartRandom, None, } pub enum Winner { Nought, Cross, None, } #[derive(Copy, Clone, Debug)] pub enum TileStatus { Nought(Cursor), Cross(Cursor), Cursor, None, } #[derive(Copy, Clone, Debug)] pub enum Cursor { True, None, } pub enum GameMode { TwoPlayer, SinglePlayer, Spectate, } #[derive(Copy, Clone)] pub enum Players { Nought, Cross, } pub fn switch_player(current_player: Players) -> Players { match current_player { Players::Cross => { if IS_DEBUG { println!("Current player was switched to Nought"); }; Players::Nought } Players::Nought => { if IS_DEBUG { println!("Current player was switched to Cross"); }; Players::Cross } } } impl GameBoard { pub fn empty_board() -> Self { Self { row_one: [TileStatus::Cursor, TileStatus::None, TileStatus::None], row_two: [TileStatus::None, TileStatus::None, TileStatus::None], row_three: [TileStatus::None, TileStatus::None, TileStatus::None], } } }