From d7ac8dcb88a5cd93f505f1f00b1daec8ac6cceaf Mon Sep 17 00:00:00 2001 From: Frederick Yin Date: Mon, 6 Jun 2022 11:49:25 +0800 Subject: Flatten map to array of size H*W --- pieces.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'pieces.c') diff --git a/pieces.c b/pieces.c index 3b71003..001c9df 100644 --- a/pieces.c +++ b/pieces.c @@ -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] = '+'; } } } -- cgit v1.2.3