Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define NCARD 31 /* number of different cards */
- static unsigned short card_inps[NCARD]; /* bitmask of input resources per card */
- static unsigned short card_outs[NCARD]; /* bitmask of output resources per card */
- // Calculate score for given cards (given last-filled column `cc')
- static unsigned get_score(const signed char cards[], int cc)
- {
- static const int dr[8] = { -1, -1, -1, 0, 0, 1, 1, 1 };
- static const int dc[8] = { -1, 0, 1, -1, 1, -1, 0, 1 };
- unsigned res = 0;
- for (int c = 0; c <= cc; ++c)
- {
- for (int r = 0; r < H; ++r)
- {
- int i = cards[H*c + r];
- assert(i >= 0);
- unsigned nearby = 0;
- for (int dir = 0; dir < 8; ++dir)
- {
- int nr = r + dr[dir],
- nc = c + dr[dir];
- if (nr < 0 || nr >= H || nc < 0 || nc > cc) continue;
- int j = cards[H*nc + nr];
- assert(j >= 0);
- nearby |= card_outs[j];
- }
- for (unsigned m = card_inps[i] & nearby; m != 0; m &= m - 1) ++res;
- }
- }
- return res;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement