示例#1
0
文件: main.cpp 项目: luqui/soylent
void step_reaction() {
    Uint8* keys = SDL_GetKeyState(NULL);

    if (!keys[SDLK_SPACE] && randrange(0,1) < RMUTATE_PROB) {
        // introduce spike
        int xidx = rand() % GRIDW;
        int yidx = rand() % GRIDH;
        modify_reaction(xidx,yidx);
    }

    // diffuse toward identity
    float gran1 = 1.0/GRAN;
    if (randrange(0,1) < RDIFFUSE_PROB) {
        std::cout << "RDIFFUSE\n";
        for (int i = 0; i < GRAN; i++) {
            for (int j = 0; j < GRAN; j++) {
                for (int k = 0; k < GRAN; k++) {
                    REACT[i][j][k][0] = RDIFFUSE * i * gran1 + (1 - RDIFFUSE) * REACT[i][j][k][0];
                    REACT[i][j][k][1] = RDIFFUSE * j * gran1 + (1 - RDIFFUSE) * REACT[i][j][k][1];
                    REACT[i][j][k][2] = RDIFFUSE * k * gran1 + (1 - RDIFFUSE) * REACT[i][j][k][2];
                }
            }
        }
    }
}
示例#2
0
文件: nnwork.c 项目: echoline/ann
// initialize new nnwork_t struct
nnwork_t *nnwork_init(unsigned int inum, unsigned int hnum, unsigned int onum) {
	unsigned int i, h, o;
	nnwork_t *ret = (nnwork_t*)malloc(sizeof(nnwork_t));

	ret->inum = inum;
	ret->hnum = hnum;
	ret->onum = onum;
	ret->ihw = (double**)malloc(sizeof(double*) * inum);
	for (i = 0; i < inum; i++)
		ret->ihw[i] = (double*)malloc(sizeof(double) * hnum);
	ret->how = (double**)malloc(sizeof(double*) * hnum);
	for (h = 0; h < hnum; h++)
		ret->how[h] = (double*)malloc(sizeof(double) * onum);
	ret->hout = (double*)malloc(sizeof(double) * hnum);
	ret->lambda = 1.0;
	ret->rate = 0.25;
	ret->mrate = .002;
	ret->mlow = -10;
	ret->mhigh = 10;

	for (i = 0; i < inum; i++) for (h = 0; h < hnum; h++)
			ret->ihw[i][h] = randrange(-0.5, 0.5);

	for (h = 0; h < hnum; h++) for (o = 0; o < onum; o++)
			ret->how[h][o] = randrange(-0.5, 0.5);
	
	return ret;
}
示例#3
0
Vec3i random_surface_block()
{
    Vec3i p;
    p.x = randrange(0, map_dim.x - 1);
    p.y = randrange(0, map_dim.y - 1);
    p.z = t_map::get_highest_solid_block(p.x, p.y);
    return p;
}
示例#4
0
void perlin(uint8_t * const img, uint16_t width, uint16_t height)
{
	uint8_t *limg = img;
	for (int y = 0; y < HEIGHT; y++)
		for (int x = 0; x < WIDTH; x++) {
			*(limg++) = 128;
			*(limg++) = 128;
			*(limg++) = 128;
			limg++;
		}

	int8_t *mipmap = malloc(sizeof(int8_t) * (2 * 2 + 4 * 4 + 8 * 8 + 16 * 16) * 4);

	int8_t *lmipmap = mipmap;
	for (int s = 2; s <= 16; s*=2)
		for (int x = 0; x < s * s; x++) {
			*(lmipmap++) = randrange(-128 / s, 128 / s);
			*(lmipmap++) = randrange(-128 / s, 128 / s);
			*(lmipmap++) = randrange(-128 / s, 128 / s);
			lmipmap++;
			printf("S: %d X: %d Y: %d R: %d G: %d B: %d\n", s, x / s, x, *(lmipmap-4), *(lmipmap-3), *(lmipmap-2));
		};

	limg = img;
	lmipmap = mipmap;
	for (int y = 0; y < height; y++)
		for (int x = 0; x < width; x++)
			for (int bit = 0; bit < 2; bit ++) {
				for (int s = 2; s <= 16; s*=2) {
					size_t offset = 0;
					for (int i = s / 2; i >= 2; i/=2)
						offset += i * i;
					lmipmap = mipmap + offset;
					uint16_t xblock = width / (s - 1);
					uint16_t yblock = height / (s - 1);

					uint8_t xbpos = (float)x / (float)xblock;
					uint8_t ybpos = (float)y / (float)yblock;

					float xmul = (float)x / (float)width - (float)xbpos;
					float ymul = (float)y / (float)height - (float)ybpos;

					int8_t valtl, valtr, valbl, valbr;
					valtl = lmipmap[bit + 4 * (ybpos * s + xbpos)];
					valtr = lmipmap[bit + 4 * (ybpos * s + xbpos + 1)];
					valbl = lmipmap[bit + 4 * ((ybpos + 1) * s + xbpos)];
					valbr = lmipmap[bit + 4 * ((ybpos + 1) * s + xbpos + 1)];

					int8_t wlerpu = lerp(xmul, valtl, valtr);
					int8_t wlerpl = lerp(xmul, valbl, valbr);

					int8_t endval = lerp(ymul, wlerpl, wlerpu);

					limg[bit + 4 * (y * width + x)] = limg[bit + 4 * (y * width + x)] + endval;
				}
			}
	free(mipmap);
}
示例#5
0
/**
 * Get a random point in a given range.  This is done by generating one X value
 * and one Y value according to the size given.
 */
