/// <summary> /// Find the best move for the given player /// </summary> /// <param name="trace"> Trace object or null</param> /// <param name="rnd"> Random object</param> /// <param name="rndRep"> Repetitive random object</param> /// <param name="board"> Board</param> /// <param name="searchMode"> Search mode</param> /// <param name="ePlayer"> Player making the move</param> /// <param name="dispatcher"> Main thread dispatcher</param> /// <param name="actionMoveFound"> Action to execute when the find best move routine is done</param> /// <param name="cookie"> Cookie to pass to the actionMoveFound action</param> /// <returns> /// true if search has started, false if search engine is busy /// </returns> public static bool FindBestMove <T>(ITrace trace, Random rnd, Random rndRep, ChessBoard board, SearchMode searchMode, ChessBoard.PlayerE ePlayer, Dispatcher dispatcher, Action <T, MoveExt> actionMoveFound, T cookie) { bool bRetVal; bool bMultipleThread; SearchEngine searchEngine; if (IsSearchEngineBusy) { bRetVal = false; } else { bRetVal = true; m_bCancelSearch = false; if (searchMode.m_eOption == SearchMode.OptionE.UseMinMax) { searchEngine = new SearchEngineMinMax(trace, rnd, rndRep); } else { searchEngine = new SearchEngineAlphaBeta(trace, rnd, rndRep); } bMultipleThread = (searchMode.m_eThreadingMode == SearchMode.ThreadingModeE.DifferentThreadForSearch || searchMode.m_eThreadingMode == SearchMode.ThreadingModeE.OnePerProcessorForSearch); m_searchEngineWorking = searchEngine; if (bMultipleThread) { Task.Factory.StartNew(() => searchEngine.FindBestMove(board, searchMode, ePlayer, dispatcher, actionMoveFound, cookie)); } else { searchEngine.FindBestMove(board, searchMode, ePlayer, null /*dispatcher*/, actionMoveFound, cookie); } } return(bRetVal); }
/// <summary> /// Class constructor. Build a board. /// </summary> private ChessBoard(SearchEngineAlphaBeta searchEngineAlphaBeta, SearchEngineMinMax searchEngineMinMax) { m_pBoard = new PieceE[64]; m_book = new Book(); m_piPiecesCount = new int[16]; m_rnd = new Random((int)DateTime.Now.Ticks); m_rndRep = new Random(0); m_stackPossibleEnPassantAt = new Stack<int>(256); m_trace = null; m_moveHistory = new MoveHistory(); m_bDesignMode = false; m_moveStack = new MovePosStack(); m_searchEngineAlphaBeta = searchEngineAlphaBeta; m_searchEngineMinMax = searchEngineMinMax; ResetBoard(); }
/// <summary> /// Class constructor. Build a board. /// </summary> public ChessBoard(SearchEngine.ITrace trace) : this(null, null) { m_trace = trace; m_searchEngineAlphaBeta = new SearchEngineAlphaBeta(trace, m_rnd, m_rndRep); m_searchEngineMinMax = new SearchEngineMinMax(trace, m_rnd, m_rndRep); }