Ejemplo n.º 1
0
        public double Solve(ChessType[] board, ChessType color, Mode mode, int nbits, int empties, int discdiff)
        {
            int[]  myboard = new int[91];
            double eval    = 0;

            nodes = 0; bestMove = 0;
            int col = (color == ChessType.WHITE ? 1 : 0);

            if (empties > 20)
            {
                MidSolve midSolve = new MidSolve();
                midSolve.SearchDepth = 8;
                midSolve.PrepareToSolve(board);
                eval     = midSolve.Solve(board, -Constants.HighestScore, Constants.HighestScore, color, empties, discdiff, 1);
                bestMove = midSolve.BestMove;
                nodes    = midSolve.Nodes;
            }
            else
            {
                EndSolve endSolve = new EndSolve();
                endSolve.PrepareToSolve(board);
                if (empties > 16)
                {
                    eval = endSolve.Solve(board, -1, 1, color, empties, discdiff, 1);
                }
                else
                {
                    eval = endSolve.Solve(board, -64, 64, color, empties, discdiff, 1);
                }
                bestMove = endSolve.BestMove;
                nodes    = endSolve.Nodes;
            }
            return(eval);
        }
Ejemplo n.º 2
0
        public void Search(ChessType[] curboard, ChessType col)
        {
            int    empties = 0;
            int    white   = 0;
            int    black   = 0;
            int    discdiff;
            double start_time;

            ChessType[] board = new ChessType[91];

            for (int i = 0; i < 91; i++)
            {
                board[i] = curboard[i];
            }
            for (int i = 10; i <= 80; i++)
            {
                switch (board[i])
                {
                case ChessType.EMPTY:
                    empties++;
                    break;

                case ChessType.BLACK:
                    black++;
                    break;

                case ChessType.WHITE:
                    white++;
                    break;

                default:
                    break;
                }
            }
            discdiff   = (col == ChessType.BLACK ? black - white : white - black);
            start_time = getCurTime();
            if (empties > emptiesOfStartGame)
            {
                boardState = BoardState.START;
                staSolve.PrepareToSolve(board);
                bestScore = staSolve.Solve(board, -Constants.HighestScore, Constants.HighestScore, col, empties, discdiff, 1);

                bestMove = staSolve.BestMove;
                nodes    = staSolve.Nodes;
            }
            else if (empties > wldDepth)
            {
                boardState = BoardState.MIDDLE;
                midSolve.PrepareToSolve(board);
                bestScore = midSolve.Solve(board, -Constants.HighestScore, Constants.HighestScore, col, empties, discdiff, 1);
                bestMove  = midSolve.BestMove;
                nodes     = midSolve.Nodes;
            }
            else
            {
                boardState = BoardState.WLD;
                bestScore  = mtdSolve.Solve(board, col, MTDSolve.Mode.DEFAULT, 0, empties, discdiff);
                bestMove   = mtdSolve.BestMove;
                nodes      = mtdSolve.Nodes;
            }
            time = (getCurTime() - start_time) / 10000000.0;
            if (time < 0)
            {
                time = 0;
            }
        }