yojimbos_law

a queue simulator for combat-y quests

Sep 15th, 2018
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.90 KB | None | 0 0
  1. //here's the script:
  2.  
  3. int[int] buffer_queue;
  4. boolean olfacted = false;
  5.  
  6. int select(int n){
  7. int selection = -1;
  8. boolean in_queue;
  9. int rejection_roll = 4;
  10. while(selection == -1){
  11. selection = random(n);
  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(in_queue){
  19. rejection_roll = random(4);
  20. if(rejection_roll == 1){
  21. selection = -1;
  22. }
  23. }
  24. }
  25. for i from 2 to 5 {
  26. buffer_queue[i-1] = buffer_queue[i];
  27. }
  28. buffer_queue[5] = selection;
  29. return selection;
  30. }
  31.  
  32. int select_with_olfaction(int n, int copies, boolean rejecting){
  33. int selection = -1;
  34. boolean in_queue;
  35. int rejection_roll = n+copies+1;
  36. while(selection == -1){
  37. if(olfacted){
  38. selection = min( random(n+copies) , n-1 );
  39. if(selection != n-1 || rejecting){
  40. in_queue = false;
  41. for i from 1 to 5{
  42. if(selection == buffer_queue[i]){
  43. in_queue = true;
  44. }
  45. }
  46. if(in_queue){
  47. rejection_roll = random(4);
  48. if(rejection_roll == 1){
  49. selection = -1;
  50. }
  51. }
  52. }
  53. }
  54. else{
  55. selection = random(n);
  56. in_queue = false;
  57. for i from 1 to 5{
  58. if(selection == buffer_queue[i]){
  59. in_queue = true;
  60. }
  61. }
  62. if(in_queue){
  63. rejection_roll = random(4);
  64. if(rejection_roll == 1){
  65. selection = -1;
  66. }
  67. }
  68. }
  69. }
  70. for i from 2 to 5 {
  71. buffer_queue[i-1] = buffer_queue[i];
  72. }
  73. buffer_queue[5] = selection;
  74. if(selection == n-1){
  75. olfacted = true;
  76. }
  77. return selection;
  78. }
  79.  
  80. int trials = 10000;
  81. int monster_counter;
  82. int monsters_in_place = 10;
  83. int monsters_to_find = 1;
  84. int banishes_available = 2;
  85. int extra_copies = 0;
  86. boolean rejectiness = true;
  87. int[int] trial_combats;
  88. int[int] trial_banishes;
  89. boolean[int] banishes;
  90. float average;
  91. float sexually_transmitted_disease;
  92.  
  93. for a from 2 to 10{
  94. for b from 0 to min(2,a){
  95.  
  96. monsters_in_place = a;
  97. banishes_available = b;
  98. average = 0.0;
  99. sexually_transmitted_disease = 0.0;
  100. clear(trial_combats);
  101. clear(trial_banishes);
  102. for i from 1 to trials{
  103. for j from 1 to monsters_in_place{
  104. banishes[i] = false;
  105. }
  106. trial_banishes[i] = 0;
  107. monster_counter = 0;
  108. for j from 1 to 5{
  109. buffer_queue[j] = -1;
  110. }
  111. olfacted = false;
  112. while( monster_counter < monsters_to_find){
  113. if(monsters_in_place - trial_banishes[i] == 1){
  114. monster_counter++;
  115. }
  116. else{
  117. if( select_with_olfaction( monsters_in_place - trial_banishes[i] , extra_copies , rejectiness) == ( monsters_in_place - trial_banishes[i] ) - 1 ){
  118. monster_counter++;
  119. }
  120. else{
  121. if(trial_banishes[i] < banishes_available){
  122. trial_banishes[i]++;
  123. }
  124. }
  125. }
  126. trial_combats[i]++;
  127. }
  128. }
  129.  
  130. string textiness = "";
  131. if(!rejectiness){
  132. textiness += " and removing rejection";
  133. }
  134. print("with "+banishes_available+" banishes available, and an olfactiony thing adding "+extra_copies+" additional copies"+textiness);
  135. foreach i in trial_combats{
  136. average += trial_combats[i];
  137. }
  138.  
  139. average /= trial_combats.count().to_float();
  140.  
  141. foreach i in trial_combats{
  142. sexually_transmitted_disease += ( trial_combats[i].to_float() - average ) ** 2;
  143. }
  144.  
  145. sexually_transmitted_disease /= trial_combats.count().to_float() - 1.0;
  146. sexually_transmitted_disease = sexually_transmitted_disease ** (0.5);
  147.  
  148. print("we fight an average of "+average+" monsters, give or take "+sexually_transmitted_disease+" monsters");
  149.  
  150.  
  151. average = 0.0;
  152. sexually_transmitted_disease = 0.0;
  153.  
  154. foreach i in trial_banishes{
  155. average += trial_banishes[i];
  156. }
  157.  
  158. average /= trial_banishes.count().to_float();
  159.  
  160. foreach i in trial_banishes{
  161. sexually_transmitted_disease += ( trial_banishes[i].to_float() - average ) ** 2;
  162. }
  163.  
  164. sexually_transmitted_disease /= trial_banishes.count().to_float() - 1.0;
  165. sexually_transmitted_disease = sexually_transmitted_disease ** (0.5);
  166.  
  167. print("with an average of "+average+" banishes, give or take "+sexually_transmitted_disease+" banishes");
  168.  
  169. print("to encounter "+monsters_to_find+" of a monster in a place with "+monsters_in_place+" monsters");
  170. print("=================================");
  171. }
  172. }
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182. =======================================================================================================================
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194. //here's the output:
  195.  
  196. > run queue quest simulator.ash
  197.  
  198. with 0 banishes available, and an olfactiony thing adding 0 additional copies
  199. we fight an average of 1.886 monsters, give or take 1.2143111031138625 monsters
  200. with an average of 0.0 banishes, give or take 0.0 banishes
  201. to encounter 1 of a monster in a place with 2 monsters
  202. =================================
  203. with 1 banishes available, and an olfactiony thing adding 0 additional copies
  204. we fight an average of 1.5016 monsters, give or take 0.5000224417405889 monsters
  205. with an average of 0.5016 banishes, give or take 0.5000224417405889 banishes
  206. to encounter 1 of a monster in a place with 2 monsters
  207. =================================
  208. with 2 banishes available, and an olfactiony thing adding 0 additional copies
  209. we fight an average of 1.4958 monsters, give or take 0.5000073606819214 monsters
  210. with an average of 0.4958 banishes, give or take 0.5000073606819214 banishes
  211. to encounter 1 of a monster in a place with 2 monsters
  212. =================================
  213. with 0 banishes available, and an olfactiony thing adding 0 additional copies
  214. we fight an average of 2.7791 monsters, give or take 2.0476138459792232 monsters
  215. with an average of 0.0 banishes, give or take 0.0 banishes
  216. to encounter 1 of a monster in a place with 3 monsters
  217. =================================
  218. with 1 banishes available, and an olfactiony thing adding 0 additional copies
  219. we fight an average of 2.3095 monsters, give or take 1.4117043036359178 monsters
  220. with an average of 0.6669 banishes, give or take 0.47134552788868295 banishes
  221. to encounter 1 of a monster in a place with 3 monsters
  222. =================================
  223. with 2 banishes available, and an olfactiony thing adding 0 additional copies
  224. we fight an average of 1.9961 monsters, give or take 0.8202146458132532 monsters
  225. with an average of 0.9961 banishes, give or take 0.8202146458132532 banishes
  226. to encounter 1 of a monster in a place with 3 monsters
  227. =================================
  228. with 0 banishes available, and an olfactiony thing adding 0 additional copies
  229. we fight an average of 3.6378 monsters, give or take 2.8845871878528153 monsters
  230. with an average of 0.0 banishes, give or take 0.0 banishes
  231. to encounter 1 of a monster in a place with 4 monsters
  232. =================================
  233. with 1 banishes available, and an olfactiony thing adding 0 additional copies
  234. we fight an average of 3.1157 monsters, give or take 2.265000338334012 monsters
  235. with an average of 0.7388 banishes, give or take 0.43931066386553763 banishes
  236. to encounter 1 of a monster in a place with 4 monsters
  237. =================================
  238. with 2 banishes available, and an olfactiony thing adding 0 additional copies
  239. we fight an average of 2.7364 monsters, give or take 1.6025516706758145 monsters
  240. with an average of 1.2441 banishes, give or take 0.8366511749342944 banishes
  241. to encounter 1 of a monster in a place with 4 monsters
  242. =================================
  243. with 0 banishes available, and an olfactiony thing adding 0 additional copies
  244. we fight an average of 4.506 monsters, give or take 3.7518757518293757 monsters
  245. with an average of 0.0 banishes, give or take 0.0 banishes
  246. to encounter 1 of a monster in a place with 5 monsters
  247. =================================
  248. with 1 banishes available, and an olfactiony thing adding 0 additional copies
  249. we fight an average of 3.9599 monsters, give or take 3.010448184212248 monsters
  250. with an average of 0.7965 banishes, give or take 0.4026213610776342 banishes
  251. to encounter 1 of a monster in a place with 5 monsters
  252. =================================
  253. with 2 banishes available, and an olfactiony thing adding 0 additional copies
  254. we fight an average of 3.4825 monsters, give or take 2.3299434786409177 monsters
  255. with an average of 1.3989 banishes, give or take 0.7992763441184667 banishes
  256. to encounter 1 of a monster in a place with 5 monsters
  257. =================================
  258. with 0 banishes available, and an olfactiony thing adding 0 additional copies
  259. we fight an average of 5.4749 monsters, give or take 4.709138731101486 monsters
  260. with an average of 0.0 banishes, give or take 0.0 banishes
  261. to encounter 1 of a monster in a place with 6 monsters
  262. =================================
  263. with 1 banishes available, and an olfactiony thing adding 0 additional copies
  264. we fight an average of 4.7957 monsters, give or take 3.896957805521442 monsters
  265. with an average of 0.8339 banishes, give or take 0.3721889875644576 banishes
  266. to encounter 1 of a monster in a place with 6 monsters
  267. =================================
  268. with 2 banishes available, and an olfactiony thing adding 0 additional copies
  269. we fight an average of 4.3247 monsters, give or take 3.1749138441525386 monsters
  270. with an average of 1.4921 banishes, give or take 0.7673307433218705 banishes
  271. to encounter 1 of a monster in a place with 6 monsters
  272. =================================
  273. with 0 banishes available, and an olfactiony thing adding 0 additional copies
  274. we fight an average of 6.3065 monsters, give or take 5.527369440456562 monsters
  275. with an average of 0.0 banishes, give or take 0.0 banishes
  276. to encounter 1 of a monster in a place with 7 monsters
  277. =================================
  278. with 1 banishes available, and an olfactiony thing adding 0 additional copies
  279. we fight an average of 5.7137 monsters, give or take 4.745417179597643 monsters
  280. with an average of 0.8612 banishes, give or take 0.34575499222929945 banishes
  281. to encounter 1 of a monster in a place with 7 monsters
  282. =================================
  283. with 2 banishes available, and an olfactiony thing adding 0 additional copies
  284. we fight an average of 5.1557 monsters, give or take 3.963032686315772 monsters
  285. with an average of 1.5776 banishes, give or take 0.7227935272595675 banishes
  286. to encounter 1 of a monster in a place with 7 monsters
  287. =================================
  288. with 0 banishes available, and an olfactiony thing adding 0 additional copies
  289. we fight an average of 7.3707 monsters, give or take 6.50160815497713 monsters
  290. with an average of 0.0 banishes, give or take 0.0 banishes
  291. to encounter 1 of a monster in a place with 8 monsters
  292. =================================
  293. with 1 banishes available, and an olfactiony thing adding 0 additional copies
  294. we fight an average of 6.4322 monsters, give or take 5.463770533143205 monsters
  295. with an average of 0.872 banishes, give or take 0.33410651402851016 banishes
  296. to encounter 1 of a monster in a place with 8 monsters
  297. =================================
  298. with 2 banishes available, and an olfactiony thing adding 0 additional copies
  299. we fight an average of 5.9248 monsters, give or take 4.787362201012619 monsters
  300. with an average of 1.6201 banishes, give or take 0.7000178515575809 banishes
  301. to encounter 1 of a monster in a place with 8 monsters
  302. =================================
  303. with 0 banishes available, and an olfactiony thing adding 0 additional copies
  304. we fight an average of 8.2587 monsters, give or take 7.441808406646514 monsters
  305. with an average of 0.0 banishes, give or take 0.0 banishes
  306. to encounter 1 of a monster in a place with 9 monsters
  307. =================================
  308. with 1 banishes available, and an olfactiony thing adding 0 additional copies
  309. we fight an average of 7.5795 monsters, give or take 6.652405970813946 monsters
  310. with an average of 0.8881 banishes, give or take 0.3152591455182519 banishes
  311. to encounter 1 of a monster in a place with 9 monsters
  312. =================================
  313. with 2 banishes available, and an olfactiony thing adding 0 additional copies
  314. we fight an average of 6.8332 monsters, give or take 5.806767570254704 monsters
  315. with an average of 1.6589 banishes, give or take 0.6764588307169813 banishes
  316. to encounter 1 of a monster in a place with 9 monsters
  317. =================================
  318. with 0 banishes available, and an olfactiony thing adding 0 additional copies
  319. we fight an average of 9.2137 monsters, give or take 8.480767928228246 monsters
  320. with an average of 0.0 banishes, give or take 0.0 banishes
  321. to encounter 1 of a monster in a place with 10 monsters
  322. =================================
  323. with 1 banishes available, and an olfactiony thing adding 0 additional copies
  324. we fight an average of 8.501 monsters, give or take 7.681946382917871 monsters
  325. with an average of 0.8993 banishes, give or take 0.30094611952424577 banishes
  326. to encounter 1 of a monster in a place with 10 monsters
  327. =================================
  328. with 2 banishes available, and an olfactiony thing adding 0 additional copies
  329. we fight an average of 7.6424 monsters, give or take 6.556067452524079 monsters
  330. with an average of 1.6953 banishes, give or take 0.6424166715753709 banishes
  331. to encounter 1 of a monster in a place with 10 monsters
  332. =================================
Advertisement
Add Comment
Please, Sign In to add comment