Exemplo n.º 1
0
static void *periodic_thread(void *arg)
{
    sigset_t alarm_sig;
    noble_simulation * sim;
    make_periodic(1000 * TIMING_CONST_MS, &alarm_sig);
    while (1) {
        
        sim = sim_sim();


        sim_cycle();
        count++;
        if ((count & 2047) == 0)
        {
            printf("count is %ld\n", count);
        }
        if (sim->num == 0)
        {
            printf("new run at %ld\n", count);
            
            sim_init(1,rand(),MAP_AREA,0);
        }
        
        wait_period(&alarm_sig);
    }
    return NULL;
}
Exemplo n.º 2
0
int main(int argc, const char * argv[])
{
    n_int   counter = 0;

    printf(" --- test sim --- start -----------------------------------------------\n");
    
    sim_init(2, 0x12738291, MAP_AREA, 0);
    
    {
        noble_simulation * local_sim = sim_sim();
        noble_being      * first_being = &(local_sim->beings[0]);
        noble_being      * second_being = &(local_sim->beings[1]);
        noble_being_constant * first_being_constant = &(first_being->constant);
        noble_being_delta * first_being_delta = &(first_being->delta);
        noble_being_events * first_being_events = &(first_being->events);
        noble_being_brain * first_being_brain = &(first_being->braindata);
        noble_immune_system * first_being_immune = &(first_being->immune_system);
        noble_being_volatile * first_being_volatile = &(first_being->changes);
        
        n_uint being_hash1 = math_hash((n_byte *)first_being, sizeof(noble_being));
        n_uint being_constant_hash1 = math_hash((n_byte *)first_being_constant, sizeof(noble_being_constant));
        n_uint being_delta_hash1 = math_hash((n_byte *)first_being_delta, sizeof(noble_being_delta));
        n_uint being_events_hash1 = math_hash((n_byte *)first_being_events, sizeof(noble_being_events));
        n_uint being_brain_hash1 = math_hash((n_byte *)first_being_brain, sizeof(noble_being_brain));
        n_uint being_immune_hash1 = math_hash((n_byte*)first_being_immune, sizeof(noble_immune_system));
        n_uint being_volatile_hash1 = math_hash((n_byte*)first_being_volatile, sizeof(noble_being_volatile));

        while (counter < 1000)
        {
            sim_cycle();
            counter ++;
        }
 
        n_uint being_hash2 = math_hash((n_byte *)first_being, sizeof(noble_being));
        n_uint being_constant_hash2 = math_hash((n_byte *)first_being_constant, sizeof(noble_being_constant));
        n_uint being_delta_hash2 = math_hash((n_byte *)first_being_delta, sizeof(noble_being_delta));
        n_uint being_events_hash2 = math_hash((n_byte *)first_being_events, sizeof(noble_being_events));
        n_uint being_brain_hash2 = math_hash((n_byte *)first_being_brain, sizeof(noble_being_brain));
        n_uint being_immune_hash2 = math_hash((n_byte*)first_being_immune, sizeof(noble_immune_system));
        n_uint being_volatile_hash2 = math_hash((n_byte*)first_being_volatile, sizeof(noble_being_volatile));

        printf("hash %lx\n", being_hash1 ^ being_hash2);
        printf("constant %lx\n", being_constant_hash1 ^ being_constant_hash2);

        printf("delta %lx\n", being_delta_hash1 ^ being_delta_hash2);
        printf("events %lx\n", being_events_hash1 ^ being_events_hash2);

        printf("brain %lx\n", being_brain_hash1 ^ being_brain_hash2);
        printf("immune %lx\n", being_immune_hash1 ^ being_immune_hash2);

        printf("volatile %lx\n", being_volatile_hash1 ^ being_volatile_hash2);

    }
    sim_close();
    
    printf(" --- test sim ---  end  -----------------------------------------------\n");
    
    return 1;
}