コード例 #1
0
        public string getCommand(Position pos, bool drawOffer, List <Position> history)
        {
            // Create a search object
            ulong[] posHashList     = new ulong[200 + history.Count];
            int     posHashListSize = 0;

            for (int i = 0; i < history.Count; i++)
            {
                Position p = history[i];
                posHashList[posHashListSize++] = p.zobristHash();
            }
            tt.nextGeneration();
            Search sc = new Search(pos, posHashList, posHashListSize, tt);

            // Determine all legal moves
            MoveGen.MoveList moves = new MoveGen().pseudoLegalMoves(pos);
            MoveGen.RemoveIllegal(pos, moves);
            sc.scoreMoveList(moves, 0);

            // Test for "game over"
            if (moves.size == 0)
            {
                // Switch sides so that the human can decide what to do next.
                return("swap");
            }

            if (bookEnabled)
            {
                Move bookMove = book.getBookMove(pos);
                if (bookMove != null)
                {
                    SystemHelper.printf("Book moves: " + book.getAllBookMoves(pos));
                    return(TextIO.moveTostring(pos, bookMove, true));
                }
            }

            // Find best move using iterative deepening
            currentSearch = sc;
            sc.setListener(listener);
            Move bestM;

            if ((moves.size == 1) && (canClaimDraw(pos, posHashList, posHashListSize, moves.m[0]) == ""))
            {
                bestM       = moves.m[0];
                bestM.score = 0;
            }
            else if (randomMode)
            {
                bestM = findSemiRandomMove(sc, moves);
            }
            else
            {
                sc.timeLimit(minTimeMillis, maxTimeMillis);
                bestM = sc.iterativeDeepening(moves, maxDepth, maxNodes, verbose);
            }
            currentSearch = null;
//        tt.printStats();
            string strMove = TextIO.moveTostring(pos, bestM, true);

            bestmv = bestM;

            // Claim draw if appropriate
            if (bestM.score <= 0)
            {
                string drawClaim = canClaimDraw(pos, posHashList, posHashListSize, bestM);
                if (drawClaim != "")
                {
                    strMove = drawClaim;
                }
            }
            return(strMove);
        }