コード例 #1
0
ファイル: IA.cs プロジェクト: Meik0n/IATest-Unity
    public float GetUtility(RBYAction lastAction, RBYAction action)
    {
        float utility = 0;

        if (lastAction == RBYAction.Red && action == RBYAction.Red)
        {
            utility--;
        }
        else if (lastAction == RBYAction.Red && action == RBYAction.Blue ||
                 lastAction == RBYAction.Red && action == RBYAction.Yellow)
        {
            utility++;
        }
        else if (lastAction == RBYAction.Blue && action == RBYAction.Blue)
        {
            utility--;
        }
        else if (lastAction == RBYAction.Blue && action == RBYAction.Red ||
                 lastAction == RBYAction.Blue && action == RBYAction.Yellow)
        {
            utility++;
        }
        else if (lastAction == RBYAction.Yellow && action == RBYAction.Yellow)
        {
            utility--;
        }
        else if (lastAction == RBYAction.Yellow && action == RBYAction.Red ||
                 lastAction == RBYAction.Yellow && action == RBYAction.Blue)
        {
            utility++;
        }

        return(utility);
    }
コード例 #2
0
ファイル: IA.cs プロジェクト: Meik0n/IATest-Unity
    private RBYAction GetNextActionUCB1()
    {
        int   i, best;
        float bestScore;
        float tempScore;

        for (i = 0; i < numActions; i++)
        {
            //spawneo inicial aleatorio
            if (count[i] == 0)
            {
                int r = Random.Range(0, 4);
                lastAction = (RBYAction)r;
                return(lastAction);
            }
        }

        //aplica UCB1
        best      = -1;
        bestScore = int.MinValue;
        for (i = 0; i < numActions; i++)
        {
            tempScore     = UCB1(score[i] / count[i], count[i], totalActions);
            UCB1scores[i] = tempScore;
            if (tempScore > bestScore)
            {
                best      = i;
                bestScore = tempScore;
            }
        }
        lastAction = (RBYAction)best;
        return(lastAction);
    }
コード例 #3
0
ファイル: IA.cs プロジェクト: Meik0n/IATest-Unity
    public void TellOponentActionUCB1(RBYAction action)
    {
        totalActions++;
        float utility;

        utility = GetUtility(lastAction, action);
        score[(int)lastAction] += utility;
        count[(int)lastAction]++;
    }
コード例 #4
0
ファイル: GameController.cs プロジェクト: Meik0n/IATest-Unity
    public void PlayerPlay(int action)
    {
        RBYAction iaAction = ia.Play();

        if (ia.GetUtility(iaAction, (RBYAction)action) == 1)
        {
            scoreIA++;
        }
        else if (ia.GetUtility(iaAction, (RBYAction)action) == -1)
        {
            scorePlayer++;
        }
        ia.TellOponentActionUCB1((RBYAction)action);
    }