The algorithm for verifying or restarting the PLG.

The algorithm for verifying(success) or restarting(failure) the PLG.

With the PLG working correctly, we need to check that the PLG is complete. By complete I mean we need to check that the PLG created fulfills our requirements which are:
  1. Reach a minimum percentage of room density  towards the levels size. In other words we want a certain numbers of rooms to fill up the level before we can declare it as finished.
  2. Attach to our maze the must included pieces, in my example the Temple Room and the Minotaur Throne Room. these rooms must be attached included in our level.
  3. Find a pre-exit room for us to attach our exit room and place the exit.

This is how I check those requirements
1)Checking the Density: The first algorithm required a value X set from the user that indicated after how many tiles placed we should check the density. This was set because the scanning slowed down the process, and there was no point calculating  the density before X tiles. Recently been able to calculate the density based on the areas of each tile, I have removed the X value requirement mentioned above. So to check the Density we calculate the current density and compare it with our desired density. To calculate our current density it is
= (TotalAreaOccupiedbyRooms / TotalLevelArea) * 100;


2. Attaching our must included Pieces: Every time a new tile is moved to it's desired position, before we add the new exits to of that room to OpenExits list we:
  •  check if any of the points are outside the level dimensions (those points are stored elsewhere so we can attach to them one-Exit rooms later on).
  • Check if the tiles exits are within range of any of the exit points belonging to the "Must included" tiles. If there is we move that must included piece to that exit and attach the remaining available exits of the tile to openExit list. After the "Must Included" piece is placed and colition is checked, it changes folder (the must placed pieces are placed within a empty game object "Preplaced Rooms") to Rooms gameobject. After a must included piece has been removed we check if the if the "Preplaced Rooms" gameobject has a child count is zero. If it is we set the bool variable AllPreplacedRoomsFound==true.


3.Find a pre-exit room. To find the preexit room we use the line(s) set by the user and we raycast across the line pointing down.the tiles hit are stored to a list of possible pre-exit rooms. We then select one randomly and check if the exit room can be attached without any colition. Then we set a variable bool ExitFound = true; (it is initially set to false).

So our 3 conditions for a completed level are:
 Current Density> Target Density
AllPreplacedRoomsFound=true
ExitFound=true

Now if we have a look at the reasons a level would never complete would be:

  • the openExit list is empty. This may happen if we use many 2 exit rooms, or just the unlucky creation were rooms are placed out side our area and loose their exit points. Another reason could be the rooms are to big in regards to the level area.
  • the only way must included rooms do not attach is if the density is to low. (and we did not increase the density afterwards) I do not consider this a problem as we can add more tiles until the rooms are used.
  • The scan exit lines do not find a preexit room. This could happen because a) the scan lines are too smal in lenght, b) unlucky placement in combination with small dencity, c)Scan lines are placed too far away from the level boundries (note to restrict the scan lines within the level maxDimention +5).   

So an algorithm for checking the conditions would be:

While ( Current Density< Target Density or AllPreplacedRoomsFound=false or ExitFound=false And  Failsafe=4000)
{

if there are no more available exits or exceeded density< density (we set this for greater speed)
{
  LevelCannotComplete=true
 Break our while statement

}


 Place Tile -- this increases the density and eventually will use our replaced rooms

if( our density is good AND ExitNotFound and DontScanExitsCounter<0)
  {
   Search for exit  --if it is successful ExitFound=true;
 
   if (ExitFound=false)
      DontscanCounter=10;

  }

DontScanExitsCounter--
FailSafe++


}

Comments

Popular posts from this blog

Player stats and brightness.

Testing the PLG

More work done on the interface, saving data.