minsweeper_rs/solver/
start.rs1use std::fmt::{Display, Formatter};
2use crate::{CellType, GameState, GameStatus, Minsweeper};
3use crate::solver::{GameResult, Logic, Move, Solver};
4
5#[derive(Copy, Clone, Debug)]
6pub struct SafeStart;
7
8impl Solver for SafeStart {
9
10 fn solve(&self, _game_state: &GameState) -> Option<Move> {
11 None
12 }
13
14 fn solve_game(&self, minsweeper: &mut dyn Minsweeper) -> GameResult {
15 match minsweeper.gamestate().status {
16 GameStatus::Playing | GameStatus::Won => GameResult::Won,
17 GameStatus::Lost => GameResult::Lost,
18 GameStatus::Never => GameResult::Resigned
19 }
20 }
21}
22
23#[derive(Copy, Clone, Debug)]
24pub struct ZeroStart;
25
26impl Solver for ZeroStart {
27
28 fn solve(&self, _game_state: &GameState) -> Option<Move> {
29 None
30 }
31
32 fn solve_game(&self, minsweeper: &mut dyn Minsweeper) -> GameResult {
33 match minsweeper.gamestate().status {
34 GameStatus::Playing if minsweeper.gamestate().board
35 .iter()
36 .any(|e| matches!(e.cell_type, CellType::Safe(0))) => GameResult::Won,
37 GameStatus::Playing => GameResult::Lost,
38 GameStatus::Won => GameResult::Won,
39 GameStatus::Lost => GameResult::Lost,
40 GameStatus::Never => GameResult::Resigned
41 }
42 }
43}
44
45#[derive(Copy, Clone, Debug)]
46pub enum StartLogic {}
47
48impl Display for StartLogic {
49 fn fmt(&self, _f: &mut Formatter<'_>) -> std::fmt::Result {
50 unreachable!()
51 }
52}
53
54impl Logic for StartLogic {
55
56}