예제 #1
0
void world_copy_data(const struct world * world_in, struct world * world_out)
{
    ASSERT_VALID_WORLD(world_in);
    ASSERT_VALID_WORLD(world_out);

    // Détermine la plus petite largeur compatible entre les deux mondes
    const unsigned int world_in_width = world_get_width(world_in);
    const unsigned int world_out_width = world_get_width(world_out);
    const unsigned int width = world_in_width <= world_out_width ? world_in_width : world_out_width;

    // Détermine la plus petite hauteur compatible entre les deux mondes
    const unsigned int world_in_height = world_get_height(world_in);
    const unsigned int world_out_height = world_get_height(world_out);
    const unsigned int height = world_in_height <= world_out_height ? world_in_height : world_out_height;

    // Copie l'état des cellules
    for (unsigned int y = 0; y < height; ++y) {
        for (unsigned int x = 0; x < width; ++x) {
            const bool cell_is_alive = world_cell_get_is_alive(world_in, x, y);
            world_cell_set_is_alive(world_out, x, y, cell_is_alive);
        }
    }
}
예제 #2
0
파일: user.c 프로젝트: nameless-/Simuluce
/*
 * Randomly choose a destination into the grid
 */
int user_choose_dest(struct user_t* user){
  user->dest.x = (rand() % (world_get_width()-2)) + 1;
  user->dest.y = (rand() % (world_get_height()-2)) + 1;
  user->speed  = (rand() % (u_max_speed-u_min_speed)) + u_min_speed;
  return 0;
}