yojimbos_law

battlefield hypothesis checker

Nov 12th, 2018
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.65 KB | None | 0 0
  1. //simulator used:
  2.  
  3. boolean olfacted = false;
  4. int[int] buffer_queue;
  5. //start with empty queue
  6. buffer_queue[1] = -1;
  7. buffer_queue[2] = -1;
  8. buffer_queue[3] = -1;
  9. buffer_queue[4] = -1;
  10. buffer_queue[5] = -1;
  11.  
  12.  
  13. //compute sum of distribution outside of function for efficiency.
  14. int select(int[int] copy_distribution, int distribution_sum){
  15. int selection = -1;
  16. int pre_selection = -1;
  17. boolean in_queue;
  18. int rejection_roll = 4;
  19.  
  20. //this iterates until we pass a 3/4 rejection roll.
  21. while(selection == -1){
  22. //roll a random number between 0 and [total number of copies] - 1 inclusive, shift to range [1,total]
  23. pre_selection = random(distribution_sum) + 1;
  24. //discern which monster that roll corresponds to.
  25. foreach i in copy_distribution{
  26. //decrement roll by the number of copies corresponding to monster i.
  27. pre_selection -= copy_distribution[i];
  28. //the monster that exhausts this quantity is the one we rolled.
  29. if(pre_selection <= 0){
  30. selection = i;
  31. break;
  32. }
  33. }
  34.  
  35. //now we check if the monster is in the queue.
  36. in_queue = false;
  37. for i from 1 to 5{
  38. if(selection == buffer_queue[i]){
  39. in_queue = true;
  40. }
  41. }
  42.  
  43. //if it is, we apply the typical 3/4 rejection rate.
  44. if(in_queue){
  45. rejection_roll = random(4);
  46. //if the roll isn't 1, we reject it and start over.
  47. if(rejection_roll != 1){
  48. selection = -1;
  49. }
  50. }
  51. }
  52.  
  53.  
  54. //shift queue left.
  55. for i from 2 to 5 {
  56. buffer_queue[i-1] = buffer_queue[i];
  57. }
  58.  
  59. //put selection in rightmost queue slot.
  60. buffer_queue[5] = selection;
  61.  
  62. return selection;
  63. }
  64.  
  65.  
  66. int trials = 100000;
  67. float average;
  68. float sexually_transmitted_disease;
  69.  
  70.  
  71. int[int] monster_counter;
  72. int[int] copies;
  73.  
  74. /*
  75. null hypothesis for battlefield at 0 kills:
  76. 3
  77. 2
  78. 2
  79. 3
  80. 3
  81. 2
  82. */
  83.  
  84. copies[1] = 3;
  85. copies[2] = 2;
  86. copies[3] = 2;
  87. copies[4] = 3;
  88. copies[5] = 3;
  89. copies[6] = 2;
  90.  
  91.  
  92.  
  93. int total_copies = 0;
  94. foreach i in copies{
  95. total_copies += copies[i];
  96. }
  97.  
  98. int resultant;
  99. for i from 1 to trials{
  100. //print(i+": "+select(copies,total_copies));
  101. resultant = select(copies,total_copies);
  102. monster_counter[resultant]++;
  103. if(i%(trials/100) == 0){
  104. print(i+": "+resultant);
  105. }
  106. }
  107.  
  108. print("results for "+trials+" trials:");
  109. foreach i in monster_counter{
  110. print("monster"+i+" ("+copies[i]+" copies): "+monster_counter[i]);
  111. }
  112.  
  113. =================================================================================================================
  114.  
  115. //simulation output:
  116.  
  117. > run battlefield test.ash
  118.  
  119. 1000: 2
  120. 2000: 5
  121. 3000: 3
  122. 4000: 3
  123. 5000: 5
  124. 6000: 4
  125. 7000: 5
  126. 8000: 4
  127. 9000: 6
  128. 10000: 2
  129. 11000: 3
  130. 12000: 1
  131. 13000: 2
  132. 14000: 1
  133. 15000: 6
  134. 16000: 1
  135. 17000: 4
  136. 18000: 2
  137. 19000: 3
  138. 20000: 2
  139. 21000: 5
  140. 22000: 3
  141. 23000: 1
  142. 24000: 1
  143. 25000: 4
  144. 26000: 4
  145. 27000: 2
  146. 28000: 6
  147. 29000: 2
  148. 30000: 3
  149. 31000: 5
  150. 32000: 3
  151. 33000: 1
  152. 34000: 2
  153. 35000: 6
  154. 36000: 4
  155. 37000: 5
  156. 38000: 6
  157. 39000: 2
  158. 40000: 1
  159. 41000: 6
  160. 42000: 1
  161. 43000: 1
  162. 44000: 2
  163. 45000: 2
  164. 46000: 3
  165. 47000: 6
  166. 48000: 1
  167. 49000: 4
  168. 50000: 4
  169. 51000: 6
  170. 52000: 3
  171. 53000: 4
  172. 54000: 6
  173. 55000: 2
  174. 56000: 3
  175. 57000: 1
  176. 58000: 2
  177. 59000: 6
  178. 60000: 5
  179. 61000: 6
  180. 62000: 4
  181. 63000: 4
  182. 64000: 6
  183. 65000: 2
  184. 66000: 4
  185. 67000: 5
  186. 68000: 5
  187. 69000: 4
  188. 70000: 1
  189. 71000: 5
  190. 72000: 3
  191. 73000: 3
  192. 74000: 2
  193. 75000: 3
  194. 76000: 5
  195. 77000: 1
  196. 78000: 1
  197. 79000: 2
  198. 80000: 2
  199. 81000: 3
  200. 82000: 1
  201. 83000: 2
  202. 84000: 6
  203. 85000: 4
  204. 86000: 1
  205. 87000: 5
  206. 88000: 2
  207. 89000: 1
  208. 90000: 2
  209. 91000: 2
  210. 92000: 3
  211. 93000: 5
  212. 94000: 5
  213. 95000: 6
  214. 96000: 4
  215. 97000: 6
  216. 98000: 3
  217. 99000: 6
  218. 100000: 5
  219. results for 100000 trials:
  220. monster1 (3 copies): 18394
  221. monster2 (2 copies): 14821
  222. monster3 (2 copies): 14854
  223. monster4 (3 copies): 18613
  224. monster5 (3 copies): 18483
  225. monster6 (2 copies): 14835
Advertisement
Add Comment
Please, Sign In to add comment