Advertisement
Kaelygon

hit Calculator

Apr 18th, 2024
512
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 KB | None | 0 0
  1. //i'm bad at probabilistics so i brute forced this
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string>
  5. #include <iostream>
  6.  
  7. using namespace std;
  8.  
  9. int main(int ac, char** av){
  10.     srand(0);
  11.  
  12.     uint stHitChance = RAND_MAX*0.4327;
  13.     uint ndhitCahnce = RAND_MAX*0.5880;
  14.  
  15.     uint zeroHit=0;
  16.     uint oneHit =0;
  17.     uint twoHit =0;
  18.     uint count=1000000;
  19.  
  20.     bool lightbearer=1;
  21.  
  22.     for(uint i=0;i<count;i++){
  23.         bool noHit=1;
  24.        
  25.         uint curChance=stHitChance;
  26.  
  27.         uint hitRoll=rand();
  28.         if(hitRoll<curChance){
  29.             curChance=ndhitCahnce;
  30.             oneHit++;
  31.             noHit=0;
  32.         }
  33.  
  34.         if(lightbearer){
  35.             hitRoll=rand();
  36.             if(hitRoll<curChance){
  37.                 oneHit-=curChance==ndhitCahnce;
  38.                 twoHit++;
  39.                 noHit=0;
  40.             }
  41.         }
  42.         if(noHit){
  43.             zeroHit++;
  44.         }
  45.  
  46.     }
  47.     printf("0 hit: %f \n",(double)zeroHit/count);
  48.     printf("1 hit: %f \n",(double)oneHit /count);
  49.     printf("2 hit: %f \n",(double)twoHit /count);
  50.    
  51.  
  52. }
  53.    
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement