Browse Source

calculate_lab_way

remotes/origin/Joe
Joe Lukas Kalb 11 months ago
parent
commit
4a697fad04
  1. 29
      src/main/c/labyrinth.c
  2. 1
      src/main/c/labyrinth.h

29
src/main/c/labyrinth.c

@ -130,3 +130,32 @@ void ask_lab_walls(Field_State** field, unsigned short len_x, unsigned short len
} while (wall_input_continue != 1); } while (wall_input_continue != 1);
} }
short calculate_lab_way(Field_State** field, unsigned short len_x, unsigned short len_y, unsigned short x, unsigned short y){
Direction direction = N;
unsigned short c_x;
unsigned short c_y;
if (x == len_x-1 && y == len_y-1){
field[x][y] = SOLUTION;
return 0;
}
do {
c_x = x;
c_y = y;
if (lab_can_move(field, c_x, c_y, direction, len_x, len_y) == 0){
lab_move(&c_x, &c_y, direction);
printf("%d - %d\n", c_x, c_y);
field[c_x][c_y] = SOLUTION;
if (calculate_lab_way(field, len_x, len_y, c_x, c_y) == 0){
return 0;
}
field[c_x][c_y] = WAY;
}
turn_direction_right(&direction);
}
while (direction != N);
return 1;
}

1
src/main/c/labyrinth.h

@ -13,5 +13,6 @@ unsigned short get_natural_number(char text[]);
void ask_lab_dimensions(unsigned short *len_x, unsigned short *len_y); void ask_lab_dimensions(unsigned short *len_x, unsigned short *len_y);
short get_wall_input(unsigned short *x, unsigned short *y, unsigned short len_x, unsigned short len_y); short get_wall_input(unsigned short *x, unsigned short *y, unsigned short len_x, unsigned short len_y);
void ask_lab_walls(Field_State** field, unsigned short len_x, unsigned short len_y); void ask_lab_walls(Field_State** field, unsigned short len_x, unsigned short len_y);
short calculate_lab_way(Field_State** field, unsigned short len_x, unsigned short len_y, unsigned short x, unsigned short y);
#endif // TEST_H #endif // TEST_H
Loading…
Cancel
Save