Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //this script simulates KoL's encounter selection process a bunch of times to generate queue state and encounter rate data against which one can test hypotheses about new olfacty things.
- int[int] buffer_queue;
- float[int][int][boolean] encounter_rate;
- void select(int n, int copies, boolean rejection_exempt){
- int selection = -1;
- boolean in_queue;
- int rejection_roll;
- while(selection == -1){
- selection = random(n+copies);
- in_queue = false;
- for i from 1 to 5{
- if(selection == buffer_queue[i]){
- in_queue = true;
- }
- }
- if(rejection_exempt){
- if(in_queue && selection < n-1 ){
- rejection_roll = random(4);
- if(rejection_roll < 3){
- selection = -1;
- }
- }
- }
- else{
- if(in_queue){
- rejection_roll = random(4);
- if(rejection_roll < 3){
- selection = -1;
- }
- }
- }
- }
- for i from 2 to 5 {
- buffer_queue[i-1] = buffer_queue[i];
- }
- buffer_queue[5] = selection;
- if(selection >= n-1){
- encounter_rate[n][copies][rejection_exempt] += 1;
- }
- }
- void generate_and_save_some_queue_data(int n, int copies, boolean rejection_exempt){
- //rolls will take values 0,...,n-1
- //queue will remember last 5 rolls.
- //rejection rolls will take values 0,...,3 and will reject selections if less than 3.
- //rejection rate is effectively 3/4
- //seed selection process with uniform distibution queue
- //copies are additional copies added by sniffing effects.
- //rejection_exempt is whether the sniffed monster is made exempt from rejection by sniffing.
- //let's see how long this takes to run
- print("starting simulation with n="+n+" copies="+copies+" rejection="+rejection_exempt.to_string());
- int starting_gun = gametime_to_int();
- for i from 1 to 5{
- buffer_queue[i] = random(n+copies);
- }
- //seed queue with more queueily selected things
- for i from 1 to 25 {
- select(n,copies,rejection_exempt);
- }
- //let's count some queues for some numerical analysis of steady state distributions
- float[string] queue_frequency;
- int progress = 0;
- buffer queuey_string ;
- for i from 1 to 10000000{
- select(n,copies,rejection_exempt);
- queuey_string.set_length(0);
- for j from 1 to 5{
- if(j == 1){
- queuey_string.append(buffer_queue[j].to_string());
- }
- else{
- queuey_string.append(","+buffer_queue[j].to_string());
- }
- }
- queue_frequency[queuey_string.to_string()] += 1;
- if(i%100000 == 0){
- progress++;
- int butts = (gametime_to_int()-starting_gun)/1000;
- print("we're "+i/100000+"/100 done after "+butts+" seconds.");
- }
- }
- foreach i in queue_frequency{
- queue_frequency[i] /= 1000000;
- }
- encounter_rate[n][copies][rejection_exempt] /= 1000000;
- //let's label the file in a way that is good.
- map_to_file(queue_frequency,"olfacty queue data with n="+n+" copies="+copies+" rejection="+rejection_exempt.to_string()+".txt");
- print_html("and we're done");
- }
- //number of copies
- for a from 0 to 4{
- generate_and_save_some_queue_data(8,a,true);
- generate_and_save_some_queue_data(8,a,false);
- }
- map_to_file(encounter_rate, "olfacty encounter rate data.txt");
Advertisement
Add Comment
Please, Sign In to add comment