Example #1
0
int main(void)
{

    int a, b, result;

    srand(time(NULL));

    a = rand() % 9 + 1;
    b = rand() % 9 + 1;

    printf("How much is %d times %d? :", a, b);
    scanf("%d", &result);

    while (result != a * b) {
	printf("No please try again: ");
	scanf("%d", &result);

    }

    printf("Very good!\n");
    return 0;



}
Example #2
0
void Agent::Wander(float radius, float jitter, float distance, float weight)
{
	auto &m = m_movementInfo;
	// determine some random angles for circle/jitter
	float cangle = rand();
	float jangle = rand();

	// create circle/jitter vectors

	float xCircle = cos(cangle) * radius;
	float yCircle = sin(cangle) * radius;
	
	float xJitter = cos(jangle) * jitter;
	float yJitter = sin(jangle) * jitter;
	//combine
	float xOffset = xCircle + xJitter;
	float yOffset = yCircle + yJitter;

	float offMag = sqrt(xOffset*xOffset + yOffset*yOffset);
	//normalize to size of circle
	xOffset *= radius / offMag;
	yOffset *= radius / offMag;

	// find normal of vector between, Mult by distance
	float velMag = sqrtf(m.m_velocityX*m.m_velocityX + m.m_velocityY*m.m_velocityY);
	float xPosition = (m.m_velocityX / velMag) * distance;
	float yPosition = (m.m_velocityY / velMag) * distance;

	// add our offset and circle position to the player's position to get our target
	float xTarget = xOffset + xPosition + m.m_positionX;
	float yTarget = yOffset + yPosition + m.m_positionY;

	Patrol();
}
Example #3
0
 static inline __host__ __device__ Vec3 random(float r){
     float r2 = 2.f * r;
     float x_ = rand() * 1.f /RAND_MAX;
     float y_ = rand() * 1.f /RAND_MAX;
     float z_ = rand() * 1.f /RAND_MAX;
     return Vec3(x_ * r2 - r, y_ * r2 - r, z_ * r2 - r);
 }
Example #4
0
DataAdapter::DataAdapter()
{
	m_parallel3DObj = new t3DParallelColor[OBJ_NUM];
	DataIndex = new int[18847];//18847 = total point number in brain obj
	AddressCode = new V3D[40]; //40 == neuro address count
	for (int i = 0; i < 40; i++)
	{
		AddressCode[i].R = ((float)((rand() % 255))) / 255;
		AddressCode[i].G = ((float)((rand() % 255))) / 255;
		AddressCode[i].B = ((float)((rand() % 255))) / 255;
	}
	for (int i = 0; i < 18847;i++)
	{
		DataIndex[i] = 0;
	}
	for (int i = 0; i < OBJ_NUM; i ++)
	{
		m_parallel3DObj[i].pColors = new CVector3[VertexNum[i]];
	}
	for (int i = 0; i < OBJ_NUM; i++)
	{
		for (int j = 0; j < VertexNum[i]; j++)
		{
			m_parallel3DObj[i].pColors[j].x = 255;
			m_parallel3DObj[i].pColors[j].y = 255;
			m_parallel3DObj[i].pColors[j].z = 255;
		}
	}
	this->start();
}
Example #5
0
void gen2(int number) {
  sprintf(input, "%s%d.in", name, number);
  out = fopen(input, "w");
  
  if (number & 1) std::random_shuffle(p1, p1 + 20); 
  
  fprintf(out, "%d\n", 5);
  for (int tt = 1; tt <= 5; ++tt) {
    n = 40 + rand() % 11;
    m = 40 + rand() % 11; 
    C = 10 + rand() % 41;
    D = 2 + rand() % (C * 2 / 3);
    if (number & 1) fprintf(out, "%d %d %d %d %d\n", n, m, C, D, p1[tt]);
    else fprintf(out, "%d %d %d %d %d\n", n, m, C, D, 100000 + Rand() % M1 + 1);

    bo.clear();
    bo[mp(1, 1)] = bo[mp(n, m)] = true;
    for (int i = 1; i <= C; ++i) {
      int x, y;
      do {
        x = Rand() % n + 1;
        y = Rand() % m + 1;
      } while (bo[mp(x, y)]);
      bo[mp(x, y)] = true;
      fprintf(out, "%d %d\n", x, y);
    }
  }
}
Example #6
0
        void UpdateAI(const uint32 diff)
        {
            if (!UpdateVictim())
                return;

            //Check for War Stomp
            if (War_Stomp_Timer <= diff)
            {
                DoCast(me->getVictim(), WAR_STOMP);
                War_Stomp_Timer = 25000 + rand()%15000;
            }
            else
                War_Stomp_Timer -= diff;

            //Check for Arcane Volley
            if (Arcane_Volley_Timer <= diff)
            {
                DoCast(me->getVictim(), DUNGEON_MODE(ARCANE_VOLLEY, ARCANE_VOLLEY_H));
                Arcane_Volley_Timer = 20000 + rand()%15000;
            }
            else
                Arcane_Volley_Timer -= diff;

            //Check for Summon Treants
            if (Summon_Treants_Timer <= diff)
            {
                SummonTreants();
                Summon_Treants_Timer = 45000;
            }
            else
                Summon_Treants_Timer -= diff;

            DoMeleeAttackIfReady();
        }
Example #7
0
    void UpdateAI(const uint32 diff)
    {
        if (!UpdateVictim())
            return;

        if ((me->GetHealth() * 100) / me->GetMaxHealth() <= 20)
        {
            if (!Root)
            {
                DoCast(me, SPELL_FOUL_SPORES);
                Root = true;
            }
        }

        if (Mushroom_Timer <= diff)
        {
            if (Unit* pTarget = SelectUnit(SELECT_TARGET_RANDOM, 0))
                me->SummonCreature(17990, pTarget->GetPositionX() + float(rand() % 8), pTarget->GetPositionY() + float(rand() % 8), pTarget->GetPositionZ(), float(rand() % 5), TEMPSUMMON_TIMED_DESPAWN, 22000);
            else
                me->SummonCreature(17990, me->GetPositionX() + float(rand() % 8), me->GetPositionY() + float(rand() % 8), me->GetPositionZ(), float(rand() % 5), TEMPSUMMON_TIMED_DESPAWN, 22000);

            Mushroom_Timer = 10000;
        }
        else Mushroom_Timer -= diff;

        if (AcidGeyser_Timer <= diff)
        {
            if (Unit* pTarget = SelectUnit(SELECT_TARGET_RANDOM, 0))
                DoCast(pTarget, SPELL_ACID_GEYSER);
            AcidGeyser_Timer = 10000 + rand() % 7500;
        }
        else AcidGeyser_Timer -= diff;

        DoMeleeAttackIfReady();
    }
