aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreug-vs <eugene@eug-vs.xyz>2022-03-29 12:52:29 +0300
committereug-vs <eugene@eug-vs.xyz>2022-03-29 12:52:29 +0300
commit792a22e042ae4499dcb4f89e3d5459adbc6ba7ad (patch)
tree46000b65d407ff9f6ca422f7c76d0b3bedc6d066
parent2c803562d153b53a2c1f983af5e8ee68422cbfdb (diff)
downloadcarcassonne-engine-c-792a22e042ae4499dcb4f89e3d5459adbc6ba7ad.tar.gz
feat: add coordinates translation
-rw-r--r--src/board.h2
-rw-r--r--src/main.c14
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);
diff --git a/src/main.c b/src/main.c
index f80e4f7..e29406e 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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);