示例#1
0
npc::npc(dungeon_t *d, const monster_description &m)
{
  pair_t p;
  uint32_t room;

  symbol = m.symbol;
  color = m.color;
  room = rand_range(1, d->num_rooms - 1);
  do {
    p[dim_y] = rand_range(d->rooms[room].position[dim_y],
                          (d->rooms[room].position[dim_y] +
                           d->rooms[room].size[dim_y] - 1));
    p[dim_x] = rand_range(d->rooms[room].position[dim_x],
                          (d->rooms[room].position[dim_x] +
                           d->rooms[room].size[dim_x] - 1));
  } while (d->charmap[p[dim_y]][p[dim_x]]);
  pc_last_known_position[dim_y] = p[dim_y];
  pc_last_known_position[dim_x] = p[dim_x];
  position[dim_y] = p[dim_y];
  position[dim_x] = p[dim_x];
  d->charmap[p[dim_y]][p[dim_x]] = this;
  speed = m.speed.roll();
  hp = m.hitpoints.roll();
  damage = &m.damage;
  bounty = (hp + damage->roll()) / 10; //Bounty
  level = m.level;
  next_turn = d->the_pc->next_turn;
  alive = 1;
  sequence_number = ++d->character_sequence_number;
  characteristics = m.abilities;
  have_seen_pc = 0;
  name = m.name.c_str();
  description = (const char *) m.description.c_str();
}
示例#2
0
void tm_rect_generate_overlapping( tm_rect_t* r, tm_rect_t* overlap_r, tm_vect_t* sz, vect_t* map_sz )
{
	tm_vect_t* unit = tm_vect_create(1, 1);
	tm_rect_t aux_r;

	tm_vect_substract( &overlap_r->v1, sz, &aux_r.v1 );
	tm_vect_add( &aux_r.v1, unit, &aux_r.v1 );
	if( (int) aux_r.v1.x < 0 )
		aux_r.v1.x = 0;
	if( (int) aux_r.v1.y < 0 )
		aux_r.v1.y = 0;

	tm_vect_substract( &overlap_r->v2, unit, &aux_r.v2 );
	tm_vect_add( &aux_r.v2, sz, &aux_r.v2 );
	if( (int) aux_r.v2.x > map_sz->x )
		aux_r.v2.x = map_sz->x;
	if( (int) aux_r.v2.y > map_sz->y )
		aux_r.v2.y = map_sz->y;

	assert( rect_is_valid(&aux_r) );

	tm_vect_init( &r->v1, rand_range((int)aux_r.v1.x, (int)aux_r.v2.x), rand_range((int)aux_r.v1.y, (int)aux_r.v2.y) );
	tm_vect_add( &r->v1, sz, &r->v2 );

	tm_vect_destroy( unit );
}
示例#3
0
/**
 * Return the number of things dropped by a monster.
 *
 * \param race is the monster race.
 * \param maximize should be set to false for a random number, true to find
 * out the maximum count.
 */