static Point_t getRandomPoint(int width, int height)
{
    Point_t pt;

    pt.x = randrange(0, width);
    pt.y = randrange(0, height);

    return pt;
}
示例#6
0
void createRandomBodyColor(double &r, double &g, double &b)
{
    // Use narrow HSI ranges to avoid white (the selection color)
    // and avoid undesirable colors.
    double h = randrange(0.0, 6.283);
    double s = randrange(0.3, 1.0); 
    double i = randrange(0.3, 0.8);
    hsi2rgb(h, s, i, r, g, b);
}
示例#7
0
/**
 * Generate a random RGB color.  This is done by setting each channel of the
 * color to a random value between 0 and the maximum color value (255).
 */
static Color_t getRandomColor(void)
{
    Color_t color;

    color.red   = randrange(0, MAX_COLOR_VALUE);
    color.green = randrange(0, MAX_COLOR_VALUE);
    color.blue  = randrange(0, MAX_COLOR_VALUE);

    return color;
}
示例#8
0
文件: example4.c 项目: gyakoo/cpoly
void randomcircles()
{
  int i;

  // init circles
  for (i=0;i<MAXCIRCLES;++i)
  {
    g_circles[i].x = randrange(-40.0f,40.0f);
    g_circles[i].y = randrange(-40.0f,40.0f);
    g_circles[i].r = randrange(2.0f, 12.0f);
  }
}
示例#9
0
int8_t randrange(int8_t from, int8_t to)
{
	int base_random = rand();
	if (RAND_MAX == base_random) return randrange(from, to);
	int range = to - from,
	    remainder = RAND_MAX % range,
	    bucket = RAND_MAX / range;
	if (base_random < RAND_MAX - remainder) {
		return from + base_random/bucket;
	} else {
		return randrange(from, to);
	}
}
示例#10
0
void Generate_Mine()
{
  int a;
  do
  {
//    Mine_X_Pos=random(MaxX); // Maybe not available, what does it do?
//    Mine_Y_Pos=random(MaxY);
		Mine_X_Pos=randrange(0, MaxX);
		Mine_Y_Pos=randrange(0, MaxY);
    a=sqrt(pow(Mine_X_Pos-Ship_X_Pos,2)+pow(Mine_Y_Pos-Ship_Y_Pos,2));
  } while(a < 0.5*MaxX );  /* repeat until distance exceeds min. */

//  Draw_Mine(cr,Mine_X_Pos,Mine_Y_Pos,MINE_SIZE_FACTOR*MaxX);  /* draw mine first time */
//	Mine_Should_Clean = 1;
}
void Reset_Screen()
{
	printf("Reseting\n");
        /*  reset variables */
				/*  reset variables */
	#ifdef NO_RANDOM_SPAWN
  Ship_X_Pos=0.5*MaxX;
  Ship_Y_Pos=0.5*MaxY;
  Ship_Headings=0;
  #else
  Ship_X_Pos=randrange(20,MaxX-20);
  Ship_Y_Pos=randrange(20,MaxY-20);
  Ship_Headings=randrange(0,359);
  #endif
  Loop_Counter = 0;
  Last_Missile_Hit = -11;
  Score=0.0;
  Ship_X_Speed=0.0;
  Ship_Y_Speed=0.0;
  srand(time(NULL));
	Ship_Damaged_By_Fortress = 0;
  Mine_Flag=DEAD;
  for(int i=0;i<MAX_NO_OF_MISSILES;i++)  {
  	Missile_X_Pos[i]=-200;
  	Missile_Flag[i]=DEAD;
  }
  Missile_Type=VS_FRIEND;
  Missile_Vs_Mine_Only=OFF;
  Missiles_Counter=0;
  Shell_Flag=DEAD;
  Rotate_Input=0; /* joystick left/right */
  Accel_Input=0; /* joystick forward */
  End_Flag=OFF;
  Fort_Headings=270;
  Vulner_Counter=0;
  Timing_Flag=OFF; /* if screen reset between consecutive presses */
  Resource_Flag=OFF;
  Resource_Off_Counter=0;
  Bonus_Display_Flag=NOT_PRESENT;   /* in case bonus is pressed after */
  Bonus_Granted=OFF;
  Fort_Lock_Counter=0;
	// Score=0;
	// Points=0;
	// Velocity=0;
	// Control=0;
	// Speed=0;

}  /* end reset screen */
示例#12
0
文件: main.cpp 项目: luqui/soylent
void modify_reaction(int xidx, int yidx) {

    int a = int(GRID_FRONT[xidx][yidx].value[0] * GRAN + 0.5);
    int aw = rand() % 25;
    int b = int(GRID_FRONT[xidx][yidx].value[1] * GRAN + 0.5);
    int bw = rand() % 25;
    int c = int(GRID_FRONT[xidx][yidx].value[2] * GRAN + 0.5);
    int cw = rand() % 25;
    int coef = rand() % COEFS;

    float value = randrange(0,1);

    for (int i = a-aw; i < a+aw; i++) {
        if (i < 0 || i >= GRAN) continue;
        for (int j = b-bw; j < b+bw; j++) {
            if (j < 0 || j >= GRAN) continue;
            for (int k = c-cw; k < c+cw; k++) {
                if (k < 0 || k >= GRAN) continue;

                float ad = fabs(float(i-a))/aw;
                float bd = fabs(float(j-b))/bw;
                float cd = fabs(float(k-c))/cw;

                float blend = RMUTATE * exp(-ad*ad - bd*bd - cd*cd);
                REACT[i][j][k][coef] = blend * value + (1-blend) * REACT[i][j][k][coef];
            }
        }
    }


}
示例#13
0
void create_health_change_indicator(const BoundingBox& box, const Vec3& position, int amount)
{
    const float STRAY_SPEED = 1.0f/6.0f;
    const float RADIUS_FACTOR = 0.3f;
    const float TEXT_SCALE = 0.95f;
    int ttl = randrange(35, 45);

    Particle::BillboardTextHud* b = Particle::billboard_text_hud_list->create();
    IF_ASSERT(b == NULL) return;
    b->set_state(
        position.x + (RADIUS_FACTOR * box.radius * (2*randf() - 1)),
        position.y + (RADIUS_FACTOR * box.radius * (2*randf() - 1)),
        position.z + box.height * 0.5f * (2 * randf() - 1) * RADIUS_FACTOR,
        (2*randf()-1)*STRAY_SPEED,
        (2*randf()-1)*STRAY_SPEED,
        (2*randf()-1)*STRAY_SPEED);
    Color color = COLOR_WHITE;
    if (amount > 0)
        color = Particle::BB_PARTICLE_HEAL_COLOR;
    else if (amount < 0)
        color = Particle::BB_PARTICLE_DMG_COLOR;
    b->set_color(Particle::BB_PARTICLE_DMG_COLOR);
    char txt[11+1];
    snprintf(txt, 11+1, "%d", abs(amount));
    txt[11] = '\0';
    b->set_text(txt);
    b->set_scale(TEXT_SCALE);
    b->set_ttl(ttl);
}
示例#14
0
文件: shuffle.c 项目: eokeeffe/C-code
main()
{
	int a[N], i, nvalues = N;

	srand((unsigned int)time((time_t *)NULL));

	/* shuffle an array containing the numbers 1..N, */
	/* to generate a random sequence in [1,N] with no repeats */

	for(i = 0; i < nvalues; i++)
		a[i] = i + 1;

	for(i = 0; i < nvalues-1; i++) {
		int c = randrange(nvalues-i);
		int t = a[i]; a[i] = a[i+c]; a[i+c] = t;	/* swap */
	}
	for(i = 0; i < N; i++)
		printf("%d\n", a[i]);

	/* verify shuffle by sorting back to original order */

	qsort(a, nvalues, sizeof(int), intcmp);

	for(i = 0; i < nvalues; i++)
		if(a[i] != i + 1)
			printf("oops: a[%d] = %d\n", i, a[i]);

	return 0;
}
示例#15
0
// ----------------------------------------------------------------------
// CRainfall::ResetParticle
// Implementation of CParticleEngine::ResetParticle(GLint)
// ----------------------------------------------------------------------
//
void CRainfall::ResetParticle(GLint aIndex)
	{

	TParticle & Particle = iParticles[aIndex];

    Particle.iPosition = TVector( iWidth * (Random() - 0.5f), 0, iDepth * (Random() - 0.5f)) + iPosition;
    Particle.iVelocity = TVector( 0, randrange( -40.f, -20.f, iSeed ), 0);
	}
