diff options
author | Frederick Yin <fkfd@fkfd.me> | 2022-06-06 11:49:25 +0800 |
---|---|---|
committer | Frederick Yin <fkfd@fkfd.me> | 2022-06-06 11:49:25 +0800 |
commit | d7ac8dcb88a5cd93f505f1f00b1daec8ac6cceaf (patch) | |
tree | 31cd7a7425e26e64c3c1e23605da8097a949f9e4 /pieces.c | |
parent | fc9ae26aacede490d32f0b31d314f2c8286d158a (diff) |
Flatten map to array of size H*W
Diffstat (limited to 'pieces.c')
-rw-r--r-- | pieces.c | 8 |
1 files changed, 4 insertions, 4 deletions
@@ -94,7 +94,7 @@ void refillpieces(struct piece** hand, int nhand) { } } -bool placeable(char** map, struct piece* pc, int row, int col, int mapH, int mapW) { +bool placeable(char* map, struct piece* pc, int row, int col, int mapH, int mapW) { // boundary check if (row < 0 || row + (pc->h) > mapH || col < 0 || col + (pc->w) > mapW) return false; @@ -102,7 +102,7 @@ bool placeable(char** map, struct piece* pc, int row, int col, int mapH, int map // check if blocks to be taken by `pc` are vacant for (int r = 0; r < pc->h; r++) { for (int c = 0; c < pc->w; c++) { - if (map[row + r][col + c] == '+' && pc->blocks[r * pc->w + c] == '+') + if (map[(row + r) * mapW + col + c] == '+' && pc->blocks[r * pc->w + c] == '+') return false; } } @@ -110,11 +110,11 @@ bool placeable(char** map, struct piece* pc, int row, int col, int mapH, int map return true; } -void place(char** map, struct piece* pc, int row, int col) { +void place(char* map, struct piece* pc, int row, int col, int mapW) { for (int r = 0; r < pc->h; r++) { for (int c = 0; c < pc->w; c++) { if (pc->blocks[r * (pc->w) + c] == '+') - map[row + r][col + c] = '+'; + map[(row + r) * mapW + col + c] = '+'; } } } |