diff options
| author | eug-vs <eugene@eug-vs.xyz> | 2022-03-31 22:41:21 +0300 | 
|---|---|---|
| committer | eug-vs <eugene@eug-vs.xyz> | 2022-03-31 22:45:19 +0300 | 
| commit | 7dbd21f32c633e6c0c7fe9c55accda3bfc9fc88c (patch) | |
| tree | 933a2df571f4cd782dd40baffcf55d733d590e42 /src | |
| parent | 01d7e24b2c32d9350a11afa0e9ef677790c460d6 (diff) | |
| download | carcassonne-engine-c-7dbd21f32c633e6c0c7fe9c55accda3bfc9fc88c.tar.gz | |
refactor: remove unused code
Diffstat (limited to 'src')
| -rw-r--r-- | src/board.c | 19 | ||||
| -rw-r--r-- | src/board.h | 21 | ||||
| -rw-r--r-- | src/main.c | 5 | 
3 files changed, 12 insertions, 33 deletions
diff --git a/src/board.c b/src/board.c index fdafd2d..263e205 100644 --- a/src/board.c +++ b/src/board.c @@ -1,17 +1,6 @@  #include <stdio.h>  #include "board.h" -void print_board(BoardUnit* board) { -  for (int row = 0; row < BOARD_ROW_UNITS; row++) { -    for (int i = 0; i < BOARD_ROW_UNITS; i++) { -      int index = BOARD_ROW_UNITS * row + i; -      if (board[index].feature == EMPTY && is_center_index(index)) printf("*"); -      else printf("%c", board[index].feature); -    } -    printf("\n"); -  } -} -  void initialize_board(BoardUnit* board) {    for (int i = 0; i < BOARD_UNITS; i++) {      board[i].feature = EMPTY; @@ -30,7 +19,7 @@ int is_allowed_placement(Tile tile, int index, BoardUnit* board) {    int neighbor_count = 0;    for (int i = 0; i < 4; i++) { -    char neighbor = board[index + neighbor_increments[i]].feature; +    char neighbor = board[index + NEIGHBOR_INCREMENTS[i]].feature;      if (neighbor != EMPTY) {        if (neighbor != tile.edges[i]) return 0;        neighbor_count++; @@ -53,7 +42,7 @@ int place_tile(Tile tile, int index, BoardUnit* board, int force) {    board[index].feature = tile.center;    for (int i = 0; i < 4; i++) { -    board[index + neighbor_increments[i]].feature = tile.edges[i]; +    board[index + NEIGHBOR_INCREMENTS[i]].feature = tile.edges[i];    }    return 1; @@ -62,7 +51,7 @@ int place_tile(Tile tile, int index, BoardUnit* board, int force) {  void traverse_structure(int group, int index, BoardUnit* board) {    board[index].structure_group = group;    for (int i = 0; i < 4; i++) { -    int new_unit = index + neighbor_increments[i]; +    int new_unit = index + NEIGHBOR_INCREMENTS[i];      if (board[new_unit].feature == board[index].feature && board[new_unit].structure_group == 0) {        traverse_structure(group, new_unit, board);      } @@ -99,7 +88,7 @@ int evaluate_structure(int index, BoardUnit* board) {        int index = translate_coordinate(i * BOARD_WIDTH + j);        if (board[index].feature != EMPTY) { // Empty tiles doesn't count          for (int k = 0; k < 4; k++) { -          if (board[index + neighbor_increments[k]].structure_group == structure_group) { +          if (board[index + NEIGHBOR_INCREMENTS[k]].structure_group == structure_group) {              printf("Found at tile %i\n", i * BOARD_WIDTH + j);              value++;              break; diff --git a/src/board.h b/src/board.h index dc1995a..e0acd1f 100644 --- a/src/board.h +++ b/src/board.h @@ -3,15 +3,9 @@  #define BOARD_UNITS BOARD_ROW_UNITS * BOARD_ROW_UNITS -char EMPTY = ' '; - -int neighbor_increments[] = { -  - BOARD_ROW_UNITS, -    1, -    BOARD_ROW_UNITS, -  - 1 -}; - +/* constants */ +const char EMPTY = ' '; +const int NEIGHBOR_INCREMENTS[] = { -BOARD_ROW_UNITS, 1, BOARD_ROW_UNITS, -1 };  /* structs */  typedef struct { @@ -28,14 +22,11 @@ typedef struct {  /* board */  void initialize_board(BoardUnit* board); -void print_board(BoardUnit* board); -void write_board(BoardUnit* board, char* filename); -void read_board(BoardUnit* board, char* filename); - -/* moves */ -int is_allowed_placement(Tile tile, int index, BoardUnit* board);  int translate_coordinate(int index);  int is_center_index(int index); + +/* tiles */ +int is_allowed_placement(Tile tile, int index, BoardUnit* board);  int place_tile(Tile tile, int index, BoardUnit* board, int force);  /* structures */ @@ -20,7 +20,7 @@ void draw_structures(BoardUnit* board, WINDOW* win) {      for (int i = 0; i < BOARD_ROW_UNITS; i++) {        int index = BOARD_ROW_UNITS * row + i;        if (board[index].feature == EMPTY && is_center_index(index)) waddch(win, '*'); -      else waddch(win, board[index].structure_group == 0 ? ' ' : '0' + board[index].structure_group); +      else waddch(win, board[index].structure_group == 0 ? EMPTY : '0' + board[index].structure_group);      }    }  } @@ -64,7 +64,6 @@ int main() {    /* main loop */    char position[3];    while (1) { -      /* prepare */      refresh_structure_groups(board);      wclear(input_win); @@ -86,7 +85,7 @@ int main() {      box(input_box, 0, 0);      mvwaddstr(input_box, 0, 0, "Enter position:");      wrefresh(input_box); -    wgetstr(input_win, position); +    wgetnstr(input_win, position, 3);      int result = place_tile(tile, translate_coordinate(atoi(position)), board, 0);      if (result) wprintw(messages_win, "Placed tile %s (%c) at position %i\n", tile.edges, tile.center, atoi(position));  |