Exemplo n.º 1
0
    virtual void test_by_pict()
    {
        Mat frame1 = readImage("optflow/RubberWhale1.png", IMREAD_GRAYSCALE);

        UMat usrc;
        frame1.copyTo(usrc);
        int histSize = randomInt(3, 29);
        float hue_range[] = { 0, 180 };
        const float* ranges1 = { hue_range };
        Mat hist1;

        //compute histogram
        calcHist(&frame1, 1, 0, Mat(), hist1, 1, &histSize, &ranges1, true, false);
        normalize(hist1, hist1, 0, 255, NORM_MINMAX, -1, Mat());

        Mat dst1;
        UMat udst1, src, uhist1;
        hist1.copyTo(uhist1);
        std::vector<UMat> uims;
        uims.push_back(usrc);
        std::vector<float> urngs;
        urngs.push_back(0);
        urngs.push_back(180);
        std::vector<int> chs;
        chs.push_back(0);

        OCL_OFF(calcBackProject(&frame1, 1, 0, hist1, dst1, &ranges1, 1, true));
        OCL_ON(calcBackProject(uims, chs, uhist1, udst1, urngs, 1.0));
        EXPECT_MAT_NEAR(dst1, udst1, 0.0);
    }
Exemplo n.º 2
0
void Aircraft::checkPickupDrop(CommandQueue& commands)
{
	if (!isAllied() && randomInt(3) == 0 && !mSpawnedPickup)
		commands.push(mDropPickupCommand);

	mSpawnedPickup = true;
}
Exemplo n.º 3
0
uint32 MersenneTwister::randomIntRange (uint32 start, uint32 end) 
{
	lela_check (end > start);

	uint32 dist = end - start;
	uint32 random;

	/* All tricks doing modulo calculations do not have a perfect
	 * distribution -> We must use the slower way through gdouble for
	 * maximal quality. */
   
	if (dist <= 0x10000L) { /* 2^16 */
		/* This method, which only calls g_rand_int once is only good
		 * for (end - begin) <= 2^16, because we only have 32 bits set
		 * from the one call to g_rand_int (). */

		/* we are using (trans + trans * trans), because g_rand_int only
		 * covers [0..2^32-1] and thus g_rand_int * trans only covers
		 * [0..1-2^-32], but the biggest double < 1 is 1-2^-52. 
		 */

		double double_rand =
			randomInt () * (doubleTransform + doubleTransform * doubleTransform);
      
		random = (uint32) (double_rand * dist);
	} else {
		/* Now we use g_rand_double_range (), which will set 52 bits for
		   us, so that it is safe to round and still get a decent
		   distribution */
		random = (uint32) randomDoubleRange (0, dist);
	}
 
	return start + random;
}
Exemplo n.º 4
0
void LineViewer::adaptFlora(int pts){
	int flora_pts = this->getTotalPoints();
	int nOrganisms = this->getNOrganisms();
	int diff = pts - (flora_pts - nOrganisms);
	
	if(pts-1 > flora_pts){
		int index = 0;

		while(diff > 0){
			index = randomInt(0,this->getNOrganisms()-1);

			if(diff % 2){
				//mitosis 2
				this->flora->at(index)->mitosis(2);
				diff -= 2;
				flora_pts += 2;
			}
			else{
				//mitosis 1
				this->flora->at(index)->mitosis(1);
				diff--;
				flora_pts++;
			}

			if(this->getPointsOfOrganism(index) > 5){
				//split
				LineOrganism *org1 = NULL,*org2 = NULL;
				if(instance->flora->at(index)->split(&org1,&org2)){
					instance->getFlora()->insert(instance->getFlora()->begin() + index + 1,org1);
					instance->getFlora()->insert(instance->getFlora()->begin() + index + 2,org2);
					instance->flora->erase(instance->flora->begin() + index);
					diff--;
					nOrganisms++;
				}
			}
		}

		printf("");
	}
	else{
		while(diff < 0){
			int index = this->getNOrganisms()-1;

			if(abs(diff) > this->getPointsOfOrganism(index)){
				diff += this->getPointsOfOrganism(index);
				this->getFlora()->pop_back();
			}
			else{
				if(this->getPointsOfOrganism(index) > 4){
					this->getFlora()->at(index)->dropPoint(2);
					diff+=2;
				}
				else{
					this->getFlora()->at(index)->dropPoint(1);
					diff++;
				}
			}
		}
	}	
}
Exemplo n.º 5
0
void Pirate::genType()
{
	int t = randomInt(1,100);
	if( t<34 ) type = "dorc";
	else if(t>=34&&t<66) type = "porc";
	else type = "borc";
}
Exemplo n.º 6
0
QByteArray SecureRNG::randomPrintable(int length)
{
    QByteArray re(length, 0);
    for (int i = 0; i < re.size(); i++)
        re[i] = randomInt(95) + 32;
    return re;
}
Exemplo n.º 7
0
void GeneticPopulation::crossover(
	const Weights& parent1,
	const Weights& parent2,
	Weights& child1,
	Weights& child2) const {

	assert(parent1.size() == parent2.size());

	if (randomReal(0, 1) > crossoverRate || parent1 == parent2) {
		child1 = parent1;
		child2 = parent2;
		return;
	}

	unsigned crossoverPoint = static_cast<unsigned>(randomInt(0, parent1.size()));

	child1.clear();
	child2.clear();

	//create the offspring
	for (unsigned i = 0; i < crossoverPoint; ++i) {
		child1.push_back(parent1[i]);
		child2.push_back(parent2[i]);
	}

	for (unsigned i = crossoverPoint; i < parent1.size(); ++i) {
		child1.push_back(parent2[i]);
		child2.push_back(parent1[i]);
	}
}
Exemplo n.º 8
0
KategProblem &makRandom(int ANZ_WORD,int ANZ_CLS,int initValue,
			int auswertung,int nachbarschaft,float relInit)
{
  KategProblem &k=
    *new KategProblem(ANZ_WORD,ANZ_CLS,initValue,auswertung,nachbarschaft);
  KategProblemWBC &w=k.wordFreq;
  Array<int> after(ANZ_WORD,0);
  Array<int> before(ANZ_WORD,0);
  Array<FreqArray> twoD(ANZ_WORD);
	int i;
  for(i=0;i<ANZ_WORD;i++) twoD[i].init(ANZ_WORD,0); 
  
  for(i=0;i<ANZ_WORD;i++)
    {
      massert(after[i]==0);
      massert(before[i]==0);
      for(int j=0;j<ANZ_WORD;j++)
	{
	  massert(twoD[i][j]==0);
	}
    }
  for(i=0;i<ANZ_WORD*ANZ_WORD*relInit;i++)
    {
      int x=randomInt(ANZ_WORD);
      int y=randomInt(ANZ_WORD);
      if(twoD[x][y]==0)
	{
	  after[x]++;
	  before[y]++;
	}
      twoD[x][y]+=randomInt(10)+1;
    }
  for(i=0;i<ANZ_WORD;i++)
    {
      w.setAfterWords(i,after[i]);
      w.setBeforeWords(i,before[i]);
    }
  
  for(i=0;i<ANZ_WORD;i++)
    {
      for(int j=0;j<ANZ_WORD;j++)
	if( twoD[i][j] )
	    w.setFreq(i,j,twoD[i][j]);
    }
  w.testFull();
  return k;
}
Exemplo n.º 9
0
void KruskalMaze::generate()
{
	// Generate sets
	m_set_ids = QVector< QVector<Set*> >(columns(), QVector<Set*>(rows()));
	for (int c = 0; c < columns(); ++c) {
		for (int r = 0; r < rows(); ++r) {
			m_sets.append(QList<QPoint>() << QPoint(c, r));
			m_set_ids[c][r] = &m_sets.last();
		}
	}

	while (m_sets.size() > 1) {
		Set* set1 = &m_sets.first();

		// Find random cell
		const QPoint& cell = set1->at(randomInt(set1->size()));

		// Find random neighbor of cell
		QPoint cell2(cell);
		if (randomInt(2)) {
			cell2.rx()++;
		} else {
			cell2.ry()++;
		}
		if (cell2.x() >= columns() || cell2.y() >= rows()) {
			continue;
		}

		// Find set containing second cell
		Set* set2 = m_set_ids.at(cell2.x()).at(cell2.y());

		// Merge sets if they are different
		if (set1 != set2) {
			mergeCells(cell, cell2);
			int size = set1->size();
			for (int i = 0; i < size; ++i) {
				const QPoint& cell3 = set1->at(i);
				m_set_ids[cell3.x()][cell3.y()] = set2;
			}
			*set2 += *set1;
			m_sets.removeFirst();
		}
	}

	m_sets.clear();
	m_set_ids.clear();
}
Exemplo n.º 10
0
void MainWindow::startGrid()
{
    int i,j,k,l;
    score = 0;
    max = 0;
    for( i=0;i<4;i++ )
        for( j=0;j<4;j++ )
            grid[i][j] = 0;
    i = randomInt(4);
    j = randomInt(4);
    grid[i][j] = 2;
    do{
        k = randomInt(4);
        l = randomInt(4);
    }while( k==i && l==j);
    grid[k][l] = 2;
}
Exemplo n.º 11
0
    GpuMat createMat(Size size, int type, bool useRoi)
    {
        Size size0 = size;

        if (useRoi)
        {
            size0.width += randomInt(5, 15);
            size0.height += randomInt(5, 15);
        }

        GpuMat d_m(size0, type);

        if (size0 != size)
            d_m = d_m(Rect((size0.width - size.width) / 2, (size0.height - size.height) / 2, size.width, size.height));

        return d_m;
    }
