Infection Functions

find_infected

This function determines the x_location and y_location of all the infected people.

image

We have already set the states of the infected people and the positions of all the people, but we need to specifically set the positions of the infected people and store them in the infected_x_locations and infected_y_locations arrays. We do this by marching through the states array and checking whether the state at each cell is INFECTED. If it is, we add the locations of the current infected person from the x_locations and y_locations arrays to the infected_x_locations and infected_y_locations arrays. We determine the ID of the current infected person using the current_infected_person variable:

    int current_infected_person = 0;
    for(current_person_id = 0; current_person_id <= global->number_of_people - 1; 
        current_person_id++)
    {
        if(global->states[current_person_id] == INFECTED)
        {
            global->infected_x_locations[current_infected_person] = 
            global->x_locations[current_person_id];
            global->infected_y_locations[current_infected_person] =
            global->y_locations[current_person_id];
            current_infected_person++;
        }
    }