aboutsummaryrefslogtreecommitdiff
path: root/src/board.c
diff options
context:
space:
mode:
authoreug-vs <eugene@eug-vs.xyz>2022-03-31 21:03:38 +0300
committereug-vs <eugene@eug-vs.xyz>2022-03-31 21:03:38 +0300
commitbe2885fc3eb77ec33c5afe10a741ff23a21b0b5d (patch)
treef4be67d960d5f9322b3b536ab5268fbaf05d9c8c /src/board.c
parent6f4ac9571a0a6df9ec607e5a9a9b8d3e5f7bbc96 (diff)
downloadcarcassonne-engine-c-be2885fc3eb77ec33c5afe10a741ff23a21b0b5d.tar.gz
refactor: use struct for Tile
Diffstat (limited to 'src/board.c')
-rw-r--r--src/board.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/board.c b/src/board.c
index 8c33ae3..d885a8c 100644
--- a/src/board.c
+++ b/src/board.c
@@ -22,7 +22,7 @@ int is_center_index(int index) {
return ((index / BOARD_ROW_BYTES) % 2 == 1) && ((index % BOARD_ROW_BYTES) % 2 == 1);
}
-int is_allowed_placement(char* tile, int index, char* board) {
+int is_allowed_placement(Tile tile, int index, char* board) {
if (board[index] != EMPTY) return 0;
int neighbor_count = 0;
@@ -30,7 +30,7 @@ int is_allowed_placement(char* tile, int index, char* board) {
for (int i = 0; i < 4; i++) {
char neighbor = board[index + neighbor_increments[i]];
if (neighbor != EMPTY) {
- if (neighbor != tile[i + 1]) return 0;
+ if (neighbor != tile.edges[i]) return 0;
neighbor_count++;
}
}
@@ -38,20 +38,20 @@ int is_allowed_placement(char* tile, int index, char* board) {
return neighbor_count > 0;
}
-int place_tile(char* tile, int index, char* board, int force) {
+int place_tile(Tile tile, int index, char* board, int force) {
if (!is_center_index(index)) {
printf("Not a valid tile index: %i\n", index);
return 0;
}
if (!force && !is_allowed_placement(tile, index, board)) {
- printf("Can not place tile %s\n", tile);
+ printf("Can not place tile %s (%c)\n", tile.edges, tile.center);
return 0;
}
- board[index] = tile[0];
+ board[index] = tile.center;
for (int i = 0; i < 4; i++) {
- board[index + neighbor_increments[i]] = tile[i + 1];
+ board[index + neighbor_increments[i]] = tile.edges[i];
}
return 1;