Advertisement
Guest User

Untitled

a guest
Mar 3rd, 2013
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.14 KB | None | 0 0
  1. #define NCARD 31        /* number of different cards */
  2. static unsigned short card_inps[NCARD];  /* bitmask of input resources per card */
  3. static unsigned short card_outs[NCARD];  /* bitmask of output resources per card */
  4.  
  5. // Calculate score for given cards (given last-filled column `cc')
  6. static unsigned get_score(const signed char cards[], int cc)
  7. {
  8.     static const int dr[8] = { -1, -1, -1,  0,  0,  1,  1,  1 };
  9.     static const int dc[8] = { -1,  0,  1, -1,  1, -1,  0,  1 };
  10.  
  11.     unsigned res = 0;
  12.     for (int c = 0; c <= cc; ++c)
  13.     {
  14.         for (int r = 0; r < H; ++r)
  15.         {
  16.             int i = cards[H*c + r];
  17.             assert(i >= 0);
  18.             unsigned nearby = 0;
  19.             for (int dir = 0; dir < 8; ++dir)
  20.             {
  21.                 int nr = r + dr[dir],
  22.                     nc = c + dr[dir];
  23.                 if (nr < 0 || nr >= H || nc < 0 || nc > cc) continue;
  24.                 int j = cards[H*nc + nr];
  25.                 assert(j >= 0);
  26.                 nearby |= card_outs[j];
  27.             }
  28.             for (unsigned m = card_inps[i] & nearby; m != 0; m &= m - 1) ++res;
  29.         }
  30.     }
  31.     return res;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement