private void startIterativeSearch(ChessBoard init) { DateTime start_time = DateTime.Now; MoveGenerator.end_time = start_time.AddSeconds(this.Interval); //set iterative deepning end time; int i = 1; while (DateTime.Compare(DateTime.Now , MoveGenerator.end_time)<=0) { Console.WriteLine("Depth is "+i); init.AlphaBetaSearch(int.MinValue, int.MaxValue, i, true); ChessBoard bestState = init.bestState; MoveGenerator.best_move_queue.Clear(); while (bestState != null) { MoveGenerator.addAIBestMoveQueue(bestState.move); bestState = bestState.bestState; } //foreach (Move move in MoveGenerator.best_move_queue) //{ // Console.WriteLine("Best move is " + move.from_rank + move.from_file + move.to_rank + move.to_file); //} i++; } return; }
private void startIterativeSearch(ChessBoard init, bool min_max) { DateTime start_time = DateTime.Now; MoveGenerator.end_time = start_time.AddSeconds(this.Interval); //set iterative deepning end time; int i = 1; MoveGenerator.best_move_queue.Clear(); while (DateTime.Compare(DateTime.Now, MoveGenerator.end_time) <= 0) { MoveGenerator.states = 0; Console.WriteLine("Depth is " + i); int alpha_beta = init.AlphaBetaSearch(int.MinValue, int.MaxValue, i, min_max); ChessBoard bestState = init.bestState; if (bestState == null) { Console.WriteLine("Game over!!!"); MessageBoxResult result = MessageBox.Show("Game over", "Confirmation", MessageBoxButton.OK); if (result == MessageBoxResult.OK) { Application.Current.Dispatcher.Invoke((Action)(() => { Application.Current.Shutdown(); })); } } MoveGenerator.best_move_queue.Clear(); while (bestState != null) { MoveGenerator.addAIBestMoveQueue(bestState.move); bestState = bestState.bestState; } //Console.WriteLine("Searching in layer: {0} through {1} evaluations with an average branching factor of {2}", i, MoveGenerator.states, (Math.Pow(MoveGenerator.states, (1 / (double)i)))); MoveGenerator.branchingfactor += (Math.Pow(MoveGenerator.states, (1 / (double)i))); MoveGenerator.searchcounter += 1; //Console.WriteLine("Average branching factor of the algorithm: "+ (MoveGenerator.branchingfactor/ MoveGenerator.searchcounter)); i++; } return; }