Browse Source

Test 2 bombs around tile

remotes/origin/David
David Moeller 11 months ago
parent
commit
79c871c7ff
  1. 16
      src/main/c/Minesweeper/minesweeper_start.c
  2. 27
      test/Minesweeper/test_number_of_bombs.c

16
src/main/c/Minesweeper/minesweeper_start.c

@ -208,14 +208,14 @@ int number_of_bombs(Minesweeper_Board *board, int tile){
int sum = 0;
for(int i = 0; i < 8; i++){
int check_tile = tile;
if(i < 3 && tile % board->width == 0){continue;}
else{check_tile - 1;}
if(i > 4 && tile % board->width + 1 == board->width){continue;}
else{check_tile + 1;}
if(i % 3 == 0 && i != 0 && tile / board->width == 0){continue;}
else{check_tile - board->width;}
if(i % 3 == 1 && tile / board->width + 1 == height){continue;}
else{check_tile + board->width;}
if(i < 3){if(tile % board->width == 0){continue;}
else{check_tile -= 1;}}
if(i > 4){if(tile % board->width + 1 == board->width){continue;}
else{check_tile += 1;}}
if(i % 3 == 0){if(i != 0 && tile / board->width == 0){continue;}
else{check_tile -= board->width;}}
if(i % 3 == 1){if(tile / board->width + 1 == height){continue;}
else{check_tile += board->width;}}
if(bomb_in_array(board->bombs, check_tile, board->num_bombs)){sum++;}
}
return sum;

27
test/Minesweeper/test_number_of_bombs.c

@ -12,7 +12,7 @@ void test_no_bombs_placed_around_tile(void){
/* arrange */
int result;
Minesweeper_Board board = initialize_minesweeper();
int tile = 1 + board.width * 1;
int tile = 0 + board.width * 1;
/* act */
result = number_of_bombs(&board, tile);
@ -26,10 +26,10 @@ void test_searching_for_bombs_on_correct_tiles(void){
int result;
Minesweeper_Board board = initialize_minesweeper();
int tile = 0 + board.width * 1;
board.bombs[0] = 0 + board.width * 2;
board.bombs[0] = 2 + board.width * 1;
board.bombs[0] = board.width - 1 + board.width * 1;
board.bombs[0] = 0 + board.width * (board.height - 1);
board.bombs[0] = 0 + board.width * 3;
board.bombs[1] = 2 + board.width * 1;
board.bombs[2] = board.width - 1 + board.width * 1;
board.bombs[3] = 0 + board.width * (board.height - 1);
/* act */
result = number_of_bombs(&board, tile);
@ -38,4 +38,21 @@ void test_searching_for_bombs_on_correct_tiles(void){
TEST_ASSERT_EQUAL_INT(0, result);//no bombs placed around tile
}
void test_2_bombs_around_tile(void){
/* arrange */
int result;
Minesweeper_Board board = initialize_minesweeper();
int tile = 0 + board.width * 1;
board.bombs[0] = 0 + board.width * 2;
board.bombs[1] = 1 + board.width * 1;
board.bombs[2] = board.width - 1 + board.width * 1;
board.bombs[3] = 0 + board.width * (board.height - 1);
/* act */
result = number_of_bombs(&board, tile);
/* assert */
TEST_ASSERT_EQUAL_INT(2, result);//2 bombs placed around tile
}
#endif // TEST
Loading…
Cancel
Save