Struct tools_2048::Game
source · pub struct Game { /* private fields */ }Expand description
A struct that represents the 2048 game.
Implementations§
source§impl Game
impl Game
sourcepub fn from_existing(board: &[Vec<u64>], score: u64) -> Result<Self, Error>
pub fn from_existing(board: &[Vec<u64>], score: u64) -> Result<Self, Error>
Creates a game of 2048 from an existing board.
Arguments
board: The board to use.score: The score of the game.
Returns
Ok(Game): The game was created successfully.Err(Error): The game was not created successfully.
Errors
Error::InvalidSize: The size of the board is invalid. Must be at least 4.Error::InvalidBoard: The board is invalid. Must be quadratic.Error::InvalidValue: The board contains invalid values. Must be 0 or powers of 2 (except 1).
sourcepub fn result(&self) -> GameResult
pub fn result(&self) -> GameResult
Returns the result of the game.
Returns
Result::Victory: The game is won, 2048 was reached.Result::Pending: The game is in progress, 2048 is not reached yet.Result::Loss: The game is over, 2048 was not reached.
sourcepub fn state(&self) -> GameState
pub fn state(&self) -> GameState
Returns the state of the game.
Returns
State::InProgress: The game is in progress.State::GameOver: The game is over.
sourcepub fn find_best_move(&self, depth: usize) -> Result<GameMove, Error>
pub fn find_best_move(&self, depth: usize) -> Result<GameMove, Error>
Find the best move to make based on the current board state. Based on Monte Carlo algorithm (randomized guessing). Uses multiple threads to speed up the process.
Arguments
depth- The number of simulated games to play to determine the best move. Recommended value is 1000.
Returns
Ok(GameMove)- The best move to make.Err(Error)- There are no valid moves left.
Errors
Error::NoValidMove- There are no valid moves left.
Trait Implementations§
Auto Trait Implementations§
impl RefUnwindSafe for Game
impl Send for Game
impl Sync for Game
impl Unpin for Game
impl UnwindSafe for Game
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more