Beispiel #1
0
 private Coordinate2D GetRandomJustFloorSquareAvoidingPerimeter(State state, Level level)
 {
     List<Coordinate2D> coordList = new List<Coordinate2D>();
     foreach (Coordinate2D coord in level.InsideCoordinates)
     {
         if (level.IsJustFloor(coord))
         {
             bool onPerimeter = false;
             foreach (Coordinate2D neighbor in coord.FourNeighbors)
             {
                 if (level.IsWall(neighbor))
                 {
                     onPerimeter = true;
                     break;
                 }
             }
             if (!onPerimeter)
             {
                 coordList.Add(coord);
             }
         }
     }
     if (coordList.Count == 0)
     {
         return Coordinate2D.Undefined;
     }
     return coordList[state.Random.Next(coordList.Count)];
 }
Beispiel #2
0
        private void CheckRemove(State state, Level level, MoveList moveList)
        {
            int pushes = LevelUtils.SolutionPushes(moveList);

            bool removedASquare = false;
            foreach (Coordinate2D coord in level.InsideCoordinates)
            {
                if (level.IsJustFloor(coord))
                {
                    // Remove the square.
                    Level subLevel = new Level(level);
                    subLevel[coord] = Cell.Wall;

                    // Ensure that this does not corrupt the level.
                    if (!LevelUtils.AllBoxesAndTargetsAreAccessible(level))
                    {
                        continue;
                    }

                    // See if the level is still soluble.
                    MoveList subMoveList = FastSolve(state, subLevel);
                    if (subMoveList != null)
                    {
                        removedASquare = true;

                        if (verbose >= 2)
                        {
                            state.Log.DebugPrint("Removing square {0}", coord);
                        }
                        if (verbose >= 3)
                        {
                            state.Log.DebugPrint("Checking for more square removal:");
                            state.Log.DebugPrint(subLevel.AsText);
                        }

                        // Recursively check for more squares than can be removed.
                        AddSmallestLevel(state, subLevel, subMoveList);
                    }
                }
            }

            // At least one smaller level was soluble with the same boxes and targets.
            if (!removedASquare)
            {
                AddLevel(state, level, moveList);
            }
        }
Beispiel #3
0
 private Coordinate2D GetRandomJustFloorSquare(State state, Level level)
 {
     List<Coordinate2D> coordList = new List<Coordinate2D>();
     foreach (Coordinate2D coord in level.InsideCoordinates)
     {
         if (level.IsJustFloor(coord))
         {
             coordList.Add(coord);
         }
     }
     if (coordList.Count == 0)
     {
         return Coordinate2D.Undefined;
     }
     return coordList[state.Random.Next(coordList.Count)];
 }