Пример #1
0
 public static GameState MoveCursor(GameState current, MineField mineField, Direction direction)
 {
     return(current.Do(
                current
                .CursorPosition
                .Move(direction, mineField.Size)));
 }
Пример #2
0
 public static GameState Uncover(GameState current, MineField mineField)
 {
     return(current.Do(
                current
                .Covers()
                .UncoverDeep(mineField, current.CursorPosition)));
 }
Пример #3
0
 public static GameState Quit(GameState current, MineField mineField)
 {
     return(current.Do(
                current
                .Covers()
                .UncoverRange(
                    mineField.Mines())));
 }
Пример #4
0
        public GameResult Evaluate(MineField mineField)
        {
            var covers = Covers();

            return(new GameResult(
                       mineField
                       .Mines()
                       .Any(mine => !covers.IsCovered(mine)),
                       covers.CoverCount() - mineField.Mines().Count()));
        }
Пример #5
0
 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)));
 }
Пример #6
0
 public static GameState Start(MineField mineField)
 {
     return(GameState.Create(Covers.Create(mineField.Size)));
 }