xth

C bitmap board

xth
May 13th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.70 KB | None | 0 0
  1. // 64 bit uint used as 8x8 gameboard bitmap
  2. // what am i doing with my life
  3.  
  4. #include <stdint.h>
  5. // #define UINT64_C(c) c ## ULL
  6.  
  7. uint64_t  W[4] = {1,1,1,1}, B = {1,1,1,1};
  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. B[3] = B[3] << 62;           // 1st byte is    01000000
  17. B[1] = B[1] << 57;           // 1st byte is    00000010
  18. B[2] = B[2] << 55;           // 2nd byte is    10000000
  19. B[0] = B[0] << 48;           // 2nd byte is    00000001
  20. W[1] = W[1] << 15;           // 7th byte is    10000000
  21. W[3] = W[3] <<  8;           // 7th byte is    00000001
  22. W[0] = W[0] <<  6;           // 8th byte is    01000000
  23. W[2] = W[2] <<  1;           // 8th byte is    00000010
  24.  
  25. uint64_t  BlackSet = B[0] & B[1] & B[2] & B[3];
  26. uint64_t  WhiteSet = W[0] & W[1] & W[2] & W[3];
  27. uint64_t  CollisionSet = BlackSet & WhiteSet;
  28.  
  29. // return 1 if success
  30. int lshift_white(uint64_t  * selected_piece, unsigned int shift_amount)
  31. {
  32.         if (!((CollisionSet ^ ((*selected_piece) << shift_amount)) == CollisionSet)) {
  33.                 WhiteSet = WhiteSet ^ (*selected_piece);
  34.                 *selected_piece = (*selected_piece) << shift_amount;
  35.                 WhiteSet = WhiteSet & (*selected_piece);
  36.                 CollisionSet = WhiteSet & BlackSet;
  37.                 return 1;
  38.         } else {
  39.                 return 0;
  40.         }
  41. }
  42.  
  43. int main(int   argc, char  *argv[])
  44. {
  45.         int x = lshift_white(*W[0], 1); // Should be 10000000
  46.         printf("W[0] equals ", W[0]);
  47.         return 0;
  48. }
  49.  
  50. /*
  51. X:\lvAMZNS\Day7\C>cl main.c
  52. Microsoft (R) C/C++ Optimizing Compiler Version 19.15.26732.1 for x64
  53. Copyright (C) Microsoft Corporation.  All rights reserved.
  54.  
  55. main.c
  56. main.c(7): error C2078: too many initializers
  57. main.c(16): error C2040: 'B': 'int [3]' differs in levels of indirection from 'uint64_t'
  58. main.c(16): error C2109: subscript requires array or pointer type
  59. main.c(17): error C2040: 'B': 'int [1]' differs in levels of indirection from 'uint64_t'
  60. main.c(17): error C2109: subscript requires array or pointer type
  61. main.c(18): error C2040: 'B': 'int [2]' differs in levels of indirection from 'uint64_t'
  62. main.c(18): error C2109: subscript requires array or pointer type
  63. main.c(19): error C2466: cannot allocate an array of constant size 0
  64. main.c(19): error C2040: 'B': 'int [0]' differs in levels of indirection from 'uint64_t'
  65. main.c(19): error C2109: subscript requires array or pointer type
  66. main.c(20): error C2369: 'W': redefinition; different subscripts
  67. main.c(7): note: see declaration of 'W'
  68. main.c(20): error C2099: initializer is not a constant
  69. main.c(21): error C2369: 'W': redefinition; different subscripts
  70. main.c(7): note: see declaration of 'W'
  71. main.c(21): error C2099: initializer is not a constant
  72. main.c(22): error C2466: cannot allocate an array of constant size 0
  73. main.c(22): error C2371: 'W': redefinition; different basic types
  74. main.c(7): note: see declaration of 'W'
  75. main.c(22): error C2099: initializer is not a constant
  76. main.c(23): error C2369: 'W': redefinition; different subscripts
  77. main.c(7): note: see declaration of 'W'
  78. main.c(23): error C2099: initializer is not a constant
  79. main.c(25): error C2109: subscript requires array or pointer type
  80. main.c(26): error C2099: initializer is not a constant
  81. main.c(27): error C2099: initializer is not a constant
  82. main.c(45): error C2100: illegal indirection
  83. main.c(45): warning C4047: 'function': 'uint64_t *' differs in levels of indirection from 'uint64_t'
  84. main.c(45): warning C4024: 'lshift_white': different types for formal and actual parameter 1
  85. */
Add Comment
Please, Sign In to add comment