public void SolveProblem(Chessboard chessboard, int maxNumberOfSteps) { //array that works will be made on int[] queensPlacement = chessboard.GetQueensPlacament(); //array to check if something changed between two arrays int[] compareArray = new int[queensPlacement.Length]; //array to check heuristic of all position when queen moves verticaly int[] heuristicArray = new int[queensPlacement.Length]; heuristic = CalculateHeuristic(queensPlacement); numberOfSteps = 0; while (numberOfSteps < maxNumberOfSteps && heuristic > 0) { numberOfSteps++; queensPlacement.CopyTo(compareArray, 0); queensPlacement = MoveQueensInChessboard(queensPlacement, queensPlacement.Length, heuristicArray); //If array wasn't changed it will be replaced by a new random one if (ArrayNotChanged(queensPlacement, compareArray)) { chessboard.FillWithRandomPlacements(); queensPlacement = chessboard.GetQueensPlacament(); } heuristic = CalculateHeuristic(queensPlacement); } Chessboard drawCheesboard = new Chessboard(queensPlacement, window); }
private List <Chessboard> ChangeBoard(int size, int numberOfStates, List <Chessboard> chessboardStates, Chessboard chessboard) { for (int n = 0; n < numberOfStates; n++) { int[] compareArray = new int[size]; int[] heuristicArray = new int[size]; chessboardStates[n].GetQueensPlacament().CopyTo(compareArray, 0); //in each iteration of for loop given chessboard will be moved to it's best possible state chessboardStates[n].SetQueensPlacement(MoveQueensInChessboard(chessboardStates[n].GetQueensPlacament(), size, heuristicArray)); //If array wasn't changed it will be replaced by a new random one if (ArrayNotChanged(chessboardStates[n].GetQueensPlacament(), compareArray)) { chessboard.FillWithRandomPlacements(); chessboardStates[n].SetQueensPlacement(chessboard.GetQueensPlacament()); } } return(chessboardStates); }