Example #8
0
void World::Space() {
    
    
    for ( int i = 0; i < rain.size(); i++ ) {
        rain[i]->solid = true;
        
        rain[i]->velocity_x = 0.01;
        rain[i]->velocity_y = -0.005f;
        
        rain[i]->velocity_y += rain[i]->acceleration_y * FIXED_TIMESTEP;
        rain[i]->y += rain[i]->velocity_y * FIXED_TIMESTEP;
        rain[i]->velocity_x += rain[i]->acceleration_x * FIXED_TIMESTEP;
        rain[i]->x += rain[i]->velocity_x * FIXED_TIMESTEP;
    }
    
    for ( size_t i = 0; i < blocks.size(); i++ ) {
        blocks[i]->v = TILEHEIGHT * 5.0;
        if ( i % 10 == 0 ) blocks[i]->v = TILEHEIGHT * 1.0;
        else if ( i % 5 == 0 ) blocks[i]->v = TILEHEIGHT * 0.0;
        
        if ( blocks[i]->y < platform->y - 2.0f ) {
            blocks[i]->x = ((float)rand())/RAND_MAX * 2.66 - 1.33;
            blocks[i]->y = platform->y + 4.0 + ( rand() % 16 - 8)/ 10.0;
        }
    }
    
    platform->v = TILEHEIGHT * 4.0;
    platform->velocity_y = 0.4;
}
Example #9
0
//Method to generate random data
int generate_random_text( char *addr, unsigned long len, unsigned long  num_words  ) {

    unsigned long idxa =0, idxb =0;
    unsigned long cntr =0;
    int wordsize;
    int maxwordsize = 0 ;
    int idxc =0;

    maxwordsize = len / num_words;

    static const char alphanum[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";

    for (idxa = 0; idxa < num_words; idxa++) {

        wordsize = rand()%  maxwordsize;

        for (idxb = 0; idxb < wordsize; idxb++) {

            if( cntr >= len) break;

            idxc = rand()% (sizeof(alphanum)/sizeof(alphanum[0]) - 1);
            addr[cntr] = alphanum[idxc];
            cntr++;
        }
        addr[cntr] = ' ';
        cntr++;
    }
    return cntr;

}
Example #10
0
void World::Rain() {
    
    for ( size_t i = 0; i < rain.size(); i++ ) {
        
        rain[i]->solid = false;
        
        rain[i]->velocity_x = 0.0;
        rain[i]->velocity_y = -1.5f;
        
        rain[i]->velocity_y += rain[i]->acceleration_y * FIXED_TIMESTEP;
        rain[i]->y += rain[i]->velocity_y * FIXED_TIMESTEP;
        rain[i]->velocity_x += rain[i]->acceleration_x * FIXED_TIMESTEP;
        rain[i]->x += rain[i]->velocity_x * FIXED_TIMESTEP;
        
        if ( rain[i]->y < platform->y - 2.0f ) {
            rain[i]->x = ((float)rand())/RAND_MAX * 2.66 - 1.33;
            rain[i]->y = platform->y + 3.0f;
            rain[i]->acceleration_y = (float)(rand() % 100 ) * -1;
        }
        if ( rain[i]->x > platform->x + 2.0f ) {
            rain[i]->x = ((float)rand())/RAND_MAX * 2.66 - 1.33;
            rain[i]->velocity_x = ((float)rand())/RAND_MAX * 0.5 - 0.25;
        }
    }
    
    for ( size_t i = 0; i < blocks.size(); i++ ) {
        blocks[i]->u = TILEWIDTH * 0.0;
    }
}
Example #11
0
void World::Snow() {
    
    for ( int i = 0; i < rain.size(); i++ ) {
        
        rain[i]->solid = true;
        
        rain[i]->velocity_x = 0.01;
        rain[i]->velocity_y = -0.005f;
        
        rain[i]->velocity_y += rain[i]->acceleration_y * FIXED_TIMESTEP;
        rain[i]->y += rain[i]->velocity_y * FIXED_TIMESTEP;
        rain[i]->velocity_x += rain[i]->acceleration_x * FIXED_TIMESTEP;
        rain[i]->x += rain[i]->velocity_x * FIXED_TIMESTEP;
        
        if ( rain[i]->y < platform->y - 2.0f ) {
            rain[i]->x = ((float)rand())/RAND_MAX * 2.66 - 1.33;
            rain[i]->y = platform->y + 2.0f;
        }
        if ( rain[i]->x > platform->x + 2.0f ) {
            rain[i]->x = ((float)rand())/RAND_MAX * 2.66 - 1.33;
        }
    }
    
    for ( size_t i = 0; i < blocks.size(); i++ ) {
        blocks[i]->v = TILEHEIGHT * 2.0;
    }
    
    for ( size_t i = 0; i < rain.size(); i++ ) {
        rain[i]->v = TILEHEIGHT * 3.0;
    }
    
    platform->v = TILEHEIGHT * 2.0;
}
Example #12
0
P_ITEM cCharStuff::AddRandomLoot(P_ITEM pBackpack, char * lootlist)
{
	char sect[512];
	int i,j, storeval,loopexit=0;
	P_ITEM retitem = NULL;
	storeval=-1;
	i=0; j=0;

	sprintf(sect, "LOOTLIST %s", lootlist);
	
	Script *pScpBase=i_scripts[npc_script];
	Script *pScp=pScpBase->Select(sect,custom_npc_script);
	if (!pScp) return NULL;

	loopexit=0;
	do
	{
		pScp->NextLine();
		if (script1[0]!='}')
		{
			i++; // Count number of entries on list.
		}
	} while ( (script1[0]!='}') && (++loopexit < MAXLOOPS) );
	pScp->Close();

	if(i>0)
	{
		i=rand()%(i);
		pScp=pScpBase->Select(sect,custom_npc_script);

		loopexit=0;
		do
		{
			pScp->NextLine();
			if (script1[0]!='}')
			{
				if(j==i)
				{
					storeval=str2num(script1);	//script1 = ITEM#

					scpMark m=pScp->Suspend();
					retitem = Targ->AddMenuTarget(-1, 0, storeval);
					pScp->Resume(m);

					if(retitem!=NULL)
					{
						retitem->pos.x=50+(rand()%80);
						retitem->pos.y=50+(rand()%80);
						retitem->pos.z=9;
						retitem->SetContSerial(pBackpack->serial);
					}
					break;;    
				}
				else j++;
			}
		}	while ( (script1[0]!='}') && (++loopexit < MAXLOOPS) );
		pScp->Close();
	}
	return retitem;
}
Example #13
0
bool test_oom_random(void) {
  umm_init();
  corruption_cnt = 0;
  void *ptrs[OOM_PTRS_CNT];

  size_t size = 100;

  while (1) {
    size_t i;
    for (i = 0; i < OOM_PTRS_CNT; i++) {
      size += rand() % 40 - 10;
      ptrs[i] = wrap_malloc(size);
      if (ptrs[i] == NULL) {
        goto out;
      }
    }

    /* free some of the blocks, so we have "holes" */
    for (i = 0; i < OOM_PTRS_CNT; i++) {
      if ((rand() % 10) <= 2) {
        wrap_free(ptrs[i]);
      }
    }
  }
out:

  if (corruption_cnt != 0) {
    printf("corruption_cnt should be 0, but it is %d\n", corruption_cnt);
    return false;
  }

  return true;
}
Example #14
0
//use a new meteor from the pool
void GameLayer::resetMeteor(void) {
    if (_fallingObjects->count() > 30) {
        return;
    }
    
    CCSprite * meteor = (CCSprite *) _meteorPool->objectAtIndex(_meteorPoolIndex);
    _meteorPoolIndex++;
    if (_meteorPoolIndex == _meteorPool->count()) {
        _meteorPoolIndex = 0;
    }
    
    int meteor_x = rand() % (int) (_screenSize.width * 0.8f) + _screenSize.width * 0.1f;
    int meteor_target_x = rand() % (int) (_screenSize.width * 0.8f) + _screenSize.width * 0.1f;
    
    meteor->stopAllActions();
    meteor->setPosition(ccp(meteor_x, _screenSize.height + meteor->boundingBox().size.height * 0.5));
    
    CCActionInterval * rotate = CCRotateBy::create(0.5f, -90);
    CCAction * repeatRotate = CCRepeatForever::create(rotate);
    CCFiniteTimeAction * sequence = CCSequence::create(CCMoveTo::create(_meteorSpeed, ccp(meteor_target_x, _screenSize.height * 0.15f)), CCCallFuncN::create(this, callfuncN_selector(GameLayer::fallingObjectDone)), NULL);
    
    meteor->setVisible(true);
    meteor->runAction(repeatRotate);
    meteor->runAction(sequence);
    _fallingObjects->addObject(meteor);
}
//this function is called after each timeout, which iterates the CA
gint loopThrough(gpointer data) {
    //if autoReset is toggled, find if row is all black or all white,
    // and reset if it is either
    if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(autoResetButton))) {
        int sum = ca1->getRowSum();
        if ((sum < ROW_LOWER_BOUND) || (sum > DEFAULT_WIDTH)) {
            ca1->resetCells();
        }
    }

    //if meta-rules have been loaded, apply them here
    if (rules.size() > 0) {
        if ((numLines % ruleChangeInterval == 0) && (numLines != 0)) {
            int seed = rand() % rules.size();
            ca1->setRule(rules[seed]);
            std::cout << "changing rule to " << rules[seed] << std::endl;
            if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(randomizeLengthButton))) {
                ruleChangeInterval=rand() % maxRuleChangeInterval + 1;
            }
        }
    }

    //calculate the new row, iterate the automaton
    ca1->calcNewRow();

    //redraw the image
    redrawImage();

    //if auto-saving pics, activate here
    if ((numLines % HEIGHT == 0) && savePics) {
        getPic(data);
    }
    return TRUE;
}
Example #16
0
//Bullet_ricochet//////////////////////////////////////////////////////////////////////
Bullet_ricochet::Bullet_ricochet(Entity* from, Vec2 direction)
{
	//Random number not properly seeded yet
	expiry_timer = Timer(50);

	Sprite_sheet* _particle_image = new Sprite_sheet("media/images/ricochet.bmp");
	//_particle_image->load_sheet();
	double spread_percentage = 0.05;
	double speed_variance = 20;
	double base_speed = 35;
	
	for(unsigned int i =0; i<20; i++)//Randomise the 20?
	{
		double spread_number = ((double)(rand() % 1000))/1000*spread_percentage - spread_percentage/2;
		double speed = rand() % (int)speed_variance - (double)speed_variance/2 + base_speed;

		Entity* _new_particle = new Entity(_particle_image);
		_new_particle->set_all_positions(from->outside_position(direction));
		//std::cout << "Speed num: " << spread_number << "\n";
		//_new_particle->set_velocity(Vec2(0,0));
		_new_particle->set_velocity(direction.unit().rotate(spread_number*2*3.14)*(speed)); //*((double)1/10)//Induce some spread here //Randomise the spread
		particles.push_back(_new_particle);
		
	}
	expiry_timer.start();
}
Example #17
0
void pressSpeedKey() {
    int f, key;

    for (f = 0; f < 51; ++f) {
        BIFROSTH_setTile(rand()%9, rand()%9, rand()%8);
    }
    in_wait_nokey();

    printInk(7);
    printAt(22, 1);
    printf("CHOOSE SPEED 2-4 OR 0 TO EXIT");

    while ((key = in_inkey()) != '0') {
        switch (key) {
            case '2':
                BIFROSTH_resetAnimSlow();
                printInk(5);
                printAt(20, 25);
                printf(" slow)");
                break;
            case '4':
                BIFROSTH_resetAnimFast();
                printInk(5);
                printAt(20, 25);
                printf(" fast)");
                break;
        }
    }

    printAt(22, 1);
    printf("                             ");
}
Example #18
0
void test_add_all_get_count()
{
	std::cout << "test: add all words then get count of random words" << std::endl;
	
	std::vector<std::string> words = getWordList("data/28885.txt");
	std::ofstream out("data/28885.txt.out" + OUT_FILE);

	std::random_device rd;
	std::default_random_engine rand(rd());

	TRENDS_CLASS tr;

	for (unsigned int i = 0; i < words.size(); i++){
		tr.increaseCount(words[i], 1);
	}

	double start = getTimeInMillis();

	for (unsigned int i = 0; i < words.size(); i++) {
		std::string w = words[rand() % words.size()];
		unsigned int temp = tr.getCount(w);
		out << w << " " << temp << "\n";
	}	

	double end = getTimeInMillis();

	out.close();

	std::cout << "time per item: " << (end - start) / words.size() << " ms " << std::endl
		  << "total time: " << (end - start) << " ms" << std::endl << std::endl;
}
Example #19
0
Enchere IA::encherir(Enchere ancienneEnchere){
    int enchereAncienne = ancienneEnchere.getValeur();
    if(enchereAncienne == 160){
        return Enchere();
    }
    int enchere = enchereAncienne + 10;
    if((rand()%3) < 2){
        return Enchere();
    }else{
        Couleur col;
        int v = rand()%4;
        switch(v){
        case 0:
            col = coeur;
            break;
        case 1:
            col = pique;
            break;
        case 2:
            col = trefle;
            break;
        case 3:
            col = carreau;
            break;
        default:
            col = defc;
        }
        return Enchere(enchere, col);
    }
}
Example #20
0
void test_hardest(void)
{
	std::cout << "test: add all words, get a random nth popular word, increase that "
		  << "words count by 1 then get the most common word along with its count" << std::endl;
	
	std::vector<std::string> words = getWordList("data/28885.txt");

	std::random_device rd;
	std::default_random_engine rand(rd());

	TRENDS_CLASS tr;

	for (unsigned int i = 0; i < words.size(); i++){
		tr.increaseCount(words[i], 1);
	}

	double start = getTimeInMillis();

	for (unsigned int i = 0; i < words.size(); i++) {
		unsigned int temp = rand() % tr.numEntries();
		std::string word = tr.getNthPopular(temp);
		tr.increaseCount(word, 1);

		word = tr.getNthPopular(0);
		temp = tr.getCount(word);
	}

	double end = getTimeInMillis();

	std::cout << "time per item: " << (end - start) / words.size() << " ms " << std::endl
		  << "total time: " << (end - start) << " ms" << std::endl << std::endl;
}
 void Reset()
 {
     Haste_Timer = 15000+rand()%8000;
     SpellReflection_Timer = 30000;
     MortalWound_Timer = 8000;
     WingBuffet_Timer = 25000+rand()%10000;
 }
