// finds the value of a specific move in a column
        // deep is how many moves ahead the alg is looking
        public float FindMoveValue(Board GameBoard, int col, int deep)
        {
            // create temporary Board, make the best move and check for next best
            //Board newBoard = GameBoard.Copy();

            // check if the move will win the game
            //WinState? win = newBoard.CheckWinState();

            WinState?win = GameBoard.CheckWinState();

            // if the game is going to end with the move
            if (win != null)
            {
                // check if it will end with draw
                if (win == WinState.TIE)
                {
                    return(0f);
                }
                // return 1 (best) for win, and -1 (worst) for lose
                //else if (win == WinState.BLACKWIN && Game1.AIColor == BoardState.BLACK)
                else if (win == WinState.BLACKWIN)// && GameBoard.CurrentPlayer == TypeToken.TOKEN_BLACK)
                {
                    return(-1f);
                }
                //else if (win == WinState.REDWIN && Game1.AIColor == BoardState.RED)
                else if (win == WinState.REDWIN)// && GameBoard.CurrentPlayer == TypeToken.TOKEN_RED)
                {
                    return(1f);
                }
                else
                {
                    return(-1f);
                }
            }

            // if we have looked forward the maximum amount
            // return the value of the move
            if (deep == DEEPNESS)
            {
                // MCScore
                //int newStrength = Convert.ToInt32(Strength / ((double)Math.Pow(7, DEEPNESS)));
                //alg.SetStrength(newStrength);
                alg.SetStrength(5);

                return(alg.FindDeepValue(GameBoard, col));
            }

            //newBoard.MakeMove(col);
            GameBoard.MakeMove(col);

            // Get the possible moves for the newBoard (the next move would be players)
            List <int> possibleMoves = GameBoard.GetPossibleMoves(); //newBoard.GetPossibleMoves();

            // start looking into deeper moves
            float value = float.MinValue;

            foreach (int col2 in possibleMoves)
            {
                value = Math.Max(value, -1f * FindMoveValue(GameBoard, col2, deep + 1));
            }

            // remove the last move made so it doesnt stay permanent
            GameBoard.Unmove(col);

            return(value);
        }
Exemple #2
0
        // finds the value of a specific move in a column
        // deep is how many moves ahead the alg is looking
        public float FindMoveValue(Board GameBoard, int col, int deep)
        {
            // create temporary Board, make the best move and check for next best
            //Board newBoard = GameBoard.Copy();

            // check if the move will win the game
            //WinState? win = newBoard.CheckWinState();

            WinState? win = GameBoard.CheckWinState();

            // if the game is going to end with the move
            if (win != null)
            {
                // check if it will end with draw
                if (win == WinState.TIE)
                    return 0f;
                // return 1 (best) for win, and -1 (worst) for lose
                //else if (win == WinState.BLACKWIN && Game1.AIColor == BoardState.BLACK)
                else if (win == WinState.BLACKWIN)// && GameBoard.CurrentPlayer == TypeToken.TOKEN_BLACK)
                    return -1f;
                //else if (win == WinState.REDWIN && Game1.AIColor == BoardState.RED)
                else if (win == WinState.REDWIN)// && GameBoard.CurrentPlayer == TypeToken.TOKEN_RED)
                    return 1f;
                else
                    return -1f;
            }

            // if we have looked forward the maximum amount
            // return the value of the move
            if (deep == DEEPNESS)
            {
                // MCScore
                //int newStrength = Convert.ToInt32(Strength / ((double)Math.Pow(7, DEEPNESS)));
                //alg.SetStrength(newStrength);
                alg.SetStrength(5);

                return alg.FindDeepValue(GameBoard, col);
            }

            //newBoard.MakeMove(col);
            GameBoard.MakeMove(col);

            // Get the possible moves for the newBoard (the next move would be players)
            List<int> possibleMoves = GameBoard.GetPossibleMoves(); //newBoard.GetPossibleMoves();

            // start looking into deeper moves
            float value = float.MinValue;
            foreach (int col2 in possibleMoves)
                value = Math.Max(value, -1f * FindMoveValue(GameBoard, col2, deep + 1));

            // remove the last move made so it doesnt stay permanent
            GameBoard.Unmove(col);

            return value;
        }