int mon_create_drop_count(const struct monster_race *race, bool maximize)
{
	int number = 0;
	static const int drop_4_max = 6;
	static const int drop_3_max = 4;
	static const int drop_2_max = 3;

	if (maximize) {
		if (rf_has(race->flags, RF_DROP_20)) number++;
		if (rf_has(race->flags, RF_DROP_40)) number++;
		if (rf_has(race->flags, RF_DROP_60)) number++;
		if (rf_has(race->flags, RF_DROP_4)) number += drop_4_max;
		if (rf_has(race->flags, RF_DROP_3)) number += drop_3_max;
		if (rf_has(race->flags, RF_DROP_2)) number += drop_2_max;
		if (rf_has(race->flags, RF_DROP_1)) number++;
	} else {
		if (rf_has(race->flags, RF_DROP_20) && randint0(100) < 20) number++;
		if (rf_has(race->flags, RF_DROP_40) && randint0(100) < 40) number++;
		if (rf_has(race->flags, RF_DROP_60) && randint0(100) < 60) number++;
		if (rf_has(race->flags, RF_DROP_4)) number += rand_range(2, drop_4_max);
		if (rf_has(race->flags, RF_DROP_3)) number += rand_range(2, drop_3_max);
		if (rf_has(race->flags, RF_DROP_2)) number += rand_range(1, drop_2_max);
		if (rf_has(race->flags, RF_DROP_1)) number++;
	}

	return number;
}
示例#4
0
int main(int argc, char** argv) {
  lightDirection.normalize();

  srand((unsigned) time(NULL));

  // 球体をランダムに配置
  for(int i = 0; i < sphere_n; i++) {
    double r = rand_range(50,200);
    Vector3d center(rand_range(-500,500), r, rand_range(-1000,0));
    //Vector3d color = HSVtoRGB( (360.0/sphere_n)*i, 255, 255);
    Vector3d color = HSVtoRGB( rand_range(0,360), 255, 255);
    sphere[i] = Sphere(center, r, color);
  }

  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
  glutInitWindowSize(600,600);
  glutInitWindowPosition(180,10);
  glutCreateWindow(argv[0]);
  glClearColor(1.0, 1.0, 1.0, 1.0);
  glShadeModel(GL_FLAT);

  glutDisplayFunc(display);
  glutReshapeFunc(resizeWindow);
  glutKeyboardFunc(keyboard);
  glutMainLoop();

  return 0;
}
示例#5
0
static void
make_map(void) {
    int w = WIDTH;
    int h = HEIGHT;
    float deviance;

    //Reset the whole heightmap to the minimum height
    for (int e = 0; e < HEIGHT; ++e)
        for (int i = 0; i < WIDTH; ++i)
            heightmap[i][e] = MINHEIGHT;

    //Add our starting corner points
    heightmap[0][0] = rand_range(-RANGE_CHANGE, RANGE_CHANGE);
    heightmap[0][HEIGHT] = rand_range(-RANGE_CHANGE, RANGE_CHANGE);

    deviance = 1.0;
    while (1) {
        draw_all_squares(w, h, deviance);
        draw_all_diamonds(w, h, deviance);

        w /= 2;
        h /= 2;

        if (w < 2 && h < 2)
            break;

        if (w < 2)
            w = 2;
        if (h < 2)
            h = 2;
        deviance *= REDUCTION;
    }
}
示例#6
0
文件: predictors.c 项目: xurban46/bc
/**
 * Genome mutation function
 *
 * Recalculates phenotype if necessary
 *
 * @param  genes
 * @return
 */
