Advertisement
Guest User

Untitled

a guest
Oct 18th, 2020
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. Node* Selection()
  2. {
  3.     Node* temp = root;
  4.     selectedCount = 0;
  5.     while (true)
  6.     {
  7.         selectedNodes[selectedCount++] = temp;
  8.  
  9.         int status = temp->status;
  10.  
  11.         if (status < 2)
  12.             return temp;
  13.  
  14.         int childIndex = temp->childIndex;
  15.  
  16.         if (childIndex == 0)
  17.             return temp;
  18.  
  19.         Node* children = nodes + childIndex;
  20.  
  21.         if (temp->childMax == 1)
  22.         {
  23.             temp = children;
  24.             continue;
  25.         }
  26.  
  27.         float visits = temp->visits;
  28.  
  29.         float sqrtLogVisits = EXPLORATION * fastlogf(fastsqrtf(visits));
  30.         int bestIndex = -1;
  31.         float bestScore = MINUS_INFINITY;
  32.  
  33.         for (int i = 0; i < temp->childMax; i++)
  34.         {
  35.             Node& child = children[i];
  36.             if (child.status != 2)
  37.                 continue;
  38.             float score = child.UCT(sqrtLogVisits);
  39.             if (score > bestScore)
  40.             {
  41.                 bestIndex = i;
  42.                 bestScore = score;
  43.             }
  44.         }
  45.  
  46.         temp = children + bestIndex;
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement