Skip to content

Commit

Permalink
Fix crash du to bad traversing of hills.
Browse files Browse the repository at this point in the history
  • Loading branch information
liberforce committed Nov 7, 2011
1 parent 2fabeea commit 6c22ed0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
12 changes: 5 additions & 7 deletions termite.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,21 @@
void termite_play_turn (Rules *rules,
State *state)
{
guint i;
gint i;
gint food_index, ant_index;
guint distance; // Manhattan distance
Tile *food;
Tile *ant;
Tile *hill;
gchar dir;

// Keep enemy hills only
for (i = 0; i < state->n_hills; ++i)
// Keep enemy hills only. We need to iterate from last to first to
// test all items as we remove last element
for (i = state->n_hills - 1; i >= 0 ; --i)
{
Tile *tile = state->hills[i];
if (hill_get_owner (&tile->with.hill) == 0)
{
state->hills[i] = state->hills[state->n_hills - 1];
if (! tile_has_enemy_hill (tile))
state->n_hills--;
}
}

// Process each ant
Expand Down
2 changes: 1 addition & 1 deletion tile.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ inline gboolean tile_is_free (Tile *tile)
&& tile->type != TILE_TYPE_FOOD);
}

inline gboolean tile_is_ennemy_hill (Tile *tile)
inline gboolean tile_has_enemy_hill (Tile *tile)
{
assert (tile != NULL);
return (tile->flags & TILE_HAS_HILL && tile->with.hill.owner != 0);
Expand Down
2 changes: 1 addition & 1 deletion tile.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void tile_set_type (Tile *tile,

TileType tile_get_type (Tile *tile);
gboolean tile_is_free (Tile *tile);
gboolean tile_is_ennemy_hill (Tile *tile);
gboolean tile_has_enemy_hill (Tile *tile);
void tile_set_flags (Tile *tile, guint16 flags);
guint16 tile_get_flags (Tile *tile);
gchar tile_get_ascii_type (Tile *tile);
Expand Down

0 comments on commit 6c22ed0

Please sign in to comment.