Exemplo n.º 12
0
void
render(SDL_Renderer *renderer)
{
    Uint8 r, g, b;
    int renderW;
    int renderH;

    SDL_RenderGetLogicalSize(renderer, &renderW, &renderH);

    /*  Come up with a random rectangle */
    SDL_Rect rect;
    rect.w = randomInt(64, 128);
    rect.h = randomInt(64, 128);
    rect.x = randomInt(0, renderW);
    rect.y = randomInt(0, renderH);

    /* Come up with a random color */
    r = randomInt(50, 255);
    g = randomInt(50, 255);
    b = randomInt(50, 255);

    /*  Fill the rectangle in the color */
    SDL_SetRenderDrawColor(renderer, r, g, b, 255);
    SDL_RenderFillRect(renderer, &rect);

    /* update screen */
    SDL_RenderPresent(renderer);
}
Exemplo n.º 13
0
Arquivo: main.c Projeto: 0-wiz-0/mame
void
render(SDL_Renderer *renderer)
{

    Uint8 r, g, b;

    /* Clear the screen */
    SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
    SDL_RenderClear(renderer);

    /*  Come up with a random rectangle */
    SDL_Rect rect;
    rect.w = randomInt(64, 128);
    rect.h = randomInt(64, 128);
    rect.x = randomInt(0, SCREEN_WIDTH);
    rect.y = randomInt(0, SCREEN_HEIGHT);

    /* Come up with a random color */
    r = randomInt(50, 255);
    g = randomInt(50, 255);
    b = randomInt(50, 255);
    SDL_SetRenderDrawColor(renderer, r, g, b, 255);

    /*  Fill the rectangle in the color */
    SDL_RenderFillRect(renderer, &rect);

    /* update screen */
    SDL_RenderPresent(renderer);
}
Exemplo n.º 14
0
        static std::vector<int> randomInts(int howMany, int min, int max) {
            std::vector<int> ints;

            for (int index = 0; index < howMany; index++) {
                ints.push_back(randomInt(min, max));
            }

            return ints;
        }