示例#16
0
文件: main.cpp 项目: luqui/soylent
void init_diffuse() {
    for (int i = 0; i < COEFS; i++) {
        float sum = 0;
        for (int j = 0; j < 4; j++) {
            DIFFUSE[i].dir[j] = randrange(0,1);
            sum += DIFFUSE[i].dir[j];
        }
        DIFFUSE[i].sum = sum;
    }
}
示例#17
0
void Generate_Aim_Mine()
{
    float radius;
    float mine_distance;
    float mine_angle;

    radius=((float)MaxX)/2.2;
    mine_angle=((float)randrange(0, 15))*22.5;
    if(mine_angle>338.0) mine_angle=0.0;
    mine_distance=radius/2.0+ ((float)randrange(0, 1))*radius/2.0;

    Mine_X_Pos=((float)MaxX)/2.0 + mine_distance*Fsin(mine_angle);
    Mine_Y_Pos=((float)MaxY)/2.0 - mine_distance*Fcos(mine_angle);
//    else Mine_Y_Pos=MaxY/2 - mine_distance*Fcos(mine_angle)/GraphSqrFact;
		     /* Y/X square ratio */

//    Draw_Mine(Mine_X_Pos,Mine_Y_Pos,MINE_SIZE_FACTOR*MaxX);
	     /* draw mine */
}
示例#18
0
int Generate_Non_Bonus_Char()
{
   int rn;

   do { rn=randrange(0,9); } // Used to be 10, appereantly random(n) generates in (0, n-1)
   while(rn==Bonus_Indication_Index); // I think the only reason for this being here
//	 is the the original random function always returned a number between 0 and n,
//	 while other random fucntions can return a number in between m and n.
   return(rn);
}
示例#19
0
void PinballMovement::bounce(bool collision)
{
    add_x = add_y = 0.0;

    if (!collision) {
        x_speed = -x_speed;
        y_speed = -y_speed;
        return;
    }

    push_out();

    float angle = get_pinball_angle(x_speed, y_speed);
    float dist = get_length(x_speed, y_speed);

    float found_a = -1.0f;
    for (float a = 0.0f; a < (2.0f*CHOW_PI); a += (2.0f*CHOW_PI) / 32.0f) {
        float x_move = 10.0f * cos(angle + a);
        float y_move = -10.0f * sin(angle + a);

        if (!test_offset(x_move, y_move)) {
            found_a = a;
            break;
        }
    }

    if (found_a == -1.0f) {
        x_speed = -x_speed;
        y_speed = -y_speed;
        return;
    }

    angle += found_a * 2.0f;
    if (angle > 2.0 * CHOW_PI)
        angle -= 2.0 * CHOW_PI;

    // add some randomness
    angle += randrange(-0.3f, 0.3f);
    dist += randrange(0.0f, 15.0f);

    x_speed = dist * cos(angle);
    y_speed = -dist * sin(angle);
}
示例#20
0
// white noise floor
void rough_floor(int x, int y, int z_start, int height, CubeType tile)
{
    GS_ASSERT(height > 0);
    if (height <= 0) return;
    GS_ASSERT(z_start >= 0 && z_start + height < map_dim.z);
    for (int i=0; i<x; i++)
    for (int j=0; j<y; j++)
    {
        int n = randrange(1, height);
        for (int k=0; k<n; k++)
            t_map::set_fast(i,j,k+z_start, tile);
    }
}
示例#21
0
void iaRandom(t_jogador *jogador,char time,t_jogada *jogada,t_jogo *jogo,void *data)
{
	unsigned int movimentos[14];
	unsigned int numMov = 0;
	unsigned int capturas[14];
	unsigned int numCapt = 0;

	while(numMov == 0 && numCapt == 0)
	{
		//escolhe uma peca
		int peca = randrange(jogador->numTorres + jogador->numPeoes-1);
		//se for menor que numPeoes, eh um peao
		if(peca < jogador->numPeoes)
		{
			jogada->pecaOrigem = time | PEAO;
			jogada->posOrigem = jogador->peaoPos[peca];
		}
		//caso contrario, eh uma torre
		else
		{
			jogada->pecaOrigem = time | TORRE;
			jogada->posOrigem = jogador->torrePos[peca-jogador->numPeoes];
		}

		movimentosPossiveis(jogo->tabuleiro,jogada->posOrigem,movimentos,&numMov,capturas,&numCapt);
	}

	//se puder capturar, captura
	if(numCapt>0)
	{
		int pos = randrange(numCapt-1);
		jogada->posDestino = capturas[pos];
	}
	else
	{
		int pos = randrange(numMov-1);
		jogada->posDestino = movimentos[pos];
	}
}
示例#22
0
void engine_spawn_enemy (Context* context) {
	Engine* engine = context->engine;
	int idx = engine_next_enemy(engine->enemy_field);
	
	if (idx >= MAX_ENEMIES) {
		return;
	}
	
	if (randrange(200) >= ENEMY_SPAWN_CHANCE) {
		return;
	}
	
	int sprite = randrange(engine->enemy_sprite_count);
	int max_w = engine->max_w - engine->enemy_sprites[sprite][0]->w;
	int x = randrange(max_w) + engine->enemy_sprites[sprite][0]->w / 2;
	
	if (engine->enemies[idx] == NULL) {
		Player* enemy = (Player*) malloc(sizeof(Player));
		engine_init_player(
			context
			, engine
			, enemy
			, x
			, 0
			, engine->enemy_sprites[sprite]
		);
		engine->enemies[idx] = enemy;
	} else {
		Player* enemy = engine->enemies[idx];
		*enemy->x = x;
		*enemy->y = 0;
		enemy->anims = engine->enemy_sprites[sprite];
		enemy->v_buf->v->bitmap = enemy->anims[0];
	}
	
	engine->enemy_field += 1 << idx;
}
示例#23
0
void Generate_Resource_Character()
{
    int lastrn;
    static bonus_character lastchar=NON_BONUS; // This is a struct

    if((lastchar==NON_BONUS) && (No_Of_Bonus_Windows<MAX_BONUS_WINDOWS))
		{
   		if(randrange(0,9)<7) /* display first bonus */
     	{
				No_Of_Bonus_Windows++;
				// An index for an array with bonus characters (like '$) of chartype
				rn=Bonus_Indication_Index;
//				Xor_Bonus_Char(rn); // Put the character/image currently passed to graphics
				lastchar=Bonus_Display_Flag=FIRST_BONUS;
				Bonus_Char_Should_Update = 1;
				Bonus_Wasted_Flag=OFF;
			}
			else /* display non_bonus character */
     	{
				lastrn=rn;
				do { rn=Generate_Non_Bonus_Char(); }
				while(rn==lastrn); /* new char is different from last one */
//				Xor_Bonus_Char(rn); // put the image to game
				Bonus_Char_Should_Update = 1;
				lastchar=Bonus_Display_Flag=NON_BONUS;
			}
		}
    else
		{
    	if(lastchar==FIRST_BONUS)
      {
//				Xor_Bonus_Char(rn);
					Bonus_Char_Should_Update = 1;
					lastchar=Bonus_Display_Flag=SECOND_BONUS;
			}
    	else
			{
    		if(lastchar==SECOND_BONUS)
        {
	        rn=Generate_Non_Bonus_Char();
//	        Xor_Bonus_Char(rn);// put the image to gam
					Bonus_Char_Should_Update = 1;
	        lastchar=Bonus_Display_Flag=NON_BONUS;
				}
			}
		}
}
示例#24
0
文件: main.cpp 项目: luqui/soylent
void color_from_density(const Cell& cell) {
    if (cell.crossing[CONTOUR_PLASMA]) {
        glColor3f(0.0, randrange(0.8, 1.0), randrange(0.9,1.0));
    }
    else if (cell.crossing[CONTOUR_FIRE]) {
        glColor3f(randrange(0.8,1.0),randrange(0,0.3),0);
    }
    else if (cell.crossing[CONTOUR_LIFE]) {
        glColor3f(randrange(0,0.2), randrange(0.8,1.0), randrange(0,0.2));
    }
    else {
        //glColor3f(0,0,0);
        double c = (cell.value + 10) / 40;
        glColor3f(c,c,c);
    }
}
示例#25
0
文件: main.cpp 项目: luqui/soylent
void step_diffusion() {
    for (int k = 0; k < COEFS; k++) {
        float sum = 0;
        for (int d = 0; d < 4; d++) {
            DIFFUSE[k].dir[d] += DT * randrange(-1,1);
            if (DIFFUSE[k].dir[d] < 0) DIFFUSE[k].dir[d] = 0;
            sum += DIFFUSE[k].dir[d];
        }

        if (DT * sum > 1) {
            float norm = 1 / (DT * sum);
            sum = 0;
            for (int d = 0; d < 4; d++) {
                DIFFUSE[k].dir[d] *= norm;
                sum += DIFFUSE[k].dir[d];
            }
        }
        DIFFUSE[k].sum = sum;
    }
}
示例#26
0
    void randomize() {

        Board* board = this;
        class Tile* t;
        std::string a = "a";
        int firstlettervalue = (int) a[0];

        for (int y=0; y<board->height; y++) {
            for (int x=0; x<board->width; x++) {
                int offset = y*board->width + x;

                t = &( board->tiles[ offset ] );

                int r = randrange(6);

                t->color = (char) (firstlettervalue + r);
            }
        }

    }
