Browse Source

refactoring: open_empty_space

remotes/origin/David
David Moeller 11 months ago
parent
commit
a667ee733a
  1. 6
      src/main/c/Minesweeper/minesweeper_start.c

6
src/main/c/Minesweeper/minesweeper_start.c

@ -163,7 +163,7 @@ Minesweeper_Board initialize_minesweeper(){
board.tiles = (int*) malloc(width * height * sizeof(int)); board.tiles = (int*) malloc(width * height * sizeof(int));
for(int i = 0; i < width * height; i++){board.tiles[i] = BLOCK;} for(int i = 0; i < width * height; i++){board.tiles[i] = BLOCK;}
board.marked = (int*) malloc(width * height * sizeof(int)); board.marked = (int*) malloc(width * height * sizeof(int));
for(int i = 0; i < width * height; i++){board.marked[i] = 0;}
for(int i = 0; i < width * height; i++){board.marked[i] = -1;}
board.num_bombs = num_bombs; board.num_bombs = num_bombs;
board.bombs = (int*) malloc(board.num_bombs * sizeof(int)); board.bombs = (int*) malloc(board.num_bombs * sizeof(int));
for(int i = 0; i < num_bombs; i++){board.bombs[i] = -1;} for(int i = 0; i < num_bombs; i++){board.bombs[i] = -1;}
@ -239,7 +239,7 @@ void open_empty_space(Minesweeper_Board *board, int tile, int index){
if(check_tile == -1){continue;} if(check_tile == -1){continue;}
int sum = open_tile(board, check_tile); int sum = open_tile(board, check_tile);
if(sum != 0){board->tiles[check_tile] = sum + 48;} if(sum != 0){board->tiles[check_tile] = sum + 48;}
else if(!array_contains_value(board->marked, check_tile, index + 1)){open_empty_space(board, check_tile, index + 1);}
else if(!array_contains_value(board->marked, check_tile, board->height * board->width)){open_empty_space(board, check_tile, index + 1);}
} }
} }
@ -250,7 +250,7 @@ int is_Valid_tile(Minesweeper_Board *board, int tile, int i){
else{check_tile -= 1;}} else{check_tile -= 1;}}
if(i > 4){if(tile % board->width + 1 == board->width){return -1;} if(i > 4){if(tile % board->width + 1 == board->width){return -1;}
else{check_tile += 1;}} else{check_tile += 1;}}
if(i % 3 == 0){if(i != 0 && tile / board->width == 0){return -1;}
if(i % 3 == 0){if(tile / board->width == 0){return -1;}
else{check_tile -= board->width;}} else{check_tile -= board->width;}}
if(i % 3 == 1){if(tile / board->width + 1 == height){return -1;} if(i % 3 == 1){if(tile / board->width + 1 == height){return -1;}
else{check_tile += board->width;}} else{check_tile += board->width;}}

Loading…
Cancel
Save