void ResetParticles::update(float delta)
{
	float playerDist = m_player->getPosition().distance(getPosition());
	if (playerDist < 0)
		playerDist *= -1;
	for (int i = 0; i < m_particles->size(); i++)
	{
		if (m_particles->at(i)->getPosition().distance(getPosition()) <= m_particleResetRange)
		{
			m_particles->at(i)->Reset();
			if (m_deleteSelf)
			{
				Delete();
				return;
			}
		}
	}
	if (!m_isFollowing)
	{
		if (m_playerDetectRange > 0 && playerDist <= m_playerDetectRange)
		{
			m_isFollowing = true;
		}
		if ((m_followOffset).distance(getPosition()) > m_speed/2.0)
		{
			cocos2d::Vec2 dirVector = ((m_origPos + m_followOffset) - getPosition()).getNormalized();
			setPosition(dirVector * m_speed/2.0 + getPosition());
			float offsetDif = (m_origPos.y + m_followOffset.y) - getPositionY();
			if (offsetDif <= 1.4 && offsetDif >= -1.4)
				m_followOffset = cocos2d::Vec2(rand() % 50 - 25, rand() % 50 - 25);
			else
			{
				setPosition((cocos2d::Vec2(((float)(rand() % 50)) / 100.0f - 15.0f, (m_origPos.y + m_followOffset.y) - getPositionY()).getNormalized()  * m_speed / 2.0 / 3.0f) + getPosition());
			}
		}
		else
		{
			m_followOffset = cocos2d::Vec2(rand() % 50 - 25, rand() % 50 - 25);
		}
	}
	else if (m_isFollowing)
	{
		if ((m_player->getPosition() + m_followOffset).distance(getPosition()) > m_speed)
		{
			cocos2d::Vec2 dirVector = ((m_player->getPosition() + m_followOffset) - getPosition()).getNormalized();
			setPosition(dirVector * m_speed + getPosition());
			float offsetDif = (m_player->getPositionY() + m_followOffset.y) - getPositionY();
			if (offsetDif <= 1.4 && offsetDif >= -1.4)
				m_followOffset = cocos2d::Vec2(rand() % 50 - 25, rand() % 50 - 25);
			else
			{
				setPosition((cocos2d::Vec2(((float)(rand() % 50)) / 100.0f - 15.0f, (m_player->getPosition().y + m_followOffset.y) - getPositionY()).getNormalized()  * m_speed / 3.0f) + getPosition());
			}
		}
		else
		{
			m_followOffset = cocos2d::Vec2(rand() % 50 - 25, rand() % 50 - 25);
		}
	}
}
Example #23
0
inline long long RAND() {
  long long x = rand();
  x = (x << 15) | rand();
  x = (x << 15) | rand();
  x = (x << 15) | rand();
  return x;
}
Example #24
0
    void BenchmarkLines(const char *msg, wxDC& dc)
    {
        if ( opts.mapMode != 0 )
            dc.SetMapMode(opts.mapMode);
        if ( opts.penWidth != 0 )
            dc.SetPen(wxPen(*wxWHITE, opts.penWidth));

        wxPrintf("Benchmarking %s DC: ", msg);

        wxStopWatch sw;
        int x = 0,
            y = 0;
        for ( int n = 0; n < opts.numLines; n++ )
        {
            int x1 = rand() % opts.width,
                y1 = rand() % opts.height;

            dc.DrawLine(x, y, x1, y1);

            x = x1;
            y = y1;
        }

        const long t = sw.Time();

        wxPrintf("%d lines done in %lums = %gus/line\n",
                 opts.numLines, t, (1000. * t)/opts.numLines);
    }
