示例#1
0
    public void calcNextMove(int player, GameBoardData gameBoard)
    {
        //Get valid turns and then choose one randomly
        List <int> validTurns = gameBoard.getValidTurns();

        turn = Random.Range(0, validTurns.Count - 1);
    }
示例#2
0
    public void calcNextMove(int player, GameBoardData gameBoard)
    {
        countRatings = 0;

        board      = gameBoard;
        validTurns = board.getValidTurns();

        turnHighestRating = validTurns [0];
        highestRating     = int.MinValue;

        for (int i = 0; i < validTurns.Count; i++)
        {
            DeepSearch deepSearch = new DeepSearch(board, validTurns[i], deep, playerMe, playerMe, int.MinValue, int.MaxValue);
            deepSearch.setAiListener(this);
            deepSearch.Start();
        }
    }
    private int getRating()
    {
        board.insert(insertPosition, playersTurn);
        deep--;

        //Fist check for winner or draw
        int winner = board.calculateWinner(board);

        if (winner == playerMe)
        {
            //Debug.Log ("Me winner");
            return(int.MaxValue);
        }
        else if (winner == GameManager.DRAW)
        {
            //Debug.Log ("Draw");
            return(0);
        }
        else if (winner != GameManager.NONE)
        {
            //enemy wins
            //Debug.Log("enemy winner");
            return(int.MinValue);
        }

        if (deep > 0)
        {
            int newPlayersTurn = playersTurn;

            if (playersTurn == GameManager.FIRSTPLAYER)
            {
                newPlayersTurn = GameManager.SECONDPLAYER;
            }
            else if (playersTurn == GameManager.SECONDPLAYER)
            {
                newPlayersTurn = GameManager.FIRSTPLAYER;
            }

            int        choosenRating = 0;
            List <int> turns         = board.getValidTurns();

            for (int i = 0; i < turns.Count; i++)
            {
                DeepSearch search;

                if (i == 0)
                {
                    search = new DeepSearch(board.clone(), turns[i], deep, newPlayersTurn, playerMe, lowerBound, upperBound);
                }

                if (newPlayersTurn == playerMe)
                {
                    search = new DeepSearch(board.clone(), turns [i], deep, newPlayersTurn, playerMe, choosenRating, upperBound);
                }
                else
                {
                    search = new DeepSearch(board.clone(), turns [i], deep, newPlayersTurn, playerMe, lowerBound, choosenRating);
                }

                int rating = search.getRating();

                if (i == 0)
                {
                    choosenRating = rating;
                }
                else
                {
                    //if this is my move than choose the highest value
                    //if this is not my move than choose the lowest value
                    if (newPlayersTurn == playerMe)
                    {
                        if (rating > choosenRating)
                        {
                            choosenRating = rating;
                            if (choosenRating == int.MaxValue)
                            {
                                //we found one of the best moves now we can exit
                                return(choosenRating);
                            }
                            else if (choosenRating <= lowerBound)
                            {
                                return(lowerBound);
                            }
                        }
                    }
                    else
                    {
                        if (rating < choosenRating)
                        {
                            choosenRating = rating;
                            if (choosenRating == int.MinValue)
                            {
                                //we found one of the best moves now we can exit
                                return(choosenRating);
                            }
                            else if (choosenRating >= upperBound)
                            {
                                return(upperBound);
                            }
                        }
                    }
                }
            }

            return(choosenRating);
        }
        else
        {
            return(calculateRating());
        }
    }