void pred_mutate(pred_genome_t genome)
{
    int max_changed_genes = _metadata->mutation_rate * _metadata->genotype_length;
    int genes_to_change = rand_range(0, max_changed_genes);

    for (int i = 0; i < genes_to_change; i++) {
        // choose mutated gene
        int gene = rand_range(0, _metadata->genotype_length - 1);
        pred_gene_t old_value = genome->_genes[gene];

        // generate new value
        pred_gene_t value = rand_urange(0, _metadata->max_gene_value);
        if (_metadata->genome_type == permuted) {
            // either unused or same value is valid, so make corrections
            while(genome->_used_values[value] && old_value != value) {
                value = (value + 1) % (_metadata->max_gene_value + 1);
            };
        }

        // rewrite gene
        genome->_genes[gene] = value;
        genome->_used_values[value] = true;
    }

    pred_calculate_phenotype(genome);
}
示例#7
0
uint32_t io_teleport_pc(dungeon_t *d)
{
  /* Just for fun. */
  pair_t dest;

  do {
    dest[dim_x] = rand_range(1, DUNGEON_X - 2);
    dest[dim_y] = rand_range(1, DUNGEON_Y - 2);
  } while (charpair(dest));

  d->charmap[character_get_y(d->pc)][character_get_x(d->pc)] = NULL;
  d->charmap[dest[dim_y]][dest[dim_x]] = d->pc;

  character_set_y(d->pc, dest[dim_y]);
  character_set_x(d->pc, dest[dim_x]);

  if (mappair(dest) < ter_floor) {
    mappair(dest) = ter_floor;
  }

  pc_observe_terrain(d->pc, d);

  dijkstra(d);
  dijkstra_tunnel(d);

  return 0;
}
示例#8
0
// converts a dead person in black particles
void Person::burn()
{
  GamePlay *gameplay = GAMEPLAY;
  BITMAP *sprite = prepare_sprite();
  int x, y, u, v;

  gameplay->get_level()->to_screen(m_pos, x, y);

  x = x-TILE_W/2;
  y = y-TILE_H+1;

  for (v=0; v<sprite->h; ++v)
    for (u=0; u<sprite->w; ++u) {
      int color, ou;

      if (m_right)
	color = getpixel(sprite, ou=u, v);
      else
	color = getpixel(sprite, ou=sprite->w-1-u, v);

      if (color != bitmap_mask_color(sprite))
	gameplay->add_particle
	  (new PixelParticle(vector2d((m_pos.x*TILE_W - TILE_W/2 + ou) / TILE_W,
				      (m_pos.y*TILE_H - TILE_H+1 + v) / TILE_H),
			     vector2d(0, rand_range(-2.0, -0.1)),
			     vector2d(rand_range(0.5, 4.0), 0),
			     rand_range(BPS/4, BPS*3/4),
			     makecol(0, 0, 0),
			     makecol(0, 0, 0)));

    }
}
示例#9
0
文件: snake.cpp 项目: taganaka/snake
    void Snake::setAppleLocation() {
        if (!needFood)
            return;
        int x;
        int y;

        while(true){

            x = rand_range(10, wW - 10);
            if (x % 10 != 0)
                x -= (x % 10);

            y = rand_range(windowOffset, wH - 10);
            if (y % 10 != 0)
                y -= (y % 10);

            bool allowed = true;
            for (std::list<Location>::const_iterator it = locations.begin(), end = locations.end(); it != end; ++it) {
                if ((*it).x == x && (*it).y == y){
                    allowed = false;
                    break;
                }
            }
            if (allowed)
                break;
        }


        foodLocation.x = x;
        foodLocation.y = y;
        needFood = false;

    }