Example #25
0
void gen3(int number) {
  sprintf(input, "%s%d.in", name, number);
  out = fopen(input, "w");
  
  if (number & 1) std::random_shuffle(p2, p2 + 20); 
  
  fprintf(out, "%d\n", 5);
  for (int tt = 0; tt <= 4; ++tt) {
    n = 100000 - tt * 5000 - rand(); 
    m = 100000 - tt * 5000 - rand();  
    C = 0;
    D = 0;
    if (number & 1) fprintf(out, "%d %d %d %d %d\n", n, m, C, D, p2[tt]);
    else fprintf(out, "%d %d %d %d %d\n", n, m, C, D, 500000000 + Rand() % M2);

    bo.clear();
    bo[mp(1, 1)] = bo[mp(n, m)] = true;
    for (int i = 1; i <= C; ++i) {
      int x, y;
      do {
        x = Rand() % n + 1;
        y = Rand() % m + 1;
      } while (bo[mp(x, y)]);
      bo[mp(x, y)] = true;
      fprintf(out, "%d %d\n", x, y);
    }
  }
}
Example #26
0
int update_FOG(UPDATE_FUNC_ARGS) {
    int r, rx, ry;
    for (rx=-1; rx<2; rx++)
        for (ry=-1; ry<2; ry++)
            if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
            {
                r = pmap[y+ry][x+rx];
                if (!r && rand()%2500==0)
                {
                    if (parts[i].temp > 253.15)
                    {
                        create_part(-1, x+rx, y+ry, PT_WATR);
                        kill_part(i);
                    }
                    else
                    {
                        create_part(-1, rx+rx, y+ry, PT_SNOW);
                        part_change_type(i,x,y,PT_SNOW);
                    }
                }
                if (!r)
                    continue;
                if (ptypes[r&0xFF].state==ST_SOLID&&5>=rand()%50&&parts[i].life==0&&!((r&0xFF)==PT_CLNE||(r&0xFF)==PT_PCLN)) // TODO: should this also exclude BCLN?
                {
                    part_change_type(i,x,y,PT_RIME);
                }
                if ((r&0xFF)==PT_SPRK)
                {
                    parts[i].life += rand()%20;
                }
            }
    return 0;
}
// Helper function for checking if a piece type has any available moves.
// Arguments are: a vector with the positions of the pieces of that type on the
// board; a pointer to a function that generates possible moves for that piece
// type; a bool for checking the color of the engine.
//
// Returns 1 if a valid move lead to victory, 0 if a simple valid move was
// found, -1 if no valid move was found.
int ChessBoard::random_piece_helper(std::vector<int> piece_positions,
								  std::vector<int> (* generate)(int, bool),
								  bool isWhite) {
	int chosen_piece, next_pos;			  
	while (piece_positions.size() != 0) {
		chosen_piece = rand() % piece_positions.size();
		std::vector<int> valid_final_moves =
							generate(piece_positions[chosen_piece], isWhite);
		
		while (valid_final_moves.size() != 0) {
			next_pos = rand() % valid_final_moves.size();
			if (try_moving_piece(piece_positions[chosen_piece],
								valid_final_moves[next_pos],
								isWhite)) {
				//if (winner(isWhite))
				//	return 1;
				return 0;
			}
			valid_final_moves.erase(valid_final_moves.begin() + next_pos);
		}
		if (table->pieces[piece_positions[chosen_piece]].name == 'K' ||
			table->pieces[piece_positions[chosen_piece]].name == 'k')
			return -1;
		piece_positions.erase(piece_positions.begin() + chosen_piece);
	}
	return -1;
}
Example #28
0
void Terrain::calculate_terrain()
{
    module::Perlin perlinModule;
    perlinModule.SetPersistence(0.25);
    utils::NoiseMap heightMap;
    utils::NoiseMapBuilderPlane heightMapBuilder;
    heightMapBuilder.SetSourceModule(perlinModule);
    heightMapBuilder.SetDestNoiseMap(heightMap);

    heightMapBuilder.SetDestSize(FIELD_WIDTH, FIELD_HEIGHT);

    //make these values random
    int x = rand() % 10;
    int y = rand() % 10;

    heightMapBuilder.SetBounds(x, x+10, y, y+10);
    heightMapBuilder.Build();

    for (int i = 0; i < FIELD_WIDTH; i++)
    {
        for (int j = 0; j < FIELD_HEIGHT; j++)
        {
            Space * sp = new Space();
            field[i][j] = Cell(i, j, sp);

            if (heightMap.GetValue(i, j) > 0.6)
            {
                field[i][j].set_sp(new AsteroidField());
            }
        }
    }
}
Example #29
0
int _tmain(int argc, _TCHAR* argv[])
{
	int v1 = rand();
	int v2 = rand();
  	  int myints[] = {v1,v2,88,55,81,31,26,77,17,20,29,22,14,48};
	  std::vector<int> v(myints,myints+14);

	  std::make_heap (v.begin(),v.end());
	  std::cout << "initial max heap   : " << v.front() << '\n';

	  std::cout << "final sorted range :";
	  for (unsigned i=0; i<v.size(); i++)
		std::cout << ' ' << v[i];

	  std::pop_heap (v.begin(),v.end()); v.pop_back(); 
	  std::pop_heap (v.begin(),v.end()); v.pop_back(); 
	  std::cout << "\n max heap after double pop : " << v.front() << '\n';

	  
	  //sorts it to a min heap
	  std::sort_heap (v.begin(),v.end());

	  //reverses min heap to make max heap
	  std::reverse(v.begin(),v.end());
	  
	  //prints heap values
	  std::cout << "\n final sorted range :";
      for (unsigned i=0; i<v.size(); i++)
		std::cout << ' ' << v[i];


	  std::cout << '\n';
	  std::system("Pause");
	return 0;
}
Example #30
0
void GeneticClass::Crossover(int parent1, int parent2, vector<int> &child1, vector<int> &child2){
	int child1Size, child2Size, cutpoint1, cutpoint2;
	int parsiz1 = chromosom[parent1].size();
	int parsiz2 = chromosom[parent2].size();
	do
	{
		cutpoint1 = rand() % chromosom[parent1].size();
		cutpoint2 = rand() % chromosom[parent2].size();

		child1Size = cutpoint1 + chromosom[parent2].size() - cutpoint2;
		child2Size = cutpoint2 + chromosom[parent1].size() - cutpoint1;
	} while ((child2Size > GraphClass::vertex) || (child1Size > GraphClass::vertex));

	child1.resize(GraphClass::vertex);
	child2.resize(GraphClass::vertex);

	copy(chromosom[parent1].begin(), chromosom[parent1].begin() + cutpoint1, child1.begin());
	copy(chromosom[parent2].begin() + cutpoint2, chromosom[parent2].end(), child1.begin() + cutpoint1);

	copy(chromosom[parent2].begin(), chromosom[parent2].begin() + cutpoint2, child2.begin());
	copy(chromosom[parent1].begin() + cutpoint1, chromosom[parent1].end(), child2.begin() + cutpoint2);	

	child1.resize(cutpoint1 + chromosom[parent2].size() - cutpoint2);
	child2.resize(cutpoint2 + chromosom[parent1].size() - cutpoint1);
	repair(child1, child2);
}