yojimbos_law

sniff effectiveness/type spading script

Mar 25th, 2018
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.04 KB | None | 0 0
  1. //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.
  2.  
  3. int[int] buffer_queue;
  4. float[int][int][boolean] encounter_rate;
  5.  
  6. void select(int n, int copies, boolean rejection_exempt){
  7. int selection = -1;
  8. boolean in_queue;
  9. int rejection_roll;
  10. while(selection == -1){
  11. selection = random(n+copies);
  12. in_queue = false;
  13. for i from 1 to 5{
  14. if(selection == buffer_queue[i]){
  15. in_queue = true;
  16. }
  17. }
  18. if(rejection_exempt){
  19. if(in_queue && selection < n-1 ){
  20. rejection_roll = random(4);
  21. if(rejection_roll < 3){
  22. selection = -1;
  23. }
  24. }
  25. }
  26. else{
  27. if(in_queue){
  28. rejection_roll = random(4);
  29. if(rejection_roll < 3){
  30. selection = -1;
  31. }
  32. }
  33. }
  34. }
  35. for i from 2 to 5 {
  36. buffer_queue[i-1] = buffer_queue[i];
  37. }
  38. buffer_queue[5] = selection;
  39. if(selection >= n-1){
  40. encounter_rate[n][copies][rejection_exempt] += 1;
  41. }
  42. }
  43.  
  44.  
  45. void generate_and_save_some_queue_data(int n, int copies, boolean rejection_exempt){
  46. //rolls will take values 0,...,n-1
  47. //queue will remember last 5 rolls.
  48. //rejection rolls will take values 0,...,3 and will reject selections if less than 3.
  49. //rejection rate is effectively 3/4
  50. //seed selection process with uniform distibution queue
  51. //copies are additional copies added by sniffing effects.
  52. //rejection_exempt is whether the sniffed monster is made exempt from rejection by sniffing.
  53. //let's see how long this takes to run
  54. print("starting simulation with n="+n+" copies="+copies+" rejection="+rejection_exempt.to_string());
  55. int starting_gun = gametime_to_int();
  56. for i from 1 to 5{
  57. buffer_queue[i] = random(n+copies);
  58. }
  59.  
  60. //seed queue with more queueily selected things
  61. for i from 1 to 25 {
  62. select(n,copies,rejection_exempt);
  63. }
  64. //let's count some queues for some numerical analysis of steady state distributions
  65. float[string] queue_frequency;
  66. int progress = 0;
  67. buffer queuey_string ;
  68. for i from 1 to 10000000{
  69. select(n,copies,rejection_exempt);
  70. queuey_string.set_length(0);
  71. for j from 1 to 5{
  72. if(j == 1){
  73. queuey_string.append(buffer_queue[j].to_string());
  74. }
  75. else{
  76. queuey_string.append(","+buffer_queue[j].to_string());
  77. }
  78. }
  79. queue_frequency[queuey_string.to_string()] += 1;
  80. if(i%100000 == 0){
  81. progress++;
  82. int butts = (gametime_to_int()-starting_gun)/1000;
  83. print("we're "+i/100000+"/100 done after "+butts+" seconds.");
  84. }
  85. }
  86. foreach i in queue_frequency{
  87. queue_frequency[i] /= 1000000;
  88. }
  89. encounter_rate[n][copies][rejection_exempt] /= 1000000;
  90.  
  91. //let's label the file in a way that is good.
  92. map_to_file(queue_frequency,"olfacty queue data with n="+n+" copies="+copies+" rejection="+rejection_exempt.to_string()+".txt");
  93.  
  94. print_html("and we're done");
  95. }
  96. //number of copies
  97. for a from 0 to 4{
  98. generate_and_save_some_queue_data(8,a,true);
  99. generate_and_save_some_queue_data(8,a,false);
  100. }
  101. map_to_file(encounter_rate, "olfacty encounter rate data.txt");
Advertisement
Add Comment
Please, Sign In to add comment