public static GameState MoveCursor(GameState current, MineField mineField, Direction direction) { return(current.Do( current .CursorPosition .Move(direction, mineField.Size))); }
public static GameState Uncover(GameState current, MineField mineField) { return(current.Do( current .Covers() .UncoverDeep(mineField, current.CursorPosition))); }
public static GameState Quit(GameState current, MineField mineField) { return(current.Do( current .Covers() .UncoverRange( mineField.Mines()))); }
public GameResult Evaluate(MineField mineField) { var covers = Covers(); return(new GameResult( mineField .Mines() .Any(mine => !covers.IsCovered(mine)), covers.CoverCount() - mineField.Mines().Count())); }
private static Covers UncoverDeep( this Covers covers, MineField mineField, Point point) { if (!covers.IsCovered(point)) { return(covers); } if (!mineField.IsEmptyAt(point)) { return(covers.Uncover(point)); } return(point .Neighbours(mineField.Size) .Aggregate( covers.Uncover(point), (current, neighbor) => current.UncoverDeep(mineField, neighbor))); }
public static GameState Start(MineField mineField) { return(GameState.Create(Covers.Create(mineField.Size))); }