Ejemplo n.º 1
0
    public int GetAction(Board board, float temp = 1e-3f)
    {
        if (board.GetAvailableMoves().Count > 0)
        {
            List <ActionP> actsProbs = mcts.GetMoveProbs(board, temp);
            mcts.UpdateWithMove(-1);

            float sumP = 0;
            foreach (ActionP actionP in actsProbs)
            {
                sumP += actionP.P;
            }
            float random   = Random.Range(0, sumP);
            float currentP = 0;
            foreach (ActionP actionP in actsProbs)
            {
                currentP += actionP.P;
                if (random <= currentP)
                {
                    return(actionP.action);
                }
            }
            return(actsProbs[actsProbs.Count - 1].action);
        }
        else
        {
            throw new System.Exception("AI没有位置可以走了!");
        }
    }