#include "tile.h" int is_allowed_placement(Tile tile, int index, BoardUnit* board) { if (board[index].feature != EMPTY) return 0; int neighbor_count = 0; for (int i = 0; i < 4; i++) { char neighbor = board[index + NEIGHBOR_INCREMENTS[i]].feature; if (neighbor != EMPTY) { if (neighbor != tile.edges[i]) return 0; neighbor_count++; } } return neighbor_count > 0; } int place_tile(Tile tile, int index, BoardUnit* board, int force) { if (!is_center_index(index)) return 0; if (!force && !is_allowed_placement(tile, index, board)) return 0; board[index].feature = tile.center; for (int i = 0; i < 4; i++) { board[index + NEIGHBOR_INCREMENTS[i]].feature = tile.edges[i]; } return 1; } void rotate_tile(Tile* tile, int increment) { char buffer[8]; for (int i = 0; i < 8; i++) { buffer[i] = tile->edges[i % 4]; } for (int i = 0; i < 4; i++) { tile->edges[i] = buffer[i + (increment % 4)]; } } void initialize_tileset(Tile* tileset) { int index = 0; for (int i = 0; i < 4; i++) tileset[index++] = (Tile){ "FFFF", 'F', 0 }; for (int i = 0; i < 5; i++) tileset[index++] = (Tile){ "CFFF", 'F', 0 }; for (int i = 0; i < 1; i++) tileset[index++] = (Tile){ "FCFC", 'C', 0 }; for (int i = 0; i < 2; i++) tileset[index++] = (Tile){ "FCFC", 'C', 1 }; for (int i = 0; i < 3; i++) tileset[index++] = (Tile){ "CCFF", 'C', 0 }; for (int i = 0; i < 2; i++) tileset[index++] = (Tile){ "CCFF", 'C', 1 }; for (int i = 0; i < 2; i++) tileset[index++] = (Tile){ "CCFF", 'C', 1 }; for (int i = 0; i < 3; i++) tileset[index++] = (Tile){ "CFCF", 'F', 0 }; for (int i = 0; i < 2; i++) tileset[index++] = (Tile){ "CCFF", 'F', 0 }; for (int i = 0; i < 1; i++) tileset[index++] = (Tile){ "FFRF", 'R', 0 }; for (int i = 0; i < 1; i++) tileset[index++] = (Tile){ "FFRF", 'R', 0 }; for (int i = 0; i < 8; i++) tileset[index++] = (Tile){ "FRFR", 'R', 0 }; for (int i = 0; i < 9; i++) tileset[index++] = (Tile){ "FFRR", 'R', 0 }; for (int i = 0; i < 4; i++) tileset[index++] = (Tile){ "FRRR", '+', 0 }; for (int i = 0; i < 1; i++) tileset[index++] = (Tile){ "RRRR", '+', 0 }; for (int i = 0; i < 4; i++) tileset[index++] = (Tile){ "CRFR", 'R', 0 }; for (int i = 0; i < 3; i++) tileset[index++] = (Tile){ "CFRR", 'R', 0 }; for (int i = 0; i < 3; i++) tileset[index++] = (Tile){ "CRRF", 'R', 0 }; for (int i = 0; i < 3; i++) tileset[index++] = (Tile){ "CRRR", '+', 0 }; for (int i = 0; i < 3; i++) tileset[index++] = (Tile){ "CCRR", 'R', 0 }; for (int i = 0; i < 2; i++) tileset[index++] = (Tile){ "CCRR", 'R', 1 }; for (int i = 0; i < 1; i++) tileset[index++] = (Tile){ "CCRC", 'C', 0 }; for (int i = 0; i < 2; i++) tileset[index++] = (Tile){ "CCRC", 'C', 1 }; }