/** * Test la fonction tirer_carte, vérifie la validité de la valeur retournée et si chaque carte est bien tirée qu'une seule fois. * @test */ void test_rand_between() { int value; value = rand_between(10, 20); CU_ASSERT(value >= 10 && value <= 20); value = rand_between(0, 5); CU_ASSERT(value >= 0 && value <= 5); value = rand_between(0, 1); CU_ASSERT(value >= 0 && value <= 1); CU_ASSERT(rand_between(1, 1) == 1); }
char *gen_sn() { static char sn[10] = {0}; static char range[3][2] = {{'0','9'}, {'a','z'}, {'A','Z'}}; int i = 0, j = 0; for(i = 0; i < 9; i++) { j = rand_between(0, 2); sn[i] = (char)rand_between((int)range[j][0], (int)range[j][1]); } sn[9] = '0'; printf("%s \n",sn); return sn; }
// arm void particle_system::explode(thing *th, bool kill) { static const unsigned SHOCKWAVE_PARTICLES = 25, DEBRIS_PARTICLES = 75; if (board::current()->thing_lives(th)) { boost::array<vec2, 2*(SHOCKWAVE_PARTICLES + DEBRIS_PARTICLES)> explosion; unsigned i = 0; while (i < 2*SHOCKWAVE_PARTICLES) { float rho = rand_between(64.0, 81.0); float theta = rand_between(0.0, 1.0); explosion[i++] = polar_vec2(rho, rand_near(theta, 0.0625)); explosion[i++] = polar_vec2(rho, rand_near(theta, 0.0625)); } while (i < 2*(SHOCKWAVE_PARTICLES + DEBRIS_PARTICLES)) { float theta = rand_between(0.0, 1.0); explosion[i++] = polar_vec2(rand_between(3.0, 7.0)*rand_between(3.0, 7.0), theta); explosion[i++] = polar_vec2(rand_between(3.0, 7.0)*rand_between(3.0, 7.0), theta); } add_particles(th->center, make_vec2(1.0, 0.0), explosion); if (kill) board::current()->remove_thing(th); } }
static void process_rs(struct Interface *iface, unsigned char *msg, int len, struct sockaddr_in6 *addr) { double delay; double next; struct timespec ts; uint8_t *opt_str; /* validation */ len -= sizeof(struct nd_router_solicit); opt_str = (uint8_t *) (msg + sizeof(struct nd_router_solicit)); while (len > 0) { int optlen; if (len < 2) { flog(LOG_WARNING, "trailing garbage in RS"); return; } optlen = (opt_str[1] << 3); if (optlen == 0) { flog(LOG_WARNING, "zero length option in RS"); return; } else if (optlen > len) { flog(LOG_WARNING, "option length greater than total length in RS"); return; } if (*opt_str == ND_OPT_SOURCE_LINKADDR && IN6_IS_ADDR_UNSPECIFIED(&addr->sin6_addr)) { flog(LOG_WARNING, "received icmpv6 RS packet with unspecified source address and there is a lladdr option"); return; } len -= optlen; opt_str += optlen; } clock_gettime(CLOCK_MONOTONIC, &ts); delay = MAX_RA_DELAY_TIME * rand() / (RAND_MAX + 1.0); if (iface->UnicastOnly) { send_ra_forall(iface, &addr->sin6_addr); } else if (timespecdiff(&ts, &iface->last_multicast) / 1000.0 < iface->MinDelayBetweenRAs) { /* last RA was sent only a few moments ago, don't send another immediately. */ next = iface->MinDelayBetweenRAs - (ts.tv_sec + ts.tv_nsec / 1000000000.0) + (iface->last_multicast.tv_sec + iface->last_multicast.tv_nsec / 1000000000.0) + delay / 1000.0; iface->next_multicast = next_timespec(next); } else { /* no RA sent in a while, send a multicast reply */ send_ra_forall(iface, NULL); next = rand_between(iface->MinRtrAdvInterval, iface->MaxRtrAdvInterval); iface->next_multicast = next_timespec(next); } }
void Benchmark::generate(int nVars, int nDoms, int nJoins) { this->nVars = nVars; this->nDoms = nDoms; this->nJoins = nJoins; srand(time(NULL)); // new seed intervals.resize(nDoms); relations.resize(nDoms); joins.resize(nJoins); int i,j,sRels,v,a,b; for (i=0;i<nDoms;++i) { intervals[i].resize(nVars); for (v=0;v<nVars;++v) if (rand_between(0,100) <= 80) { intervals[i][v].first = rand_between(0,1024); intervals[i][v].second = rand_between(intervals[i][v].first, intervals[i][v].first+1024); } else { // bottom intervals[i][v].first = 1; intervals[i][v].second = 0; } sRels = nVars * nVars; sRels = rand_between((int)(0.1 * (double)sRels), (int)(0.25 * (double)sRels)); // density relations[i].resize(sRels); for (j=0;j<sRels;++j) { a = rand_between(0, nVars); b = rand_between(0, nVars); if (intervals[i][a].first > intervals[i][a].second || intervals[i][b].first > intervals[i][b].second) // one of them is bottom continue; if (intervals[i][a].first > intervals[i][b].second) // cannot be the case: a < b continue; relations[i][j] = pair<int,int>(a,b); } } j = 0; while (j < nJoins) { a = rand_between(0, nDoms); b = rand_between(0, nDoms); if (a != b) { joins[j] = pair<int,int>(a,b); ++j; } } }
void greedy_parallel(int pid) { int nodes, node, i, tmp; int color, othernode; MPI_Status status; MPI_Request req; int * indexes, *colors, *madjacency; PblSet * psetcolors = (PblSet *) pblSetNewHashSet(); MPI_Recv( &nodes, 1, MPI_INT, 0, TAG, MPI_COMM_WORLD, &status ); //printf("[rank %d] NODES: %d\n", pid, nodes); srand( time(NULL) / pid ); indexes = (int*) malloc(nodes*sizeof(int)); colors = (int*) malloc(nodes*sizeof(int)); madjacency = (int*) malloc(nodes*nodes*sizeof(int)); MPI_Recv(madjacency, nodes*nodes, MPI_INT, 0, TAG, MPI_COMM_WORLD, &status); for (i = 0; i < nodes; i++) indexes[i] = i; for (i = nodes-1; i >= 0; i--) { tmp = rand_between(0, i); node = indexes[tmp]; indexes[tmp] = indexes[i]; pblSetClear(psetcolors); for (othernode = 0; othernode < nodes; othernode++) { if (othernode != node) { if (madjacency[POS(othernode, node, nodes)] == 1) { if (colors[othernode] != 0) /* the neighbor already has a color */ pblSetAdd(psetcolors, (void *) colors[othernode]); } } } colors[node] = find_my_color(psetcolors, nodes); } //printf("[rank %d] colors = ", pid); //for (i = 0; i < nodes; i++) // printf(" %d", colors[i]); //printf("\n"); MPI_Send(colors, nodes, MPI_INT, 0, TAG, MPI_COMM_WORLD); }
static void raft_reset_timer(raft_t r) { if (r->role == LEADER) { r->timer = r->config.heartbeat_ms; } else { r->timer = rand_between( r->config.election_ms_min, r->config.election_ms_max ); } }
void oxygarum_init_particle_shader(void) { // create noise-texture int i; for(i = 0; i < 1024; i++) { random_buffer[i] = rand_between(0.0f, 1.0f); } glGenTextures(1, &rand_tex_id); glBindTexture(GL_TEXTURE_1D, rand_tex_id); glTexImage1D(GL_TEXTURE_1D, 0, 4, 256, 0, GL_RGBA, GL_FLOAT, &random_buffer); glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_T, GL_REPEAT); // load shaders GLuint vertexshader = oxygarum_create_shader(GL_VERTEX_SHADER, particle_vertexshader, strlen(particle_vertexshader)); particle_program = glCreateProgram(); glAttachShader(particle_program, vertexshader); const char *varyings[] = {"pos","vel","lifetime","size","color","seed_off"}; glTransformFeedbackVaryings(particle_program, 6, varyings, GL_INTERLEAVED_ATTRIBS); glBindAttribLocation(particle_program, 0, "Pos"); glBindAttribLocation(particle_program, 1, "Vel"); glBindAttribLocation(particle_program, 2, "Lifetime"); glBindAttribLocation(particle_program, 3, "Size"); glBindAttribLocation(particle_program, 4, "Color"); glBindAttribLocation(particle_program, 5, "Seed_off"); oxygarum_link_program(particle_program); loc_rand_tex = glGetUniformLocation(particle_program, "rand_tex"); loc_seed0 = glGetUniformLocation(particle_program, "seed0"); loc_seed1 = glGetUniformLocation(particle_program, "seed1"); loc_seed2 = glGetUniformLocation(particle_program, "seed2"); loc_aspeed = glGetUniformLocation(particle_program, "aspeed"); loc_spawn_point = glGetUniformLocation(particle_program, "spawn_point"); loc_gvector = glGetUniformLocation(particle_program, "gvector"); loc_gvertex = glGetUniformLocation(particle_program, "gvertex"); loc_gspeed = glGetUniformLocation(particle_program, "gspeed"); loc_pos_min = glGetUniformLocation(particle_program, "pos_min"); loc_pos_max = glGetUniformLocation(particle_program, "pos_max"); loc_vel_min = glGetUniformLocation(particle_program, "vel_min"); loc_vel_max = glGetUniformLocation(particle_program, "vel_max"); loc_col_min = glGetUniformLocation(particle_program, "col_min"); loc_col_max = glGetUniformLocation(particle_program, "col_max"); loc_life_min = glGetUniformLocation(particle_program, "life_min"); loc_life_max = glGetUniformLocation(particle_program, "life_max"); }
static void mi_shuffle_announce(struct mi_announce *ann) { for (int i = 0; i < ann->ntiers; i++) { for (int j = 0; j < ann->tiers[i].nurls - 1; j++) { char *tmp = ann->tiers[i].urls[j]; int ri = rand_between(j, ann->tiers[i].nurls - 1); ann->tiers[i].urls[j] = ann->tiers[i].urls[ri]; ann->tiers[i].urls[ri] = tmp; } } }
static void timer_handler(int sock, struct Interface *iface) { dlog(LOG_DEBUG, 1, "timer_handler called for %s", iface->props.name); if (send_ra_forall(sock, iface, NULL) != 0) { dlog(LOG_DEBUG, 4, "send_ra_forall failed on interface %s", iface->props.name); } double next = rand_between(iface->MinRtrAdvInterval, iface->MaxRtrAdvInterval); reschedule_iface(iface, next); }
int main(int argc,const char *argv[]){ // set seed for random number generator unsigned int seed = (unsigned int)time(NULL); srand(seed); //printf("%d\n",seed); // what is the starting string char target[]="Target string"; length = (int)strlen(target); // use length of string function, cast it as an int because otherwise it's an unsigned int //strlen doesn't include the /0 in the length of the string //make a random starting sequence of letters char *startString = malloc((length+1)*sizeof(char)); /// BECAUSE strlen doesn't include the /0 in the length of the string int i; for(i=0; i < length; i++){ startString[i]= randChar(); } startString[length]='\0'; /// BECAUSE the array starts with a zero and goes to length (rather than length-1) then we just put the null character in there int muts = 0; //how many mutations happen to get to the target sequence int mutationsAtMismatches; while(stringEval(startString, target)>0){ // evolve the string of characters //mutate int site; do{ site = rand_between(length); muts++; }while(startString[site]==target[site]); startString[site]=randChar(); //evaluate how close the two strings are -- Hamming distance ( sum over units for if 1 when units are different and 0 if same ) //--inherent in the loop //decide --inherent in the loop //stop when we get the phrase we want--inherent in the loop mutationsAtMismatches++; printf("%s \n", startString); //Print mutations to console as they happen } printf("Number of mutations to target= %d \n", mutationsAtMismatches); //print the number of steps it takes to get to the target sequence }
void radvd_timer_handler(void *data) { struct Interface *iface = (struct Interface *) data; double next; dlog(LOG_DEBUG, 4, "timer_handler called for %s", iface->Name); send_ra(sock, iface, NULL); next = rand_between(iface->MinRtrAdvInterval, iface->MaxRtrAdvInterval); if (iface->init_racount < MAX_INITIAL_RTR_ADVERTISEMENTS) { iface->init_racount++; next = min(MAX_INITIAL_RTR_ADVERT_INTERVAL, next); } set_timer(&iface->tm, next); }
void timer_handler(void *data) { struct Interface *iface = (struct Interface *) data; double next; dlog(LOG_DEBUG, 4, "timer_handler called for %s", iface->Name); if (send_ra_forall(iface, NULL) != 0) { return; } next = rand_between(iface->MinRtrAdvInterval, iface->MaxRtrAdvInterval); if (iface->init_racount < MAX_INITIAL_RTR_ADVERTISEMENTS) { iface->init_racount++; next = min(MAX_INITIAL_RTR_ADVERT_INTERVAL, next); } iface->next_multicast = next_timeval(next); }
char randChar(){ //produce a random character, to: 1. mutate and 2. to create our initial random sequence char finalChar; int choices = 26*2+4; //length of our library of all possible characters, see comments in MAIN int draw = rand_between(choices-1); // minus 1 because 52 is going from 0 to 51 //make letters out of the numbers we drew if(draw < 26) finalChar = 'a'+draw; // so 0-25 in our library is now lowercase a-z else if(draw < 52) finalChar = 'A'+(draw-26);//if 26-51, then it's an uppercase letter A-Z else{ //use a switch statement, in some situations, where there are lots of choices, it's better than a bunch of if statements switch(draw){ //C will look at draw and then proceed into one of the things following in the curly brackets //so these are all case statements: case, value of draw, colon, do everything here case 52: finalChar = '\''; // need to escape into the apostrophe because otherwise C would read it as a single quote break; // NEED these here because the switch statement goes to the matching 'case' then proceeds through all following unless the breaks stop it case 53: finalChar = '!'; break; case 54: finalChar = ' '; break; case 55: finalChar = '.'; break; } } return(finalChar); }
void oxygarum_update_particle_system(particle_emitter_t *emitter, float frametime) { GLint swp = emitter->input; emitter->input = emitter->output; emitter->output = swp; glEnable(GL_RASTERIZER_DISCARD); glUseProgram(particle_program); glBindBuffer(GL_ARRAY_BUFFER, emitter->particle_buffer[emitter->input]); glEnable(GL_TEXTURE_1D); glBindTexture(GL_TEXTURE_1D, rand_tex_id); glUniform1i(loc_rand_tex, 0); glUniform1f(loc_seed0, rand_between(0.0f, 256.0f)); glUniform1f(loc_seed1, rand_between(0.0f, 256.0f)); glUniform1f(loc_seed2, rand_between(0.0f, 256.0f)); glUniform1f(loc_aspeed, (GLfloat)frametime); glUniform3fv(loc_spawn_point, 1, &emitter->spawn_point); glUniform3fv(loc_gvector, 1, &emitter->gravity_vector); glUniform3fv(loc_gvertex, 1, &emitter->gravity_vertex); glUniform1f(loc_gspeed, (GLfloat)emitter->gravity_speed); glUniform3fv(loc_pos_min, 1, &emitter->borders[0].pos); glUniform3fv(loc_pos_max, 1, &emitter->borders[1].pos); glUniform3fv(loc_vel_min, 1, &emitter->borders[0].velocity); glUniform3fv(loc_vel_max, 1, &emitter->borders[1].velocity); glUniform4fv(loc_col_min, 1, &emitter->borders[0].color); glUniform4fv(loc_col_max, 1, &emitter->borders[1].color); glUniform1fv(loc_life_min, 1, &emitter->borders[0].lifetime); glUniform1fv(loc_life_max, 1, &emitter->borders[1].lifetime); glEnableVertexAttribArray(0); glEnableVertexAttribArray(1); glEnableVertexAttribArray(2); glEnableVertexAttribArray(3); glEnableVertexAttribArray(4); glEnableVertexAttribArray(5); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(particle_t), 0x00); // position glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(particle_t), 0x0C); // velocity glVertexAttribPointer(2, 1, GL_FLOAT, GL_FALSE, sizeof(particle_t), 0x18); // lifetime glVertexAttribPointer(3, 1, GL_FLOAT, GL_FALSE, sizeof(particle_t), 0x1C); // size glVertexAttribPointer(4, 4, GL_FLOAT, GL_FALSE, sizeof(particle_t), 0x20); // color glVertexAttribPointer(5, 1, GL_FLOAT, GL_FALSE, sizeof(particle_t), 0x30); // seed_off glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, emitter->particle_buffer[emitter->output]); glBeginTransformFeedback(GL_POINTS); glDrawArrays(GL_POINTS, NULL, emitter->particle_counter); glEndTransformFeedback(); glDisableVertexAttribArray(0); glDisableVertexAttribArray(1); glDisableVertexAttribArray(2); glDisableVertexAttribArray(3); glDisableVertexAttribArray(4); glDisableVertexAttribArray(5); glUseProgram(0); glDisable(GL_RASTERIZER_DISCARD); }
static void process_rs(int sock, struct Interface *iface, unsigned char *msg, int len, struct sockaddr_in6 *addr) { double delay; double next; struct timeval tv; uint8_t *opt_str; /* validation */ len -= sizeof(struct nd_router_solicit); opt_str = (uint8_t *)(msg + sizeof(struct nd_router_solicit)); while (len > 0) { int optlen; if (len < 2) { flog(LOG_WARNING, "trailing garbage in RS"); return; } optlen = (opt_str[1] << 3); if (optlen == 0) { flog(LOG_WARNING, "zero length option in RS"); return; } else if (optlen > len) { flog(LOG_WARNING, "option length greater than total length in RS"); return; } if (*opt_str == ND_OPT_SOURCE_LINKADDR && IN6_IS_ADDR_UNSPECIFIED(&addr->sin6_addr)) { flog(LOG_WARNING, "received icmpv6 RS packet with unspecified source address and there is a lladdr option"); return; } len -= optlen; opt_str += optlen; } gettimeofday(&tv, NULL); delay = MAX_RA_DELAY_TIME*rand()/(RAND_MAX+1.0); dlog(LOG_DEBUG, 3, "random mdelay for %s: %.2f", iface->Name, delay); if (iface->UnicastOnly) { mdelay(delay); send_ra(sock, iface, &addr->sin6_addr); } else if ((tv.tv_sec + tv.tv_usec / 1000000.0) - (iface->last_multicast_sec + iface->last_multicast_usec / 1000000.0) < iface->MinDelayBetweenRAs) { /* last RA was sent only a few moments ago, don't send another immediately */ clear_timer(&iface->tm); next = iface->MinDelayBetweenRAs - (tv.tv_sec + tv.tv_usec / 1000000.0) + (iface->last_multicast_sec + iface->last_multicast_usec / 1000000.0) + delay/1000.0; set_timer(&iface->tm, next); } else { /* no RA sent in a while, send an immediate multicast reply */ clear_timer(&iface->tm); send_ra(sock, iface, NULL); next = rand_between(iface->MinRtrAdvInterval, iface->MaxRtrAdvInterval); set_timer(&iface->tm, next); } }
int rand_under(int upper) { return rand_between(0, upper); }
int main(void) { /* Zero an array. */ { double d[2]; d[0] = 1.0; d[1] = 2.0; ZERO_ARRAY(d); /* Pass pointer to array. */ printf("d[0] = %f\n", d[0]); printf("d[1] = %f\n", d[1]); printf("\n"); } /* Zero a struct. */ { struct stuff st; st.d[0] = 1.0; st.d[1] = 2.0; st.str[0] = 'O'; st.str[1] = 'K'; st.str[2] = '\n'; st.str[3] = '\0'; st.x = -5; ZERO_STRUCT(&st); /* Pass pointer to struct. */ printf("st.d[0] = %f\n", st.d[0]); printf("st.d[1] = %f\n", st.d[1]); printf("st.str = \"%s\"\n", st.str); printf("st.x = %d\n", st.x); printf("\n"); } /* Count array length. */ { double d[3]; printf("length = %d\n", COUNT_ARRAY(d)); printf("\n"); } /* Test maximum. */ { int a = 4; int b = 5; printf("max = %d\n", MAX(a, b)); printf("max = %d\n", MAX(b, a)); printf("\n"); } /* Test strcmp. */ { char a[] = "ab"; char b[] = "abd"; printf("strcmp = %d\n", strcmp(a, b)); printf("\n"); } /* Test strlen. */ { char a[] = "ab\n"; char b[] = ""; printf("strlen = %d\n", strlen(a)); /* = 3 */ printf("strlen = %d\n", strlen(b)); /* = 0 */ printf("\n"); } /* Test strcpy. */ { char dst[20] = ""; char src[20] = "baba"; printf("strcpy = %s\n", strcpy(dst, src)); printf("\n"); } /* Test memset. */ { char dst[20] = ""; printf("memset = %s\n", (char *)memset(dst, 97, sizeof(dst)-1)); printf("\n"); } /* Test FILL_ARRAY. */ { int arr[2]; size_t i = 0; uint8_t *byte = (uint8_t *)arr; FILL_ARRAY(arr, 0xba); printf("arr[0] = %d\n", arr[0]); printf("arr[1] = %d\n", arr[1]); for (i = 0; i < sizeof(arr); ++i) { printf("arr as byte[%d] = 0x%x\n", i, *byte++); } printf("\n"); } /* Test atoi. */ { char str[] = "0123456789"; char str1[] = "-489"; char str2[] = " 9 white space"; char str3[] = "--5"; char str4[] = ""; printf("%s = %d\n", str, atoi(str)); printf("%s = %d\n", str1, atoi(str1)); printf("%s = %d\n", str2, atoi(str2)); printf("%s = %d\n", str3, atoi(str3)); printf("%s = %d\n", str4, atoi(str4)); printf("\n"); } /* Test strchar. */ { char str[] = "0123456789"; printf("%s\n", strchr(str,'5')); printf("%s\n", strchr(str,'1')); printf("\n"); } /* Test rand. */ { size_t i = 0; for (i = 0; i < 5; ++i) { printf("rand() = %d\n", rand()); } for (i = 0; i < 10; ++i) { printf("rand_between(1, 3) = %d\n", rand_between(1, 3)); } while (rand() != 0) { } while (rand() != RAND_MAX) { } printf("\n"); } return 0; }
void generate_maze() { short row, column, nb_room, i; Rectangle * rooms; Direction direction; if (g_maze == NULL) { g_maze = malloc(sizeof(Maze)); g_maze->size = MIN_SIZE; } else { free_squares(); g_maze->size *= GROWING_SPEED; } g_maze->squares = malloc(g_maze->size * g_maze->size * sizeof(Square)); //génération //remplissage par des murs for (row = 0 ; row < g_maze->size ; row++) { for (column = 0 ; column < g_maze->size ; column++) { g_maze->squares[row * g_maze->size + column].type = WALL; g_maze->squares[row * g_maze->size + column].entity = NULL; } } //choix du nombre de pièces... //nb_room = rand_between(1 + g_maze->size / 15, (1 + g_maze->size / 15) + (((g_maze->size % 15) > 7) ? rand_between(0, 1) : 0)); nb_room = 1; rooms = malloc(sizeof(Rectangle) * nb_room); //première pièce i = 0; if (rand_boolean()) { rooms[i].a.row = 1; rooms[i].a.column = rand_between(1, g_maze->size / 7); rooms[i].c.row = rand_between(3, g_maze->size / nb_room - 2); rooms[i].c.column = rand_between(rooms[i].a.column + 1, g_maze->size / nb_room - 2); g_maze->door = g_maze->squares + rand_between(rooms[i].a.column, rooms[i].c.column); } else { rooms[i].a.row = rand_between(1, g_maze->size / 7); rooms[i].a.column = 1; rooms[i].c.row = rand_between(rooms[i].a.row + 1, g_maze->size / nb_room - 2); rooms[i].c.column = rand_between(3, g_maze->size / nb_room - 2); g_maze->door = g_maze->squares + g_maze->size * rand_between(rooms[i].a.column, rooms[i].c.column); } g_maze->door->type = AIR; if (((rooms[i].c.row - rooms[i].a.row) == 2) && (rand_boolean() || rand_boolean())) { rooms[i].c.row++; } if (((rooms[i].c.column - rooms[i].a.column) == 2) && (rand_boolean() || rand_boolean())) { rooms[i].c.column++; } if (((rooms[i].c.row - rooms[i].a.row) <= 3) && (rand_boolean())) { rooms[i].c.row++; } if (((rooms[i].c.column - rooms[i].a.column) <= 3) && (rand_boolean())) { rooms[i].c.column++; } /*//dernière pièce i = nb_room - 1; if (rand_boolean()) { rooms[i].c.row = g_maze->size - 2; rooms[i].c.column = rand_between(g_maze->size - 1 - g_maze->size / 7, g_maze->size - 2); rooms[i].a.row = rand_between(g_maze->size - 1 - g_maze->size / nb_room + 2, g_maze->size - 4); rooms[i].a.column = rand_between(g_maze->size - 1 - g_maze->size / nb_room + 2, rooms[i].c.column - 1); } else { rooms[i].c.row = rand_between(g_maze->size - 1 - g_maze->size / 7, g_maze->size - 2); rooms[i].c.column = g_maze->size - 2; rooms[i].a.row = rand_between(g_maze->size - 1 - g_maze->size / nb_room + 2, rooms[i].c.row - 1); rooms[i].a.column = rand_between(g_maze->size - 1 - g_maze->size / nb_room + 2, g_maze->size - 4); } if (((rooms[i].c.row - rooms[i].a.row) == 2) && (rand_boolean() || rand_boolean())) { rooms[i].a.row--; } if (((rooms[i].c.column - rooms[i].a.column) == 2) && (rand_boolean() || rand_boolean())) { rooms[i].a.column--; } if (((rooms[i].c.row - rooms[i].a.row) <= 3) && (rand_boolean())) { rooms[i].a.row--; } if (((rooms[i].c.column - rooms[i].a.column) <= 3) && (rand_boolean())) { rooms[i].a.column--; }*/ // for (i = 1 ; i < nb_room ; i++) { } // for(i = 0; i < nb_room; i++) { for (row = rooms[i].a.row ; row <= rooms[i].c.row ; row++) { for (column = rooms[i].a.column ; column <= rooms[i].c.column ; column++) { g_maze->squares[row * g_maze->size + column].type = AIR; } } } //choix de leur taille et de leur placement... //génération des couloirs }