Beispiel #1
0
        private Tuple <int, int> AlphaBetaSearch(Game.Game gameStatus, Tuple <int, int> alpha, Tuple <int, int> beta, int algDepth)
        {
            if (algDepth == 0 || gameStatus.gameBoard.resolved)
            {
                return(Tuple.Create(EvalFunc(gameStatus), -1));
            }

            if (gameStatus.activePlayer == 1)
            {
                Tuple <int, int> ans = Tuple.Create(-1000, -1);
                for (int i = 0; i < gameStatus.currPossibleMoves.Count; i++)
                {
                    Game.Game        newStatus = gameStatus.GenSuccesor(gameStatus.currPossibleMoves[i]);
                    Tuple <int, int> res       = Tuple.Create(AlphaBetaSearch(newStatus, alpha, beta, algDepth - 1).Item1, i);
                    ans = res.Item1 > ans.Item1 ? res : ans;

                    alpha = alpha.Item1 > ans.Item1 ? alpha : ans;
                    if (alpha.Item1 >= beta.Item1)
                    {
                        break;
                    }
                }

                return(alpha);
            }
            else
            {
                Tuple <int, int> ans = Tuple.Create(1000, -1);
                for (int i = 0; i < gameStatus.currPossibleMoves.Count; i++)
                {
                    Game.Game        newStatus = gameStatus.GenSuccesor(gameStatus.currPossibleMoves[i]);
                    Tuple <int, int> res       = Tuple.Create(AlphaBetaSearch(newStatus, alpha, beta, algDepth - 1).Item1, i);
                    ans = res.Item1 < ans.Item1 ? res : ans;

                    beta = beta.Item1 < ans.Item1 ? beta : ans;
                    if (alpha.Item1 >= beta.Item1)
                    {
                        break;
                    }
                }

                return(beta);
            }
        }