Advertisement
xth

W[0] equals W[0] equals ...

xth
May 13th, 2019
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.90 KB | None | 0 0
  1. // 64 bit uint used as 8x8 gameboard bitmap
  2. // what am i doing with my life
  3. #include <stdio.h>
  4. #include <stdint.h>
  5. // #define UINT64_C(c) c ## ULL
  6.  
  7. uint64_t  W[4] = {1,1,1,1}, B[4] = {1,1,1,1}, WhiteSet,BlackSet,CollisionSet;
  8. /* 0  0  0  0  0  0  0  0      
  9.    0  0  0  0  0  0  0  0      
  10.    0  0  0  0  0  0  0  0      
  11.    0  0  0  0  0  0  0  0      
  12.    0  0  0  0  0  0  0  0      
  13.    0  0  0  0  0  0  0  0      
  14.    0  0  0  0  0  0  0  0      
  15.    0  0  0  0  0  0  0  1 */
  16.  
  17. // return 1 if success
  18. int lshift_white(uint64_t selected_piece, unsigned int shift_amount)
  19. {
  20.         if (!((CollisionSet ^ ((selected_piece) << shift_amount)) == CollisionSet)) {
  21.                 WhiteSet = WhiteSet ^ (selected_piece);
  22.                 selected_piece = (selected_piece) << shift_amount;
  23.                 WhiteSet = WhiteSet & (selected_piece);
  24.                 CollisionSet = WhiteSet & BlackSet;
  25.                 return 1;
  26.         } else {
  27.                 return 0;
  28.         }
  29. }
  30.  
  31. int main(int   argc, char  *argv[])
  32. {
  33.         printf("W[0] equals ", W[0], "\n");
  34.         B[0] = B[0] << 62;           // 1st byte is    01000000
  35.         B[1] = B[1] << 57;           // 1st byte is    00000010
  36.         B[2] = B[2] << 55;           // 2nd byte is    10000000
  37.         B[0] = B[0] << 48;           // 2nd byte is    00000001
  38.         W[1] = W[1] << 15;           // 7th byte is    10000000
  39.         W[3] = W[3] <<  8;           // 7th byte is    00000001
  40.         W[0] = W[0] <<  6;           // 8th byte is    01000000
  41.         W[2] = W[2] <<  1;           // 8th byte is    00000010
  42.         printf("W[0] equals ", W[0], "\n");
  43.         BlackSet = B[0] & B[1] & B[2] & B[3];
  44.         WhiteSet = W[0] & W[1] & W[2] & W[3];
  45.         CollisionSet = BlackSet & WhiteSet;
  46.         printf("W[0] equals ", W[0], "\n");
  47.         int x = lshift_white(W[0], 1);
  48.         printf("W[0] equals ", W[0], "!");
  49.         return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement