Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //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.
- int[int] value_count;
- int[int] buffer_queue;
- boolean is_in_queue(int query, int queue_memory) {
- for i from 1 to queue_memory {
- if(query == buffer_queue[i]){
- //we found query in queue slot i.
- return true;
- }
- }
- return false;
- }
- void select(int unique_entities, int queue_memory, int rejection_threshold, int q, int epsilon){
- int selection = -1;
- int max_unique_entities = unique_entities -1;
- //assume everything is in the queue.
- boolean is_everything_in_queue = true;
- int rejection_roll = q;
- if(unique_entities > queue_memory){
- //in this case, we can't have everything in the queue, so
- is_everything_in_queue = false;
- } else if (is_everything_in_queue) {
- //now we have to actually check each thing.
- for j from 0 to max_unique_entities {
- //only do the following until we find something outside the queue.
- // update our understanding of whether the queue is full based on our knowledge of j.
- is_everything_in_queue = is_in_queue(j, queue_memory);
- if (!is_everything_in_queue) {
- break;
- }
- }
- }
- while(selection == -1){
- //pick a random encounter.
- selection = random(unique_entities+epsilon);
- //account for extra copies corresponding to max_unique_entities.
- selection = selection > max_unique_entities ? max_unique_entities : selection;
- //in_queue is now true if selection is in queue.
- boolean is_in_queue = is_in_queue(selection, queue_memory);
- //apply rejection if the selection is in queue and the queue isn't full.
- if(is_in_queue && !is_everything_in_queue ){
- rejection_roll = random(q);
- //if the rejection roll is below threshold,
- if(rejection_roll < rejection_threshold){
- //get rid of selection.
- selection = -1;
- }
- }
- }
- for i from 2 to queue_memory {
- buffer_queue[i-1] = buffer_queue[i];
- }
- value_count[selection]++;
- buffer_queue[queue_memory] = selection;
- }
Add Comment
Please, Sign In to add comment