diff --git a/src/main/c/Minesweeper/minesweeper_start.c b/src/main/c/Minesweeper/minesweeper_start.c index 19b4e50..fedb818 100644 --- a/src/main/c/Minesweeper/minesweeper_start.c +++ b/src/main/c/Minesweeper/minesweeper_start.c @@ -247,16 +247,17 @@ void open_empty_space(Minesweeper_Board *board, int tile, int index){ } } -int is_Valid_tile(Minesweeper_Board *board, int tile, int i){ +//0 = up-left, 1 = down-left, 2 = mid-left, 3 = up-mid, 4 = down-mid, 5 = mid-right, 6 = up-right, 7 = down-right +int is_Valid_tile(Minesweeper_Board *board, int tile, int direction){ int check_tile = tile; - if(i < 3){if(tile % board->width == 0){return -1;} + if(direction < 3){if(tile % board->width == 0){return -1;} else{check_tile -= 1;}} - if(i > 4){if(tile % board->width + 1 == board->width){return -1;} + if(direction > 4){if(tile % board->width + 1 == board->width){return -1;} else{check_tile += 1;}} - if(i % 3 == 0){if(tile / board->width == 0){return -1;} + if(direction % 3 == 0){if(tile / board->width == 0){return -1;} else{check_tile -= board->width;}} - if(i % 3 == 1){if(tile / board->width + 1 == height){return -1;} + if(direction % 3 == 1){if(tile / board->width + 1 == height){return -1;} else{check_tile += board->width;}} return check_tile; diff --git a/src/main/c/Minesweeper/minesweeper_start.h b/src/main/c/Minesweeper/minesweeper_start.h index c37d731..750003e 100644 --- a/src/main/c/Minesweeper/minesweeper_start.h +++ b/src/main/c/Minesweeper/minesweeper_start.h @@ -1,5 +1,6 @@ #ifndef MINESWEEPER_START_H #define MINESWEEPER_START_H +#include typedef struct Minesweeper_Board{ unsigned int width; @@ -10,11 +11,10 @@ typedef struct Minesweeper_Board{ int *bombs; }Minesweeper_Board; - void minesweeper_start(); Minesweeper_Board initialize_minesweeper(); bool array_contains_value(int *array, int bomb, int length); int number_of_bombs(Minesweeper_Board *board, int tile); - +int is_Valid_tile(Minesweeper_Board *board, int tile, int direction); #endif // MINESWEEPER_START_H \ No newline at end of file diff --git a/test/Minesweeper/test_is_Valid_tile.c b/test/Minesweeper/test_is_Valid_tile.c new file mode 100644 index 0000000..65082e2 --- /dev/null +++ b/test/Minesweeper/test_is_Valid_tile.c @@ -0,0 +1,24 @@ +#ifdef TEST +#include "unity.h" +#include "../../src/main/c/Minesweeper/minesweeper_start.h" + + +void setUp(void){} +void tearDown(void){} + + +void test_detect_not_valid_tile(void){ + /* arrange */ + Minesweeper_Board board = initialize_minesweeper(); + int tile = 0; + int direction = 1; + int result; + + /* act */ + result = is_Valid_tile(&board, tile, direction); + + /* assert */ + TEST_ASSERT_EQUAL_INT(-1, result);//not valid tile +} + +#endif // TEST \ No newline at end of file