|
@ -225,6 +225,12 @@ State* state; |
|
|
|
|
|
|
|
|
// Algoritmy
|
|
|
// Algoritmy
|
|
|
|
|
|
|
|
|
|
|
|
// modulení jako v Pythonu
|
|
|
|
|
|
int py_mod(int a, int b) |
|
|
|
|
|
{ |
|
|
|
|
|
return (a % b + b) % b; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// otoč směr podle jiného otočení
|
|
|
// otoč směr podle jiného otočení
|
|
|
Direction combine_directions(Direction a, Direction b) |
|
|
Direction combine_directions(Direction a, Direction b) |
|
|
{ |
|
|
{ |
|
@ -246,33 +252,27 @@ Direction invert_direction(Direction a) |
|
|
// další políčko v daném směru
|
|
|
// další políčko v daném směru
|
|
|
Field* get_neighbour_field(Field* f, Direction direction) |
|
|
Field* get_neighbour_field(Field* f, Direction direction) |
|
|
{ |
|
|
{ |
|
|
int neighbour_i, neighbour_j; |
|
|
int neighbour_i = f->i; |
|
|
|
|
|
int neighbour_j = f->j; |
|
|
switch (direction) |
|
|
switch (direction) |
|
|
{ |
|
|
{ |
|
|
case UP: |
|
|
case UP: |
|
|
neighbour_i = f->i - 1; |
|
|
neighbour_i = f->i - 1; |
|
|
neighbour_j = f->j; |
|
|
|
|
|
break; |
|
|
break; |
|
|
case DOWN: |
|
|
case DOWN: |
|
|
neighbour_i = f->i + 1; |
|
|
neighbour_i = f->i + 1; |
|
|
neighbour_j = f->j; |
|
|
|
|
|
break; |
|
|
break; |
|
|
case LEFT: |
|
|
case LEFT: |
|
|
neighbour_i = f->i; |
|
|
|
|
|
neighbour_j = f->j - 1; |
|
|
neighbour_j = f->j - 1; |
|
|
break; |
|
|
break; |
|
|
case RIGHT: |
|
|
case RIGHT: |
|
|
neighbour_i = f->i; |
|
|
|
|
|
neighbour_j = f->j + 1; |
|
|
neighbour_j = f->j + 1; |
|
|
break; |
|
|
break; |
|
|
default: |
|
|
|
|
|
neighbour_i = f->i; |
|
|
|
|
|
neighbour_j = f->j; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// zajisti, aby souřadnice byly v rozsahu herní plochy
|
|
|
// zajisti, aby souřadnice byly v rozsahu herní plochy
|
|
|
neighbour_i %= state->world.size(); |
|
|
neighbour_i = py_mod(neighbour_i, state->world.size()); |
|
|
neighbour_j %= state->world[0].size(); |
|
|
neighbour_j = py_mod(neighbour_j, state->world[0].size()); |
|
|
return state->world[neighbour_i][neighbour_j]; |
|
|
return state->world[neighbour_i][neighbour_j]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|