示例#1
0
        public INode[] GenerateChildren(INode node, int maxCount)
        {
            TreeNode           child;
            QueenConstellation newConstellation;
            List <INode>       generatedNodes = new List <INode>();

            QueenConstellation constellation = (QueenConstellation)node.Data;
            int freeColumn = constellation.FreeColumn;

            if (freeColumn == -1)
            {
                throw new Exception("No FreeColumn available");
            }
            for (int i = 0; i < constellation.BoardDimension; i++)
            {
                if (constellation.TestQueenPosition(freeColumn, i))
                {
                    newConstellation = new QueenConstellation(constellation);
                    newConstellation.SetQueen(freeColumn, i);
                    child = new TreeNode((TreeNode)node, newConstellation);
                    generatedNodes.Add(child);
                }
                if (maxCount > 0 && generatedNodes.Count == maxCount)
                {
                    break;
                }
            }

            INode[] result = new TreeNode[generatedNodes.Count];
            generatedNodes.CopyTo(result);
            return(result);
        }
示例#2
0
        public QueenProblem(int boardDimension)
        {
            _createdConstellations = new List <QueenConstellation>();
            QueenConstellation startConstellation = new QueenConstellation(boardDimension);

            _begin       = new TreeNode(startConstellation);
            _destination = null;
        }
示例#3
0
 /// <summary>
 /// Kopierkonstruktor
 /// </summary>
 /// <param name="Operand"></param>
 public QueenConstellation(QueenConstellation operand)
 {
     _lastQueenOccupations = 0;
     _board = new int[operand._board.GetLength(0)];
     operand._board.CopyTo(_board, 0);
     _occupiedPositions = new bool[operand._board.GetLength(0), operand._board.GetLength(0)];
     for (int i = 0; i < _occupiedPositions.GetLength(0); i++)
     {
         for (int j = 0; j < _occupiedPositions.GetLength(1); j++)
         {
             _occupiedPositions[i, j] = operand._occupiedPositions[i, j];
         }
     }
 }
示例#4
0
        public double GetHeuristicValue(OKSearchRoom.INode node, IHeuristicSearchProblem searchProblem, OKSearchRoom.ISearchMethod searchMethod)
        {
            QueenConstellation constellation = (QueenConstellation)node.Data;

            return(constellation.LastQueenOccupations);
        }
示例#5
0
        public bool CompareNodes(INode node)
        {
            QueenConstellation constellation = (QueenConstellation)node.Data;

            return(constellation.AllQueensOnTheBoard);
        }