示例#27
0
void Board_randomize(struct Board* board) {


  //int firstletter = atoi(a);
  std::string a = "a";
  int firstlettervalue = (int) a[0];

  //int firstletter

  for (int y=0; y<board->height; y++) {
    for (int x=0; x<board->width; x++) {
      int offset = y*board->width + x;

      struct Tile* t = &( board->tiles[ offset ] );

      int r = randrange(6);

      t->color = (char) (firstlettervalue + r);
      //t->color = 'g';

    }
  }

}
示例#28
0
int* random_number(int n, int max) {
	int i;
	const int MAX = max;
	int *directories;
	int candidates[MAX];
	srand(time(NULL));  // Crea la semilla del random 
	directories = (int *) malloc(sizeof(int)*n);

	for (i=0; i<MAX; i++)
		candidates[i] = i;

	for (i = 0; i < MAX-1; i++) 
	{
		int c = randrange(MAX-i);
		int t = candidates[i];
		candidates[i] = candidates[i+c];
		candidates[i+c] = t;
	}

	for (i=0; i<n; i++)
		directories[i] = candidates[i] + 1;

	return directories;
}
示例#29
0
void Game::mouseLeftDown(coord2d c)
{
	++count;
	// calculate inserted atom position in vector
	int pos = 0;
	float theta = 0, ang = c.getRadians();
	if (atoms.size() > 0) {
		theta = circ / atoms.size();
		float start = atoms[0]->center->getRadians();
		if (start > ang)
			start -= circ;
		pos = floor((ang - start) / theta) + 1;
	}

	atoms.insert(atoms.begin() + pos, centralAtom);
	float phase = atoms[0]->center->getRadians();
	ang = pos * theta - theta / 2 + phase;

	// change every atom postion accordingly
	atoms[pos]->center->fromRadians(ang, radius);
	updateAtomsPosition(pos);

	// look for chain reactions
	for (int i = 0; i < atoms.size(); i++)
		if (atoms[i]->type == Atom::atype::red_plus || atoms[i]->type == Atom::atype::black_plus) {
			if (int q = reaction(i)) {
				// if there's a reaction I have to update positions again and check for another one
				pos = (atoms.size() + i - q - (i >= atoms.size() + q ? atoms.size() + q - i + 1 : 0)) % atoms.size();
				ang = i * theta - theta / 2 + phase;
				atoms[pos]->center->fromRadians(ang, radius);
				updateAtomsPosition(pos);
				theta = circ / atoms.size();
				phase = atoms[0]->center->getRadians();
				i = -1; // beware of teh bad wolf
			}
		}

	// Calulate energy particles spawning chance.
	Atom::atype type = Atom::atype::normal;
	// Every time the red plus isn't picked up its chance is doubled and the 5th time (32) is 100%.
	// I think this works quite well but I should RE the game (or ask the dev eh) to know the real algorithm.
	lastRedPlus *= 2;
	if (count % 20 == 0) {
		type = Atom::atype::minus;
	}
	else if (randrange(32) < lastRedPlus) {
		type = Atom::atype::red_plus;
		lastRedPlus = 1;
	}
	else if (score > 750 && randrange(80) == 0) {
		type = Atom::atype::black_plus;
	}
	else if (score > 1500 && randrange(60) == 0) {
		type = Atom::atype::neutrino;
	}

	unsigned char number = 0, startRange = 1 + count / 40;
	if (type == Atom::atype::normal) {
		number = startRange + randrange(4);
		// check if there's an atom below the spawning range
		for (Atom* a : atoms) if (a->type == Atom::atype::normal && a->number < startRange)
			if (randrange(atoms.size() - 1) == 0) {
				number = a->number;
				break;
			}
	}
	centralAtom = new Atom(new coord2d(0, 0), type, number);
}
示例#30
0
 long randint(long a, long b)
 {
     // TODO: It should be implemented with an uniform_int_distribution
     return randrange(a, b+1);
 }