Beispiel #1
0
		private void AddWallsSequentially()
		{
			Room[,] r = _rooms;

			//capacity should be rooms * 2?
			ArrayList ExcludeWalls = new ArrayList(r.Length * 2);

			Random random = new Random();
			SolutionFinder finder = new SolutionFinder();
			finder.FindSolution(this);

			PassCount = 0;
			while (finder.CycleFound)
			{
				PassCount++;
				foreach (Room room in r)
				{
					//if there's already only one way out of this room, then skip it
					if (room.PassableNeighbors < 2)
						continue;

					Direction d = random.Next(4);
					Room neighbor = room.Neighbors[d] as Room;

					//if the selected neighbor isn't a room, move on
					if (neighbor == null)
						continue;

					//if there's already only one way out of the selected neighbor, move on
					if (neighbor.PassableNeighbors < 2)
						continue;

					RoomPair pair = new RoomPair(room, room.Neighbors[d]);

					//if we've already determined that we can't add this wall, don't try again
					if (ExcludeWalls.Contains(pair))
						continue;

					//now try to add the new wall, and make sure all the rooms are still reachable
					new Wall(room, d);
					finder.FindSolution(this);
					if (finder.RoomsConnected < r.Length)
					{
						room.RemoveConnector(d);
						ExcludeWalls.Add(pair);
						finder.CycleFound = true;
						finder.RoomsConnected = r.Length;
					}

					//break out of the foreach loop early if we've already eliminated all cycles
					if (!finder.CycleFound)
						break;
				}
			}
		}
Beispiel #2
0
		private void AddWallsRandomly()
		{
			Room[,] r = _rooms;
			Random random = new Random();
			SolutionFinder finder = new SolutionFinder();
			finder.FindSolution(this);
			while (finder.CycleFound /*&& finder.RoomsConnected == r.Length*/)
			{
				int i = random.Next(r.GetUpperBound(0) + 1);
				int j = random.Next(r.GetUpperBound(1) + 1);
				Direction d = random.Next(4);
				Room room = r[i, j];
				if (room.Neighbors[d] is Room)
				{
					new Wall(room, d);
					finder.FindSolution(this);
					if (finder.RoomsConnected < r.Length)
					{
						room.RemoveConnector(d);
						finder.FindSolution(this);
					}
				}
			}
		}