Advertisement
FractalFusion

blackjack-related code

Feb 17th, 2019
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.51 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdint.h>
  3. #include <cmath>
  4. #include <string>
  5. #include <iostream>
  6. #include <fstream>
  7. #include <iomanip>
  8.  
  9. #define FILL << std::setw(5) <<
  10. #define FILL2 << std::setw(2) <<
  11.  
  12. #define SPC << " " <<
  13.  
  14. const int SIZE=20000;
  15.  
  16. int main()
  17. {
  18.    
  19.     std::ofstream fi ("blackjack.txt", std::ofstream::out);
  20.    
  21.     uint16_t rng, rng2=0x3ff;
  22.     int ub, lb;
  23.     int array[52];
  24.     int blackjack[SIZE];
  25.     int bjnextindex[SIZE];
  26.     uint16_t bjrng[SIZE];
  27.     int bjrep[SIZE];
  28.     int bjcount=0;
  29.     int bit;
  30.    
  31.     //int index=0;
  32.    
  33.     for(int index=0;index<=SIZE;index++)
  34.     {
  35.         rng=rng2; //rng2 is starting rng
  36.        
  37.         //setup array
  38.         for(int i=0;i<=51;i++) array[i]=51-i;
  39.        
  40.         int shuffle=0, repeats=0, pos;
  41.        
  42.         //shuffle by performing 52 swaps
  43.         while(1)
  44.         {
  45.             //cycle rng 6 times
  46.             for(int i=0;i<6;i++) {bit=(rng^(rng>>2)^(rng>>11)^(rng>>15))&1; rng=(rng<<1)+bit;}
  47.             pos=rng%64;
  48.             if(pos>=52) { repeats++; continue;} //if >=52, repeat; otherwise swap position shuffle and pos
  49.             std::swap(array[pos],array[shuffle]);
  50.             shuffle++;
  51.             if(shuffle>=52) break;
  52.         }
  53.        
  54.         //check for blackjack
  55.         //array[1] and array[3] must be A and KQJT in either order
  56.         //array[0] and array[2] must not be blackjack
  57.         //A: <=3    ten-card: >=36
  58.        
  59.         if((array[1]<=3 && array[3]>=36) || (array[1]>=36 && array[3]<=3))
  60.             if( !((array[0]<=3 && array[2]>=36) || (array[0]>=36 && array[2]<=3)) )
  61.             {
  62.                 //blackjack
  63.                 //fi << std::dec << std::setfill('0') << std::setw(5) << index << " "
  64.                 //   << std::hex << std::uppercase << std::setfill('0') << std::setw(4) << rng2 << " "
  65.                 //   << std::dec << 390+6*repeats << " " << 390+6*repeats+index << "\n";
  66.                
  67.                
  68.                 blackjack[bjcount]=index;
  69.                 bjnextindex[bjcount]=390+6*repeats+index;
  70.                 bjrng[bjcount]=rng2;
  71.                 bjcount++;
  72.                
  73.                
  74.                 /*
  75.                 for(int i=0;i<=51;i++)
  76.                     fi << std::hex << array[i] << " ";
  77.                 fi << "\n";
  78.                 */
  79.             }
  80.            
  81.        
  82.         //check next rng2
  83.         bit=(rng2^(rng2>>2)^(rng2>>11)^(rng2>>15))&1;
  84.         rng2=(rng2<<1)+bit;
  85.        
  86.     }
  87.    
  88.     //run over blackjacks to find next delay
  89.     for(int i=0;i<bjcount;i++)
  90.     {
  91.         int j=i;
  92.        
  93.         do
  94.         {
  95.             j++;
  96.         } while(j<bjcount-1 && blackjack[j]<bjnextindex[i]);
  97.        
  98.         fi << std::dec << std::setfill('0') << std::setw(5) << blackjack[i] << " "
  99.            << std::hex << std::uppercase << std::setfill('0') << std::setw(4) << bjrng[i] << " "
  100.            << std::dec << bjnextindex[i] << " " << blackjack[j] << " " << blackjack[j]-bjnextindex[i] << "\n";
  101.  
  102.  
  103.     }
  104.    
  105.    
  106.     fi.close();
  107.    
  108.     printf("Done!");
  109.     getchar();
  110.     return 0;
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement