Browse Source

Strategická: Fix modulení

master
David Klement 2 years ago
parent
commit
8bb52a9898
  1. 20
      klient/strategy.cpp

20
klient/strategy.cpp

@ -225,6 +225,12 @@ State* state;
// 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í
Direction combine_directions(Direction a, Direction b)
{
@ -246,33 +252,27 @@ Direction invert_direction(Direction a)
// další políčko v daném směru
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)
{
case UP:
neighbour_i = f->i - 1;
neighbour_j = f->j;
break;
case DOWN:
neighbour_i = f->i + 1;
neighbour_j = f->j;
break;
case LEFT:
neighbour_i = f->i;
neighbour_j = f->j - 1;
break;
case RIGHT:
neighbour_i = f->i;
neighbour_j = f->j + 1;
break;
default:
neighbour_i = f->i;
neighbour_j = f->j;
}
// zajisti, aby souřadnice byly v rozsahu herní plochy
neighbour_i %= state->world.size();
neighbour_j %= state->world[0].size();
neighbour_i = py_mod(neighbour_i, state->world.size());
neighbour_j = py_mod(neighbour_j, state->world[0].size());
return state->world[neighbour_i][neighbour_j];
}

Loading…
Cancel
Save