diff options
author | eug-vs <eugene@eug-vs.xyz> | 2022-03-29 12:52:29 +0300 |
---|---|---|
committer | eug-vs <eugene@eug-vs.xyz> | 2022-03-29 12:52:29 +0300 |
commit | 792a22e042ae4499dcb4f89e3d5459adbc6ba7ad (patch) | |
tree | 46000b65d407ff9f6ca422f7c76d0b3bedc6d066 | |
parent | 2c803562d153b53a2c1f983af5e8ee68422cbfdb (diff) | |
download | carcassonne-engine-c-792a22e042ae4499dcb4f89e3d5459adbc6ba7ad.tar.gz |
feat: add coordinates translation
-rw-r--r-- | src/board.h | 2 | ||||
-rw-r--r-- | src/main.c | 14 |
2 files changed, 12 insertions, 4 deletions
diff --git a/src/board.h b/src/board.h index 924c226..d5fb2d0 100644 --- a/src/board.h +++ b/src/board.h @@ -20,6 +20,8 @@ void print_board(char* board); // Moves int is_allowed_placement(char* tile, int position, char* board); +int translate_coordinate(int position); + int is_center_position(int position); int place_tile(char* tile, int position, char* board); @@ -69,6 +69,12 @@ void create_structure_mask(char* board, char* structures) { } } +int translate_coordinate(int center_position) { + return (2 * (center_position / BOARD_WIDTH) + 1) * + (2 * BOARD_WIDTH + 1) + + (2 * (center_position % BOARD_WIDTH) + 1); +} + int main() { char board[BOARD_BYTES]; char structures[BOARD_BYTES]; @@ -76,10 +82,10 @@ int main() { initialize_board(board); initialize_board(structures); - place_tile("RFRFR", 6, board); - place_tile("RCCRR", 8, board); - place_tile("RRFRF", 18, board); - place_tile("CFFCC", 16, board); + place_tile("RFRFR", translate_coordinate(0), board); + place_tile("RCCRR", translate_coordinate(1), board); + place_tile("CFFCC", translate_coordinate(2), board); + place_tile("RRFRF", translate_coordinate(3), board); create_structure_mask(board, structures); print_board(board); |