示例#10
0
void generate_world(World* world, Tile_Info* info, isize ti_count, uint64 seed, Memory_Arena* arena)
{
	Random r_s;
	Random* r = &r_s;
	init_random(r, seed);


	for(isize i = 0; i < world->areas_height; ++i) {
		for(isize j = 0; j < world->areas_width; ++j) {
			isize index = i * world->areas_width + j;
			World_Area* area = world->areas + index;
			init_world_area(area, arena);
			area->map.info = info;
			area->map.info_count = ti_count;
			generate_tilemap(&area->map, next_random_uint64(r));
			for(isize i = 0; i < World_Area_Tilemap_Width; ++i) {
				Entity* e = world_area_get_next_entity(area);
				Sim_Body* b = sim_find_body(&area->sim, e->body_id);
				e->sprite.texture = Get_Texture_Coordinates(0, 96, 32, 64);
				b->shape.hw = 16;
				b->shape.hh = 12;
				b->inv_mass = 1.0f;
				e->sprite.size = v2(32, 64);
				e->sprite.center = v2(0, 20);
				entity_add_event_on_activate(e, test_on_activate);
				do {
					b->shape.center = v2(
						rand_range(r, 0, area->map.w * 32),
						rand_range(r, 0, area->map.h * 32));
				}
				while (info[tilemap_get_at(&area->map, b->shape.center)].solid);
			}

			generate_statics_for_tilemap(&area->sim, &area->map);

			isize north_link = modulus(i - 1, world->areas_height) * world->areas_width + j;
			isize south_link = modulus(i + 1, world->areas_height) * world->areas_width + j;
			isize west_link = i * world->areas_width + modulus(j - 1, world->areas_width);
			isize east_link = i * world->areas_width + modulus(j + 1, world->areas_width);
			area->north = Area_Link {
				v2i(World_Area_Tilemap_Width / 2,  World_Area_Tilemap_Height - 1), 
				world->areas + north_link
			};
			area->south = Area_Link {
				v2i(World_Area_Tilemap_Width / 2, 1),
				world->areas + south_link
			};
			area->west = Area_Link {
				v2i(World_Area_Tilemap_Width - 1, World_Area_Tilemap_Height / 2),
				world->areas + west_link
			};
			area->east = Area_Link {
				v2i(1, World_Area_Tilemap_Height / 2),
				world->areas + east_link
			};
		}
	}

}
示例#11
0
文件: Light.c 项目: alunbestor/Brogue
void paintLight(lightSource *theLight, short x, short y, boolean isMinersLight) {
	short i, j, k;
	short colorComponents[3], randComponent, lightMultiplier, thisComponent;
	short fadeToPercent;
	float radius;
	char grid[DCOLS][DROWS];
	boolean dispelShadows;
	
#ifdef BROGUE_ASSERTS
	assert(rogue.RNG == RNG_SUBSTANTIVE);
#endif
	
	radius = randClump(theLight->lightRadius);
	radius /= 100;
	
	randComponent = rand_range(0, theLight->lightColor->rand);
	colorComponents[0] = randComponent + theLight->lightColor->red + rand_range(0, theLight->lightColor->redRand);
	colorComponents[1] = randComponent + theLight->lightColor->green + rand_range(0, theLight->lightColor->greenRand);
	colorComponents[2] = randComponent + theLight->lightColor->blue + rand_range(0, theLight->lightColor->blueRand);
	
	// the miner's light does not dispel IS_IN_SHADOW,
	// so the player can be in shadow despite casting his own light.
	dispelShadows = !isMinersLight && colorComponents[0] + colorComponents[1] + colorComponents[2] > 0;
	
	fadeToPercent = theLight->radialFadeToPercent;
	
	// zero out only the relevant rectangle of the grid
	for (i = max(0, x - radius); i < DCOLS && i < x + radius; i++) {
		for (j = max(0, y - radius); j < DROWS && j < y + radius; j++) {
			grid[i][j] = 0;
		}
	}
	
	getFOVMask(grid, x, y, radius, T_OBSTRUCTS_VISION, (theLight->passThroughCreatures ? 0 : (HAS_MONSTER | HAS_PLAYER)),
			   (!isMinersLight));
	
	for (i = max(0, x - radius); i < DCOLS && i < x + radius; i++) {
		for (j = max(0, y - radius); j < DROWS && j < y + radius; j++) {
			if (grid[i][j]) {
				lightMultiplier = 100 - (100 - fadeToPercent) * (sqrt((i-x) * (i-x) + (j-y) * (j-y)) / (radius));
				for (k=0; k<3; k++) {
						thisComponent = colorComponents[k] * lightMultiplier / 100;
						tmap[i][j].light[k] += thisComponent;
				}
				if (dispelShadows) {
					pmap[i][j].flags &= ~IS_IN_SHADOW;
				}
			}
		}
	}
	
	tmap[x][y].light[0] += colorComponents[0];
	tmap[x][y].light[1] += colorComponents[1];
	tmap[x][y].light[2] += colorComponents[2];
	
	if (dispelShadows) {
		pmap[x][y].flags &= ~IS_IN_SHADOW;
	}
}
示例#12
0
void PE_Torpedo_Explosion::emit_single_particle(Particle& p)
{
  p.cur_pos = lerp(RAND_0_1,m_p1,m_p2) + vec2(RAND_0_1 * 0.002f, RAND_0_1 * 0.002f);
	p.cur_speed = normalized(vec2(RAND_1_1,RAND_1_1))*rand_range(0.01,0.1);
	p.cur_size = 0.0;
  float col = rand_range(0.0,0.1);
	p.cur_color = vec4(col,col,col,1);
}
int main()
{
  char keyboard_input[100];
  XColor black_col,white_col,red_col,green_col,blue_col,yellow_col,magenta_col,cyan_col;
  Colormap colormap;
  char black_bits[] = "#000000";
  char white_bits[] = "#FFFFFF";    // Mix red, green and blue to get white
  char red_bits[] = "#FF0000";
  char green_bits[] = "#00FF00";
  char blue_bits[] = "#0000FF";
  char yellow_bits[] = "#FFFF00";   // Mix red and green to get yellow
  char magenta_bits[] = "#FF00FF";  // A sort of purple color
  char cyan_bits[] = "#00FFFF";     // A blue-green color

  //Display *dpy = XOpenDisplay(NIL); 
  dpy = XOpenDisplay(NIL); assert(dpy);   // Open the display
  // Define the colors we want to use
  colormap = DefaultColormap(dpy, 0);
  XParseColor(dpy, colormap, black_bits, &black_col); XAllocColor(dpy, colormap, &black_col);
  XParseColor(dpy, colormap, white_bits, &white_col); XAllocColor(dpy, colormap, &white_col);
  XParseColor(dpy, colormap, red_bits, &red_col); XAllocColor(dpy, colormap, &red_col);
  XParseColor(dpy, colormap, green_bits, &green_col);XAllocColor(dpy, colormap, &green_col);
  XParseColor(dpy, colormap, blue_bits, &blue_col);XAllocColor(dpy, colormap, &blue_col);
  XParseColor(dpy, colormap, yellow_bits, &yellow_col);XAllocColor(dpy, colormap, &yellow_col);
  XParseColor(dpy, colormap, magenta_bits, &magenta_col);XAllocColor(dpy, colormap, &magenta_col);
  XParseColor(dpy, colormap, cyan_bits, &cyan_col);XAllocColor(dpy, colormap, &cyan_col);
  // Create the window  The numbers are the x and y locations on the screen, the width and height, 
  // border width (which is usually zero)
  w = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 0, 0, window_width, window_height,
  0, black_col.pixel, black_col.pixel);
  XSelectInput(dpy, w, StructureNotifyMask);        // We want to get MapNotify events
  XMapWindow(dpy, w);         // "Map" the window (that is, make it appear on the screen)
  for(;;){XEvent e; XNextEvent(dpy,&e); if(e.type == MapNotify) break;} //Wait for the MapNotify event
  // which means that the window has appeared on the screen.
  gc = XCreateGC(dpy, w, 0, NIL);        // Create a "Graphics Context"
  get_pen(white_col);
  //  We are finally ready to do some drawing!  Whew!  

  // ................  Students: you put your beautiful code HERE: .......................
  srand(time(NULL)); //  Get ready to make random numbers.  The time "seeds" the generator.
  int i;
  double x=0,  y=0;
  home();      // Send the turtle to the middle of the window.  That's its "home"
  get_pen(green_col);  pen_down();
  for (i=0; i<36; i++) {
    x = x + rand_range(-30.0, 30.0);  //Generates random number between these two numbers.
    y = y + rand_range(-30.0, 30.0)+5.0;
    gotoxy(x, y);   // Move the turtle to the new location.  It will draw a line if the pen is down.
    XFlush(dpy); // Tell the graphics server that it should really show us the results now.
    printf("1 x=%g y=%g heading=%g\n",turtle_x,turtle_y,turtle_heading); //Optional: use for debugging
    usleep(100000); XFlush(dpy); // Optional: use this to see the lines being drawn, one-by-one
  }
  XFlush(dpy); // Tell the graphics server that it should really show us the results now.
  sleep(1);  // Wait for 1 second
  printf("Press enter when done.\n");
  fgets (keyboard_input,100,stdin); 
  return(0);
}
示例#14
0
void relocate_targets(){
	
    for (int i=0; i<max_targets; i++) {
        targets[i].x=rand_range(100,getDisplayWidth()-100);
        targets[i].y=rand_range(100,getDisplayHeight()-100);
    }

    reassign_flares();	
}
XiEta normal_value(double mu, double sigma){
// Returns two normaly distributed, independent values with mu=0 and sigma=1
// based on the Box-Muller Method
  double u = rand_range(0,1);
  double v = rand_range(0,1);

  XiEta x = {mu + sigma*sqrt(-2*log(u))*cos(2*PI*v), mu + sigma*sqrt(-2*log(u))*sin(2*PI*v)};
  return x;
}
示例#16
0
void PE_SmokeTrail::emit_single_particle(Particle& p)
{
    p.cur_pos = m_pos + vec2(RAND_0_1 * 0.005f,RAND_0_1 * 0.005f);
    p.cur_size = 0.01 + RAND_0_1 * 0.01;
//  float col = rand_range(0.0,0.4);
    float col = rand_range(0.1,0.4);
    p.cur_color = vec4(col,col,col,0.0);
    p.cur_speed = vec2(-0.03,0.0) + normalized(vec2(rand_range(-1.0,1.0),rand_range(-1.0,1.0))) * 0.01;
}
示例#17
0
文件: pc.c 项目: influential/dungeon
void place_pc(dungeon_t *d)
{
  d->pc.position[dim_y] = rand_range(d->rooms->position[dim_y],
                                     (d->rooms->position[dim_y] +
                                      d->rooms->size[dim_y] - 1));
  d->pc.position[dim_x] = rand_range(d->rooms->position[dim_x],
                                     (d->rooms->position[dim_x] +
                                      d->rooms->size[dim_x] - 1));
}
示例#18
0
void hyp_neuron_init(neuron_t *n)
{
	for (size_t i = 0; i < n->input_count; i++)
	{
		n->weights->values[i] =
		  rand_range(-INITIAL_WEIGHT_RANGE, INITIAL_WEIGHT_RANGE);
	}
	n->bias = rand_range(-INITIAL_WEIGHT_RANGE, INITIAL_WEIGHT_RANGE);
}
示例#19
0
void tm_rect_generate_position( tm_rect_t* r, vect_t* sz, rect_t* map_r )
{
	assert( map_r->v2.x - map_r->v1.x >= sz->x );
	assert( map_r->v2.y - map_r->v1.y >= sz->y );
	r->v1.x = rand_range( map_r->v1.x, (map_r->v2.x - sz->x) );
	r->v1.y = rand_range( map_r->v1.y, (map_r->v2.y - sz->y) );
	r->v2.x = r->v1.x + sz->x;
	r->v2.y = r->v1.y + sz->y;
}
示例#20
0
/*
 * Returns random co-ordinates for player/monster/object
 */
