Aenimus

Slaw stuff

Feb 18th, 2022 (edited)
486
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.10 KB | None | 0 0
  1. //script simulates encounter selection with a range of user-specified values for # of encounters, length of queue, and rejection rate and records the distribution of queue states for 10m trials with each set of parameters.
  2.  
  3.  
  4. int[int] value_count;
  5.  
  6. int[int] buffer_queue;
  7.  
  8. boolean is_in_queue(int query, int queue_memory) {
  9.     for i from 1 to queue_memory {
  10.         if(query == buffer_queue[i]){
  11.             //we found query in queue slot i.
  12.             return true;
  13.         }
  14.     }
  15.     return false;
  16. }
  17.  
  18. void select(int unique_entities, int queue_memory, int rejection_threshold, int q, int epsilon){
  19.     int selection = -1;
  20.     int max_unique_entities = unique_entities -1;
  21.     //assume everything is in the queue.
  22.     boolean is_everything_in_queue = true;
  23.     int rejection_roll = q;
  24.  
  25.     if(unique_entities > queue_memory){
  26.         //in this case, we can't have everything in the queue, so
  27.         is_everything_in_queue = false;
  28.     } else if (is_everything_in_queue) {
  29.         //now we have to actually check each thing.
  30.         for j from 0 to max_unique_entities {
  31.             //only do the following until we find something outside the queue.
  32.             // update our understanding of whether the queue is full based on our knowledge of j.
  33.             is_everything_in_queue = is_in_queue(j, queue_memory);
  34.  
  35.             if (!is_everything_in_queue) {
  36.                 break;
  37.             }
  38.         }
  39.     }
  40.        
  41.     while(selection == -1){
  42.         //pick a random encounter.
  43.         selection = random(unique_entities+epsilon);
  44.         //account for extra copies corresponding to max_unique_entities.
  45.         selection = selection > max_unique_entities ? max_unique_entities : selection;
  46.  
  47.         //in_queue is now true if selection is in queue.
  48.         boolean is_in_queue = is_in_queue(selection, queue_memory);
  49.        
  50.         //apply rejection if the selection is in queue and the queue isn't full.
  51.         if(is_in_queue && !is_everything_in_queue ){
  52.             rejection_roll = random(q);
  53.             //if the rejection roll is below threshold,
  54.             if(rejection_roll < rejection_threshold){
  55.                 //get rid of selection.
  56.                 selection = -1;
  57.             }
  58.         }
  59.     }
  60.    
  61.     for i from 2 to queue_memory {
  62.         buffer_queue[i-1] = buffer_queue[i];
  63.     }
  64.     value_count[selection]++;
  65.     buffer_queue[queue_memory] = selection;
  66. }
Add Comment
Please, Sign In to add comment