Ejemplo n.º 1
0
 public static GameState MoveCursor(GameState current, MineField mineField, Direction direction)
 {
     return(current.Do(
                current
                .CursorPosition
                .Move(direction, mineField.Size)));
 }
Ejemplo n.º 2
0
 public static GameState Uncover(GameState current, MineField mineField)
 {
     return(current.Do(
                current
                .Covers()
                .UncoverDeep(mineField, current.CursorPosition)));
 }
Ejemplo n.º 3
0
 public static GameState Quit(GameState current, MineField mineField)
 {
     return(current.Do(
                current
                .Covers()
                .UncoverRange(
                    mineField.Mines())));
 }
Ejemplo n.º 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()));
        }
Ejemplo n.º 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)));
 }
Ejemplo n.º 6
0
 public static GameState Start(MineField mineField)
 {
     return(GameState.Create(Covers.Create(mineField.Size)));
 }