Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //simulator used:
- boolean olfacted = false;
- int[int] buffer_queue;
- //start with empty queue
- buffer_queue[1] = -1;
- buffer_queue[2] = -1;
- buffer_queue[3] = -1;
- buffer_queue[4] = -1;
- buffer_queue[5] = -1;
- //compute sum of distribution outside of function for efficiency.
- int select(int[int] copy_distribution, int distribution_sum){
- int selection = -1;
- int pre_selection = -1;
- boolean in_queue;
- int rejection_roll = 4;
- //this iterates until we pass a 3/4 rejection roll.
- while(selection == -1){
- //roll a random number between 0 and [total number of copies] - 1 inclusive, shift to range [1,total]
- pre_selection = random(distribution_sum) + 1;
- //discern which monster that roll corresponds to.
- foreach i in copy_distribution{
- //decrement roll by the number of copies corresponding to monster i.
- pre_selection -= copy_distribution[i];
- //the monster that exhausts this quantity is the one we rolled.
- if(pre_selection <= 0){
- selection = i;
- break;
- }
- }
- //now we check if the monster is in the queue.
- in_queue = false;
- for i from 1 to 5{
- if(selection == buffer_queue[i]){
- in_queue = true;
- }
- }
- //if it is, we apply the typical 3/4 rejection rate.
- if(in_queue){
- rejection_roll = random(4);
- //if the roll isn't 1, we reject it and start over.
- if(rejection_roll != 1){
- selection = -1;
- }
- }
- }
- //shift queue left.
- for i from 2 to 5 {
- buffer_queue[i-1] = buffer_queue[i];
- }
- //put selection in rightmost queue slot.
- buffer_queue[5] = selection;
- return selection;
- }
- int trials = 100000;
- float average;
- float sexually_transmitted_disease;
- int[int] monster_counter;
- int[int] copies;
- /*
- null hypothesis for battlefield at 0 kills:
- 3
- 2
- 2
- 3
- 3
- 2
- */
- copies[1] = 3;
- copies[2] = 2;
- copies[3] = 2;
- copies[4] = 3;
- copies[5] = 3;
- copies[6] = 2;
- int total_copies = 0;
- foreach i in copies{
- total_copies += copies[i];
- }
- int resultant;
- for i from 1 to trials{
- //print(i+": "+select(copies,total_copies));
- resultant = select(copies,total_copies);
- monster_counter[resultant]++;
- if(i%(trials/100) == 0){
- print(i+": "+resultant);
- }
- }
- print("results for "+trials+" trials:");
- foreach i in monster_counter{
- print("monster"+i+" ("+copies[i]+" copies): "+monster_counter[i]);
- }
- =================================================================================================================
- //simulation output:
- > run battlefield test.ash
- 1000: 2
- 2000: 5
- 3000: 3
- 4000: 3
- 5000: 5
- 6000: 4
- 7000: 5
- 8000: 4
- 9000: 6
- 10000: 2
- 11000: 3
- 12000: 1
- 13000: 2
- 14000: 1
- 15000: 6
- 16000: 1
- 17000: 4
- 18000: 2
- 19000: 3
- 20000: 2
- 21000: 5
- 22000: 3
- 23000: 1
- 24000: 1
- 25000: 4
- 26000: 4
- 27000: 2
- 28000: 6
- 29000: 2
- 30000: 3
- 31000: 5
- 32000: 3
- 33000: 1
- 34000: 2
- 35000: 6
- 36000: 4
- 37000: 5
- 38000: 6
- 39000: 2
- 40000: 1
- 41000: 6
- 42000: 1
- 43000: 1
- 44000: 2
- 45000: 2
- 46000: 3
- 47000: 6
- 48000: 1
- 49000: 4
- 50000: 4
- 51000: 6
- 52000: 3
- 53000: 4
- 54000: 6
- 55000: 2
- 56000: 3
- 57000: 1
- 58000: 2
- 59000: 6
- 60000: 5
- 61000: 6
- 62000: 4
- 63000: 4
- 64000: 6
- 65000: 2
- 66000: 4
- 67000: 5
- 68000: 5
- 69000: 4
- 70000: 1
- 71000: 5
- 72000: 3
- 73000: 3
- 74000: 2
- 75000: 3
- 76000: 5
- 77000: 1
- 78000: 1
- 79000: 2
- 80000: 2
- 81000: 3
- 82000: 1
- 83000: 2
- 84000: 6
- 85000: 4
- 86000: 1
- 87000: 5
- 88000: 2
- 89000: 1
- 90000: 2
- 91000: 2
- 92000: 3
- 93000: 5
- 94000: 5
- 95000: 6
- 96000: 4
- 97000: 6
- 98000: 3
- 99000: 6
- 100000: 5
- results for 100000 trials:
- monster1 (3 copies): 18394
- monster2 (2 copies): 14821
- monster3 (2 copies): 14854
- monster4 (3 copies): 18613
- monster5 (3 copies): 18483
- monster6 (2 copies): 14835
Advertisement
Add Comment
Please, Sign In to add comment