Exemplo n.º 1
0
        public IBestMoveResult BestMove(Board board, SearchConfig config, MoveTimer timer, CancellationToken cancelToken)
        {
            _timer       = timer;
            _cancelToken = cancelToken;

            if (_isWalledOff)
            {
                var longestPath = NextMoveOnLongestPath(board, board.PlayerToMove);
                return(new BestMoveResult(longestPath.Item1, longestPath.Item2));
            }
            else // otherwise fall back to alpha beta
            {
                var ab = new AlphaBeta().BestMove(board, config, timer, cancelToken);

                // but if alpha beta thinks we'll lose, do longest move
                if (ab.Score == int.MinValue)
                {
                    var longestPath = NextMoveOnLongestPath(board, board.PlayerToMove);
                    return(new BestMoveResult(longestPath.Item1, longestPath.Item2));
                }

                return(ab);
            }
        }
Exemplo n.º 2
0
        public IBestMoveResult BestMove(Board board, SearchConfig config, MoveTimer timer, CancellationToken cancelToken)
        {
            _timer = timer;
            _cancelToken = cancelToken;

            if (_isWalledOff)
            {
                var longestPath = NextMoveOnLongestPath(board, board.PlayerToMove);
                return new BestMoveResult(longestPath.Item1, longestPath.Item2);
            }
            else // otherwise fall back to alpha beta
            {
                var ab = new AlphaBeta().BestMove(board, config, timer, cancelToken);

                // but if alpha beta thinks we'll lose, do longest move
                if (ab.Score == int.MinValue)
                {
                    var longestPath = NextMoveOnLongestPath(board, board.PlayerToMove);
                    return new BestMoveResult(longestPath.Item1, longestPath.Item2);
                }

                return ab;
            }
        }