bool new_player_spot(void)
{
    int    y = 0, x = 0;
    int max_attempts = 10000;

    cave_type *c_ptr;
    feature_type *f_ptr;

    /* Place the player */
    while (max_attempts--)
    {
        /* Pick a legal spot */
        y = rand_range(1, cur_hgt - 2);
        x = rand_range(1, cur_wid - 2);

        c_ptr = &cave[y][x];

        /* Must be a "naked" floor grid */
        if (c_ptr->m_idx) continue;
        if (dun_level)
        {
            f_ptr = &f_info[c_ptr->feat];

            if (max_attempts > 5000) /* Rule 1 */
            {
                if (!have_flag(f_ptr->flags, FF_FLOOR)) continue;
            }
            else /* Rule 2 */
            {
                if (!have_flag(f_ptr->flags, FF_MOVE)) continue;
                if (have_flag(f_ptr->flags, FF_HIT_TRAP)) continue;
            }

            /* Refuse to start on anti-teleport grids in dungeon */
            if (!have_flag(f_ptr->flags, FF_TELEPORTABLE)) continue;
        }
        if (!player_can_enter(c_ptr->feat, 0)) continue;
        if (!in_bounds(y, x)) continue;

        /* Refuse to start on anti-teleport grids */
        if (c_ptr->info & (CAVE_ICKY)) continue;

        /* Done */
        break;
    }

    if (max_attempts < 1) /* Should be -1, actually if we failed... */
        return FALSE;

    /* Save the new player grid */
    py = y;
    px = x;

    return TRUE;
}
示例#21
0
Person::Person(vector2d pos)
{
  m_type = rand_range(0, 5);
  m_right = rand_range(0, 1) == 1 ? true: false;
  m_pos = pos;
  m_velx = rand_range(1.0, 2.0);
  m_toast_factor = 0.0;
  m_abductor = NULL;

  set_state(STAND_PERSON);
}
示例#22
0
void place_pc(dungeon_t *d)
{
  ((pc *) d->pc)->position[dim_y] = rand_range(d->rooms->position[dim_y],
                                               (d->rooms->position[dim_y] +
                                                d->rooms->size[dim_y] - 1));
  ((pc *) d->pc)->position[dim_x] = rand_range(d->rooms->position[dim_x],
                                               (d->rooms->position[dim_x] +
                                                d->rooms->size[dim_x] - 1));

  pc_init_known_terrain(d->pc);
  pc_observe_terrain(d->pc, d);
}
示例#23
0
static void
draw_all_diamonds(int w, int h, float deviance) {
    SDL_Rect r;
    r.w = w;
    r.h = h;

    for (r.y = 0 - r.h / 2; r.y < HEIGHT; r.y += r.h)
        for (r.x = 0; r.x < WIDTH; r.x += r.w)
            heightmap[r.x + r.w / 2][r.y + r.h / 2] = diam_avg_heights(&r) + rand_range(-RANGE_CHANGE, RANGE_CHANGE) * deviance;
    for (r.y = 0; r.y < HEIGHT; r.y += r.h)
        for (r.x = 0 - r.w / 2; r.x + r.w / 2 < WIDTH; r.x += r.w)
            heightmap[r.x + r.w / 2][r.y + r.h / 2] = diam_avg_heights(&r) + rand_range(-RANGE_CHANGE, RANGE_CHANGE) * deviance;
}
示例#24
0
文件: predictors.c 项目: xurban46/bc
void _create_combined(ga_pop_t pop, pred_genome_t children)
{
    ga_chr_t mom;
    ga_chr_t dad;
    int red, blue;

    red = rand_range(0, pop->size - 1);
    blue = rand_range(0, pop->size - 1);
    _tournament(pop, &mom, pop->chromosomes[red], pop->chromosomes[blue]);

    red = rand_range(0, pop->size - 1);
    blue = rand_range(0, pop->size - 1);
    _tournament(pop, &dad, pop->chromosomes[red], pop->chromosomes[blue]);

    VERBOSELOG("Making love.");
    pred_genome_t mom_genome = (pred_genome_t)mom->genome;
    pred_genome_t dad_genome = (pred_genome_t)dad->genome;

    if (_metadata->genome_type == permuted) {
        _crossover1p_permuted(children, mom_genome, dad_genome);

    } else {
        _crossover1p_repeated(children, mom_genome, dad_genome);
    }

    /*
    for (int i = 0; i < _metadata->genotype_length; i++) {
        printf("%4x ", mom_genome->_genes[i]);
    }
    printf("\n");
    for (int i = 0; i < _metadata->genotype_length; i++) {
        printf("%4x ", dad_genome->_genes[i]);
    }
    printf("\n");
    for (int i = 0; i < _metadata->genotype_length; i++) {
        printf("%4x ", children[i]);
    }
    printf("\n");
    */

    VERBOSELOG("Mutating newly created child.");
    pred_mutate(children);

    /*
    for (int i = 0; i < _metadata->genotype_length; i++) {
        printf("%4x ", children[i]);
    }
    printf("\n\n");
    */
}
示例#25
0
void reassign_flares(){
    for (int i=0; i<max_targets; i++) {
	targets[i].flares = 0;
    }

    for (int i=0; i<max_flares; i++) {
        flares[i].vx+=rand_range(0,10)-5;
        flares[i].vy+=rand_range(0,10)-5;
	flares[i].target = (int)rand_range(0,max_targets);
	targets[flares[i].target].flares ++;
    }	


}
示例#26
0
文件: main.c 项目: shurik111333/spbu
//Before running run: "ulimit -s unlimited"
int main(int argc, char* argv[]) {
    parse_opts(argc, argv);

    srand(time(NULL)); 
    int tick = 0;
    struct list **chunks_lifetime = (struct list **)malloc(sizeof(struct list*) * max_ticks);// The stack memory has somee restrictions
    for (int i = 0; i < max_ticks; i++) {
        chunks_lifetime[i] = create_list();
    }

    struct memory *mem = create_memory(memory_size);
    printf("Starting\n"); 
    while (1) {
        if (need_trace) {
            printf("Tick %d:\n", tick);
        }
        while (!is_list_empty(chunks_lifetime[tick])) {
            int8_t *ptr = get_and_remove(chunks_lifetime[tick]);
            if (need_trace) {
                printf("   Removing chunk with size %d bytes\n", get_chunk_size(ptr));
            }
            free_chunk(mem, ptr);
        }
        SIZE_TYPE chunk_size = rand_range(min_chunk_size, max_chunk_size) / 4 * 4;
        int8_t *ptr = allocate_chunk(mem, chunk_size);

        if (ptr == NULL) {
            printf("Oops. We have no free memory to allocate %d bytes on tick %d. Exiting\n", chunk_size, tick);
            break;
        }
        int chunk_lifetime = rand_range(min_lifetime, max_lifetime);
        if (tick + chunk_lifetime >= max_ticks) {
            printf("The maximum number of ticks(%d) reached. Exiting\n", max_ticks);
            break;
        }
        
        add_to_list(chunks_lifetime[tick + chunk_lifetime], ptr);
        if (need_trace){
            printf("   Allocating chunk with size %d bytes. Its lifetime is %d ticks\n", chunk_size, chunk_lifetime);
        }
        tick++;
    }

    for (int i = 0; i < max_ticks; i++) {
        free_list(chunks_lifetime[i]);
    }
    free_memory(mem);
    free(chunks_lifetime);
    return 0;
}
示例#27
0
int main(int argc, char const **argv)
{
	srand(4);
	double a1 = rand_range(-1, 1);
	double a2 = rand_range(0, 1);
	double a3 = rand_range(-3, -5);
	double a4 = rand_range(31, 35);

	printf("%.3f\n", a1);
	printf("%.3f\n", a2);
	printf("%.3f\n", a3);
	printf("%.3f\n", a4);

	return 0;
}
示例#28
0
Neuron::Neuron()
{
	for(int i(0); i < 20; ++i)
	{
		weight[i] = rand_range(-15.,15.);
	}
}
示例#29
0
文件: DICE.C 项目: NoMan2000/c-prog
main()
{
    int     rolls;
    int     i;
    int     number;     /* each random number */

    printf("Please enter the number of rolls you want: ");
    scanf("%d", &rolls);

    srand(time(NULL));

#ifdef NOT_USING_MACRO
    for (i = 0; i < rolls; i++)
    {
        number = rand();
        number = number % SIDES;/* to get it into the range 0-5 */
        number++;               /* to get it into the range 1-6 */
        printf("Roll number %3d produced %d\n", i+1, number);
    }
#else
    for (i = 0; i < rolls; i++)
        printf("MACRO: Roll number %3d produced %d\n",
                         i+1, rand_range(rand(), SIDES));
#endif

    fflush(stdin);
    getchar();

    return 0;       /* no problems */
}
示例#30
0
int main(int argc, const char* argv[]) {

  gmp_randstate_t state;
  data_arr source;
  mpz_t seed;
  uint32_t min, max, n;


  mpz_init(seed);

  parse_input(argc, argv, seed, &min, &max);

  gmp_randinit_default(state);
  gmp_randseed(state, seed);

  n = rand_range(state, min, max);

  fprintf(stderr, "%u\n",n);
  source = make_array(n);

  generate_random_arr(n, source, state);
  
  
  fprint_array(stdout, source, n);

  gmp_randclear(state);
  delete_array(source, n);
  mpz_clear(seed);
  return 0;
}