Exemplo n.º 15
0
static void initPopulation() {

    int cromosomeIdx;
    int blocks;
    int threads;

    for (cromosomeIdx = 0; cromosomeIdx < POPULATION_NMR; ++cromosomeIdx) {
        
        do {
            blocks = randomInt(columns - 1) + 1;
            threads = randomInt(columns - 1) + 1;
        } while (2l * blocks * threads >= (long) columns 
            || threads > MAX_THREADS || blocks > MAX_BLOCKS);

        population[cromosomeIdx].blocks = blocks;
        population[cromosomeIdx].threads = threads;
    }
}
Exemplo n.º 16
0
void Tile::checkPickupDrop(CommandQueue& commands)
{
	// Drop pickup, if enemy airplane, with probability 1/4, if pickup not yet dropped
	// and if not in network mode (where pickups are dropped via packets)
	if (isBlock() && randomInt(5) == 0 && !mSpawnedPickup && mPickupsEnabled){
		commands.push(mDropPickupCommand);
	}
	mSpawnedPickup = true;
}
Exemplo n.º 17
0
char * corrupt_bits(char * data, size_t * dataSz)
{
  size_t bitsToCorrupt = randomInt(0, 20);
  size_t i;

  // Flip the MSB of a random amount of bytes
  
  for(i = 0; i < bitsToCorrupt; i++)
  {
    size_t off = random_offset(*dataSz);
    size_t bit = randomInt(0, 7);

    // flip the bit
    data[off] = data[off] ^ (1 << bit);
  }

  return data;
}
Exemplo n.º 18
0
/// <summary>
/// Adds a particle.
/// </summary>
/// <param name="position">The position.</param>
void ParticleSystem::addParticle(sf::Vector2f position)
{
	mVertexNeedsUpdate = true;

	Particle particle;
	particle.position = position;
	particle.type = mType;
	particle.lifeTime = Table[mType].lifetime;

	// Trail Particles don't need velocity or angle since they dont move
	if (mType != Particle::Trail)
	{
		particle.velocity = (randomInt(2) + 1) * Table[mType].maxVelocity;
		particle.angle = randomInt(361);
	}

	mParticles.push_back(particle);
}
Exemplo n.º 19
0
void Aircraft::createPickup(SceneNode& node, const TextureHolder& textures) const
{
	auto type = static_cast<Pickup::Type>(randomInt(Pickup::TypeCount));

	std::unique_ptr<Pickup> pickup(new Pickup(type, textures));
	pickup->setPosition(getWorldPosition());
	pickup->setVelocity(0.f, 1.f);
	node.attachChild(std::move(pickup));
}
Exemplo n.º 20
0
void RecursiveBacktrackerMaze::generate()
{
	m_visited = QVector< QVector<bool> >(columns(), QVector<bool>(rows()));

	QPoint start(0, randomInt(rows()));
	m_visited[start.x()][start.y()] = true;
	makePath(start);

	m_visited.clear();
}
TEST( SequencerController, Rewind )
{
    SequencerController* controller = new SequencerController();

    int minPosition                  = randomInt( 0, 44100 );
    int maxPosition                  = randomInt( 88200, 192000 );
    AudioEngine::min_buffer_position = minPosition;
    AudioEngine::max_buffer_position = maxPosition;

    controller->setBufferPosition( randomInt( AudioEngine::min_buffer_position + 1,
                                              AudioEngine::max_buffer_position - 1 ));

    controller->rewind();

    EXPECT_EQ( minPosition, AudioEngine::min_buffer_position )
        << "expected engine to have 'rewound'";

    delete controller;
}
Exemplo n.º 22
0
void Controller::generate()
{
	int random_number  = randomInt(1,100);
	if(random_number<51&&WarriorList->getSize()<25)
	{
		Pirate *p = new Pirate();
		p->setX(0);
		p->setY(randomInt(1,6));
		WarriorList->push(p);
		
	}
	if(random_number>34&&WarriorList->getSize()<25)
	{
		Soldier *s = new Soldier();
		s->setY(randomInt(2,4));
		s->setX(24);
		WarriorList->push(s);
	}
}
Exemplo n.º 23
0
TEST( WaveTable, Accumulator )
{
    int length       = randomInt( 2, 256 );
    float frequency  = randomFloat( 20, 880 );
    WaveTable* table = new WaveTable( length, frequency );

    EXPECT_EQ( 0.0, table->getAccumulator() )
        << "expected WaveTable accumulator to be 0.0 upon construction";

    for ( int i = 0; i < randomInt( 1, 100 ); ++i )
    {
        SAMPLE_TYPE value = randomSample( 0.0, ( SAMPLE_TYPE ) length );
        table->setAccumulator( value );

        EXPECT_EQ( value, table->getAccumulator() )
            << "expected WaveTable accumulator to be " << value << " after setter, got " << table->getAccumulator() << " instead";
    }
    delete table;
}
TEST( SequencerController, GetSetBufferPosition )
{
    SequencerController* controller = new SequencerController();

    int minBufferPos = randomInt( 0, 5512 );
    int maxBufferPos = randomInt( minBufferPos + 1, minBufferPos + 44100 );

    AudioEngine::min_buffer_position = minBufferPos;
    AudioEngine::max_buffer_position = maxBufferPos;
    AudioEngine::bufferPosition      = randomInt( minBufferPos, maxBufferPos );

    // test 1. test getter

    EXPECT_EQ( AudioEngine::bufferPosition, controller->getBufferPosition() )
        << "expected SequencerController to return the buffer position";

    // test 2. test setter

    int newPosition = randomInt( minBufferPos, maxBufferPos );
    controller->setBufferPosition( newPosition );

    EXPECT_EQ( newPosition, controller->getBufferPosition() )
        << "expected SequencerController to have updated the buffer position";

    // test 3. sanitation of existing out-of-range position

    newPosition = minBufferPos - 1; // force current position to be below range

    controller->setBufferPosition( newPosition );

    EXPECT_EQ( minBufferPos, controller->getBufferPosition() )
        << "expected SequencerController to have sanitized the current buffer position";

    newPosition = maxBufferPos + 1; // force current position to be above range

    controller->setBufferPosition( newPosition );

    EXPECT_EQ( minBufferPos, controller->getBufferPosition() )
        << "expected SequencerController to have sanitized the current buffer position";

    delete controller;
}
TEST( SequencerController, GetStepPosition )
{
    SequencerController* controller = new SequencerController();

    AudioEngine::stepPosition = randomInt( 1, 16 );

    EXPECT_EQ( AudioEngine::stepPosition, controller->getStepPosition() )
        << "expected SequencerController to have returned the current step position";

    delete controller;
}
TEST( SequencerController, GetSamplesPerBar )
{
    SequencerController* controller = new SequencerController();

    AudioEngine::samples_per_bar = randomInt( 512, 8192 );

    EXPECT_EQ( AudioEngine::samples_per_bar, controller->getSamplesPerBar() )
        << "expected SequencerController to have returned samples per bar";

    delete controller;
}
Exemplo n.º 27
0
void PrimMaze::generate()
{
	// Generate cell lists
	m_regions = QVector< QVector<int> >(columns(), QVector<int>(rows(), 0));

	// Move first cell
	QPoint cell(0, randomInt(columns()));
	m_regions[0][cell.y()] = 2;
	moveNeighbors(cell);

	// Move remaining cells
	while (!m_frontier.isEmpty()) {
		cell = m_frontier.takeAt(randomInt(m_frontier.size()));
		mergeRandomNeighbor(cell);
		m_regions[cell.x()][cell.y()] = 2;
		moveNeighbors(cell);
	}

	m_regions.clear();
}
Exemplo n.º 28
0
// update all enemies
// spawn new enemies if available
void Spawner::update(float dT)
{
	// only spawn new enemies if alive
	if(alive)
	{
		// if health is below 0 it is dead
		if(curHealth <= 0.0f)
			alive = false;
		// update cool downs
		CoolDownCtrl(dT, canSpawn);

		/// check on enemy count
		if(m_enemies.size() < max_enemies && !canSpawn.active)
		{
			// spawn a new enemy
			m_enemies.add( new Enemy );
			// generate a new position next to me that is free
			int x = 0, y = 0;
			do
			{
				x = randomInt(-1,1) + m_roomPOS.x;
				y = randomInt(-1,1) + m_roomPOS.y;
			}while( m_room->checkLocation(x,y).m_type != FLOOR || (x-m_roomPOS.x == 0 && y-m_roomPOS.y == 0) );
			// initialize that enemy with the given position
			m_enemies.get( m_enemies.size()-1 )->initialize(spawnType,thePlayer, 
				V2DF( (x * TEX_SIZE) + HALF_TEX + BORDER, (y * TEX_SIZE) + HALF_TEX + BORDER ), m_room);
			// start spawn cool down
			canSpawn.active = true;
		}
	}

	for(int i = 0; i < m_enemies.size(); ++i)
	{
		// check if any enemies are dead
		if(m_enemies.get(i)->checkHealth() <= 0.0f)
			m_enemies.removeFast(i);
		// incase the original enemy was killed make sure the next enemy exists and update them
		if(i < m_enemies.size())
			m_enemies.get(i)->update(dT);
	}
}
Exemplo n.º 29
0
	bool placeObject(char tile)
	{
		if (_rooms.empty())
			return false;

		int r = randomInt(_rooms.size()); // choose a random room
		int x = randomInt(_rooms[r].x + 1, _rooms[r].x + _rooms[r].width - 2);
		int y = randomInt(_rooms[r].y + 1, _rooms[r].y + _rooms[r].height - 2);

		if (getTile(x, y) == Floor)
		{
			setTile(x, y, tile);

			// place one object in one room (optional)
			_rooms.erase(_rooms.begin() + r);

			return true;
		}

		return false;
	}
Exemplo n.º 30
0
bool CCSSBot :: startGame ()
{
    // do whatever is necessary here to join the game...
    IPlayerInfo* pInfo = playerinfomanager->GetPlayerInfo(m_pEdict);

    if ( pInfo->GetTeamIndex() == 0 )
    {
        pInfo->ChangeTeam(randomInt(2,3));
    }

    return (pInfo->GetTeamIndex() != 0);
}