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); }
public QueenProblem(int boardDimension) { _createdConstellations = new List <QueenConstellation>(); QueenConstellation startConstellation = new QueenConstellation(boardDimension); _begin = new TreeNode(startConstellation); _destination = null; }
/// <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]; } } }
public double GetHeuristicValue(OKSearchRoom.INode node, IHeuristicSearchProblem searchProblem, OKSearchRoom.ISearchMethod searchMethod) { QueenConstellation constellation = (QueenConstellation)node.Data; return(constellation.LastQueenOccupations); }
public bool CompareNodes(INode node) { QueenConstellation constellation = (QueenConstellation)node.Data; return(constellation.AllQueensOnTheBoard); }