How to do it...

We will implement the following steps in the same Bandit class we created before.

  1. Define the required member variables:
float initialRegret = 10f;float[] regret;float[] chance;RPSAction lastOpponentAction;RPSAction[] lastActionRM;
  1. Define the member function for initialization:
public void InitRegretMatching(){  if (init)    return;  // next steps}
  1. Declare the local variables and initialize them:
numActions = System.Enum.GetNames(typeof(RPSAction)).Length;regret = new float[numActions];chance = new float[numActions];int i;for (i = 0; i < numActions; i++){  regret[i] = initialRegret;  chance[i] = 0f;}init = true;
  1. Define the member function for computing the next action to be taken:
public RPSAction GetNextActionRM(){ // next ...

Get Unity 2018 Artificial Intelligence Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.