private NewDoor AnswerSetToCellMatrix(AnswerSets answers, Partition oldRoom)
        {
            IList <AnswerSet> answerSetsList = answers.Answersets;

            NewDoor door = null;

            if (answerSetsList.Count > 0)
            {
                int       index = randomGenerator.Next(answerSetsList.Count);
                AnswerSet a     = answerSetsList[index];

                foreach (Object obj in a.Atoms)
                {
                    if (obj is Cell)
                    {
                        matrixCells.AddCell((Cell)obj);
                    }
                    else if (obj is NewDoor)
                    {
                        door = (NewDoor)obj;
                    }
                }
            }
            return(door);
        }
        private NewDoor AnswerSetToCellMatrix(AnswerSets answers)
        {
            IList <AnswerSet> answerSetsList = answers.Answersets;

            NewDoor door = null;

            if (answerSetsList.Count > 0)
            {
                int       index = randomGenerator.Next(answerSetsList.Count);
                AnswerSet a     = answers.Answersets[index];

                try {
                    foreach (object obj in a.Atoms)
                    {
                        if (obj is Cell)
                        {
                            matrixCells.AddCell((Cell)obj);
                        }
                        else if (obj is NewDoor)
                        {
                            door = (NewDoor)obj;
                        }
                    }
                }
                catch (Exception e) {
                    UnityEngine.Debug.Log(e.ToString());
                    UnityEngine.Debug.Log(e.StackTrace);
                }
            }
            return(door);
        }
        public void SpacePartitioning(bool horizontal, Partition nextPartitioned)
        {
            if (nextPartitioned.Size < minRoomSize)
            {
                AddPartition(nextPartitioned);
                return;
            }

            double rNumber = randomGenerator.NextDouble();

            //        if (rNumber < pruningPercentage * (1 - nextPartitioned.getSize() / mapSize)) {
            //          addPartition(nextPartitioned);
            //          return;
            //        }

            if (rNumber < sameOrientationPercentage)
            {
                horizontal = !horizontal;
            }

            EmbASPManager controller = new EmbASPManager();

            controller.InitializeEmbASP(randomAnswersetNumber);

            InputProgram input   = controller.Input;
            Handler      handler = controller.Handler;

            input.AddFilesPath(encodingFolder + "2-space_partitioning.asp");
            handler.AddProgram(input);

            InputProgram facts = new ASPInputProgram();

            int orientationIndex = (horizontal) ? 1 : 0;


            facts.AddProgram("row(" + nextPartitioned.getMinRow() + ".." + nextPartitioned.getMaxRow() + ").");
            facts.AddProgram("col(" + nextPartitioned.getMinCol() + ".." + nextPartitioned.getMaxCol() + ").");
            facts.AddProgram("max_row(" + nextPartitioned.getMaxRow() + ").");
            facts.AddProgram("max_col(" + nextPartitioned.getMaxCol() + ").");
            facts.AddProgram("min_row(" + nextPartitioned.getMinRow() + ").");
            facts.AddProgram("min_col(" + nextPartitioned.getMinCol() + ").");
            facts.AddProgram("min_distance_wall(" + minDistanceWall + ").");
            facts.AddProgram("orientation(" + orientation[orientationIndex] + ").");

            foreach (Cell cell in matrixCells.SetCells)
            {
                if (cell.getRow() >= nextPartitioned.getMinRow() && cell.getRow() <= nextPartitioned.getMaxRow() &&
                    cell.getColumn() >= nextPartitioned.getMinCol() &&
                    cell.getColumn() <= nextPartitioned.getMaxCol())
                {
                    facts.AddObjectInput(cell);
                }
            }


            handler.AddProgram(facts);

            Output     o       = handler.StartSync();
            AnswerSets answers = (AnswerSets)o;

            NewDoor door = AnswerSetToCellMatrix(answers, nextPartitioned);


            if (door != null)
            {
                if (door.getType().Equals("hdoor"))
                {
                    SpacePartitioning(!horizontal, new Partition(nextPartitioned.getMinRow(), nextPartitioned.getMinCol(),
                                                                 door.getRow(), nextPartitioned.getMaxCol()));
                    SpacePartitioning(!horizontal, new Partition(door.getRow(), nextPartitioned.getMinCol(),
                                                                 nextPartitioned.getMaxRow(), nextPartitioned.getMaxCol()));
                }
                else if (door.getType().Equals("vdoor"))
                {
                    SpacePartitioning(!horizontal, new Partition(nextPartitioned.getMinRow(), nextPartitioned.getMinCol(),
                                                                 nextPartitioned.getMaxRow(), door.getColumn()));
                    SpacePartitioning(!horizontal, new Partition(nextPartitioned.getMinRow(), door.getColumn(),
                                                                 nextPartitioned.getMaxRow(), nextPartitioned.getMaxCol()));
                }
            }
            else
            {
                AddPartition(nextPartitioned);
            }
        }