示例#1
0
        bool placecenter(List <PlacementUnit> placementUnits, int index, Room room)
        {
            for (int i = 0; i < placementUnits.Count; i++)
            {
                PlacementUnit placementUnit = placementUnits[i];
                foreach (Tuple <Vector2D, int> positionAndRotation in placementUnit.positionsAndRotationsDomain)
                {
                    // Place placement unit only if possible and then move on to test next unit
                    if (placementUnit.TryFitAt(positionAndRotation, ref room))
                    {
                        // Move on to the subsequent placement unit, and test if any placements in its domain fit
                        bool couldNextUnitBePlaced =
                            placecenter(placementUnits, i + 1, room);

                        if (couldNextUnitBePlaced)
                        {
                            return(true);
                        }
                        else
                        {
                            // Move back placementUnit to default placement and unregister placement
                            placementUnit.Unplace(positionAndRotation, ref room);
                        }
                    }
                }
            }
        }
示例#2
0
        /// <summary>Tries to fit placement units in list -- from indexToTest to the end of the list -- in the room</summary>
        /// <param name="placementUnits">List of placement unit to place in room</param>
        /// <param name="indexToTest">List index of placement unit to try to fit in room</param>
        /// <param name="room">Room to place placement units in</param>
        /// <returns>
        /// Whether there were any possible arrangement of the placement units
        /// at indexToTest in list and subsequent placement units in list
        /// </returns>
        private bool TestPlacementRecursive(ref List <PlacementUnit> placementUnits, int indexToTest, ref Room room)
        {
            if (indexToTest >= placementUnits.Count)
            {
                // Print the room grid of obstruction values
                //Console.WriteLine(room);
                // All placement units in placementUnits have been tested
                return(true);
            }
            else
            {
                PlacementUnit placementUnit = placementUnits[indexToTest];

                // Test if placements in domains are possible
                foreach (Tuple <Vector2D, int> positionAndRotation in placementUnit.positionsAndRotationsDomain)
                {
                    // Place placement unit only if possible and then move on to test next unit
                    if (placementUnit.TryFitAt(positionAndRotation, ref room))
                    {
                        // Move on to the subsequent placement unit, and test if any placements in its domain fit
                        bool couldNextUnitBePlaced = TestPlacementRecursive(ref placementUnits, indexToTest + 1, ref room);

                        if (couldNextUnitBePlaced)
                        {
                            return(true);
                        }
                        else
                        {
                            // Move back placementUnit to default placement and unregister placement
                            placementUnit.Unplace(positionAndRotation, ref room);
                        }
                    }
                }

                // No placements fit for this and all subsequent placement units
                return(false);
            }
        }