Example #1
0
        public int Evaluate(Board CurGame, int col, int depth)
        {
            State Result = CurGame.TestVictory();

            if (Result != State.empty)
            {
                if (Result == State.draw)
                {
                    return(0);
                }
                return((Result == CurGame.CurPlayer) ? 10000 : -15000);
            }
            // cut deep
            if (depth == MAX_DEEP)
            {
                return(DeapthCut(CurGame, col));
            }
            CurGame.MakeMove(col);
            List <int> movesList = CurGame.GetValidMoves();
            int        alpha     = int.MinValue;

            foreach (int T in movesList)
            {
                alpha = Math.Max(alpha, -1 * Evaluate(CurGame, T, depth + 1));
            }
            CurGame.UnMove(col);
            return(alpha);
        }
Example #2
0
        public int MinValue(Board CurGame, int col, int depth, int alpha, int beta)
        {
            State Result = CurGame.TestVictory();

            if (Result != State.empty)
            {
                if (Result == State.draw)
                {
                    return(0);
                }
                return((Result == playerNumber) ? 10000 : -15000);
            }
            // cut deep
            if (depth == MAX_DEEP)
            {
                return(DeapthCut(CurGame, col));
            }
            CurGame.MakeMove(col);
            List <int> movesList = CurGame.GetValidMoves();

            foreach (int T in movesList)
            {
                beta = Math.Min(beta, MaxValue(CurGame, T, depth + 1, alpha, beta));
                if (beta <= alpha)
                {
                    break;
                }
            }
            CurGame.UnMove(col);
            return(beta);
        }
Example #3
0
        public override int Play(Board CurGame)
        {
            playerNumber = CurGame.CurPlayer;
            List <int> movesList    = CurGame.GetValidMoves();
            int        bestVal      = int.MinValue;
            int        ColumnToPlay = -1;

            foreach (int T in movesList)
            {
                int eval = Evaluate(CurGame, T, 0);
                if (eval > bestVal)
                {
                    bestVal      = eval;
                    ColumnToPlay = T;
                }
            }
            return(ColumnToPlay);
        }