Exemplo n.º 1
0
void StringSetMonkey::append(UnicodeString &testCase, UnicodeString &alternate)
{
    int32_t itemCount = uset_getItemCount(set), len = 0;
    int32_t index = m_rand() % itemCount;
    UChar32 rangeStart = 0, rangeEnd = 0;
    UChar buffer[16];
    UErrorCode err = U_ZERO_ERROR;

    len = uset_getItem(set, index, &rangeStart, &rangeEnd, buffer, 16, &err);

    if (len == 0) {
        int32_t offset = m_rand() % (rangeEnd - rangeStart + 1);
        UChar32 ch = rangeStart + offset;
        UnicodeString str(ch);

        testCase.append(str);
        generateAlternative(str, alternate);
    } else if (len > 0) {
        // should check that len < 16...
        UnicodeString str(buffer, len);

        testCase.append(str);
        generateAlternative(str, alternate);
    } else {
        // shouldn't happen...
    }
}
Exemplo n.º 2
0
        void operator()(Engine& e, Configuration &c, double temp)
        {
            typedef typename Configuration::modification Modification;

            //1 & 2
            Modification modif;
            m_temperature = temp;
            detail::kernel_functor<Engine,Configuration,Modification> kf(e,c,modif);
            m_kernel_ratio = random_apply(m_kernel_id,m_rand(e),m_kernel,kf);

            //3
            m_ref_pdf_ratio = m_density.pdf_ratio(c,modif);
            m_green_ratio = m_kernel_ratio*m_ref_pdf_ratio;

            //4
            if(m_green_ratio<=0) {
                m_delta   =0;
                m_accepted=false;
                return;
            }
            m_delta       = c.delta_energy(modif);
            m_acceptance_probability  = m_acceptance(m_delta,m_temperature,m_green_ratio);

            //5
            m_accepted    = ( m_rand(e) < m_acceptance_probability );
            if (m_accepted) modif.apply(c);
            //modif.apply(c,m_accepted);
        }
Exemplo n.º 3
0
 void tetclone::restart()
 {
     m_gameover = false;
     std::array<color_t, width> row;
     std::fill(row.begin(), row.end(), color_t::non);
     std::fill(m_stockpile.begin(), m_stockpile.end(), row);
     
     m_current.tetromino = m_rand();
     m_current.angle = angle_t::Zero;
     m_current.pos = point2i{{0, 0}};
     m_next = m_rand();
     m_score = 0;
     m_level = 0;
     m_fall_speed = fall_speed(m_level);
 }
Exemplo n.º 4
0
int ShadowrunTool::randValue(int high, int low)
{
    std::mt19937 gen(m_rand());
    std::uniform_int_distribution<> dis(1, 6);
    return dis(gen);

}
Exemplo n.º 5
0
UnicodeString &StringSetMonkey::generateAlternative(const UnicodeString &testCase, UnicodeString &alternate)
{
    // find out shortest string for the longest sequence of ces.
    // needs to be refined to use dynamic programming, but will be roughly right
    UErrorCode status = U_ZERO_ERROR;
    CEList ceList(coll, testCase, status);
    UnicodeString alt;
    int32_t offset = 0;

    if (ceList.size() == 0) {
        return alternate.append(testCase);
    }

    while (offset < ceList.size()) {
        int32_t ce = ceList.get(offset);
        const StringList *strings = collData->getStringList(ce);

        if (strings == NULL) {
            return alternate.append(testCase);
        }

        int32_t stringCount = strings->size();
        int32_t tries = 0;

        // find random string that generates the same CEList
        const CEList *ceList2 = NULL;
        const UnicodeString *string = NULL;
              UBool matches = FALSE;

        do {
            int32_t s = m_rand() % stringCount;

            if (tries++ > stringCount) {
                alternate.append(testCase);
                return alternate;
            }

            string = strings->get(s);
            ceList2 = collData->getCEList(string);
            matches = ceList.matchesAt(offset, ceList2);

            if (! matches) {
                collData->freeCEList((CEList *) ceList2);
            }
        } while (! matches);

        alt.append(*string);
        offset += ceList2->size();
        collData->freeCEList(ceList2);
    }

    const CEList altCEs(coll, alt, status);

    if (ceList.matchesAt(0, &altCEs)) {
        return alternate.append(alt);
    }

    return alternate.append(testCase);
}
Exemplo n.º 6
0
void SetMonkey::append(UnicodeString &test, UnicodeString &alternate)
{
    int32_t size = uset_size(set);
    int32_t index = m_rand() % size;
    UChar32 ch = uset_charAt(set, index);
    UnicodeString str(ch);

    test.append(str);
    alternate.append(str); // flip case, or some junk?
}
Exemplo n.º 7
0
void Pinwheel::randomize_dir() {
	float sign_x = velocity_x / fabs(velocity_x);
	float sign_y = velocity_y / fabs(velocity_y);
	float velocity_x_old = velocity_x;
	float velocity_y_old = velocity_y;
	float angle = atanf(velocity_y / velocity_x);
	if (m_rand() % 3 == 0)
		angle += EPSILON;
	else
		angle -= EPSILON;
	velocity_x = sign_x * fabs(cosf(angle));
	velocity_y = sign_y * fabs(sinf(angle));
}
Exemplo n.º 8
0
 tetclone::tetclone()
     :
     m_stockpile(),
     m_current(),
     m_next(),
     m_gameover(false),
     m_level(),
     m_level_count(),
     m_level_step(level_step),
     m_fall_count(),
     m_fall_speed(fall_speed(m_level)),
     m_score(),
     m_gen(std::time(0))
 {
     std::array<color_t, width> row;
     std::fill(row.begin(), row.end(), color_t::non);
     std::fill(m_stockpile.begin(), m_stockpile.end(), row);
     
     m_current.tetromino = m_rand();
     m_current.angle = angle_t::Zero;
     m_current.pos = point2i{{0, 0}};
     m_next = m_rand();
 }
Exemplo n.º 9
0
//=============================================================================
// Main execution
//=============================================================================
StatusCode HistoTimingAlg::execute()
{

  for ( unsigned int iT = 0; iT < m_nTracks; ++iT )
  {

    // fill histos
    for ( HistoMap::iterator iH = m_histos.begin(); iH != m_histos.end(); ++iH )
    {
      if ( m_useGaudiAlg )
      {
        plot1D( m_rand(), iH->second, 0,1,100 );
      }
      else
      {
        iH->first->fill( m_rand() );
      }
    }

  }

  return StatusCode::SUCCESS;
}
Exemplo n.º 10
0
static void generateTestCase(UCollator *coll, Monkey *monkeys[], int32_t monkeyCount, UnicodeString &testCase, UnicodeString &alternate)
{
    int32_t pieces = (m_rand() % 4) + 1;
    UErrorCode status = U_ZERO_ERROR;
    UBool matches;

    do {
        testCase.remove();
        alternate.remove();
        monkeys[0]->append(testCase, alternate);

        for(int32_t piece = 0; piece < pieces; piece += 1) {
            int32_t monkey = m_rand() % monkeyCount;

            monkeys[monkey]->append(testCase, alternate);
        }

        const CEList ceTest(coll, testCase, status);
        const CEList ceAlt(coll, alternate, status);

        matches = ceTest.matchesAt(0, &ceAlt);
    } while (! matches);
}
Exemplo n.º 11
0
 void tetclone::on_down_bottom()
 {
     color_t c = color(m_current.tetromino);
     point2i const& p = m_current.pos;
     auto const& lay = layout(m_current.tetromino, m_current.angle);
     for(std::size_t i = 0; i < 4; ++i){
         int x = p[0] + lay[i][0];
         int y = p[1] + lay[i][1] * ydivision;
         int yp = y / ydivision + ((y % ydivision != 0) ? 1 : 0);
         m_stockpile[yp][x] = c;
     }
     
     namespace ph = std::placeholders;
     std::size_t lines = 0;
     auto it = m_stockpile.rbegin();
     auto end = m_stockpile.rend();
     static std::function<bool(color_t)> const is_color_non
         = std::bind(std::not_equal_to<color_t>(), color_t::non, ph::_1);
     while(it != end){
         if(std::all_of((*it).begin(), (*it).end(), is_color_non)){
             std::copy(it + 1, m_stockpile.rend(), it);
             ++lines;
         }else{
             ++it;
         }
     }
     m_score += mgame::score(lines);
     if(m_score >= score_limit) m_score = score_limit;
     
     m_current.tetromino = m_next;
     m_current.pos = point2i{{0, 0}};
     m_current.angle = angle_t::Zero;
     m_next = m_rand();
     
     auto const& lay2 = layout(m_current.tetromino, m_current.angle);
     for(std::size_t i = 0; i < 4; ++i){
         int x = lay2[i][0];
         int y = lay2[i][1];
         if(m_stockpile[y][x] != color_t::non){
             m_gameover = true;
             return;
         }
     }
 }
Exemplo n.º 12
0
void matlib_main()
{
    MATRIX *A, *B, *C;
    MATRIX *At, *Bt;
    long n, ni, i;
    double sum;

    random_1(-1);

    n = query_long("dimension of arrays", 3L);
    ni = query_long("number of iterations", 100L);

#ifdef VAX_VMS
    init_stats();
#endif

    m_alloc(&A, n, n);
    m_alloc(&At, n, n);
    m_alloc(&B, n, n);
    m_alloc(&Bt, n, n);
    m_alloc(&C, n, n);
    for (i=sum=0; i<ni; i++) {

        m_rand(At, -1.0L, 1.0L);
        m_trans(A, At);

        m_invert(B, A);
        m_mult(C, A, B);

        sum += fabs(m_det(C)-1.0);

    }
    m_free(&A);
    m_free(&At);
    m_free(&B);
    m_free(&Bt);
    m_free(&C);

    printf("M.A.D.{DET{A.INV(A))}-1} = %e\n", sum/ni);

#ifdef VAX_VMS
    report_stats(stdout, "stats: ");
#endif
}
Exemplo n.º 13
0
float	ScriptFunction::Evaluate( const float& x )
{
	switch (this->sftType)
	{
		case SFTPassedValue:
			return x;

		case SFTPI:
			return SFC_MAIN_CODE_PI;

		case SFTE:
			return SFC_MAIN_CODE_E;

		case SFTRandom:
			return (m_rand()/16384.f)-1;

	}
	return 0;
}
Exemplo n.º 14
0
 inline int_type operator()(Engine& e) const { return m_rand(e); }
Exemplo n.º 15
0
Blank::Blank()
{
	m_rand(time(0)+(int)this);
}
Exemplo n.º 16
0
Arquivo: Rand.hpp Projeto: Agilack/vle
 /**
  * @brief Gererate an unsigned int value [0..2^32-1].
  * @return a random unsigned int
  */
 inline result_type getInt()
 {
     return m_rand();
 }
Exemplo n.º 17
0
int init_resources(void) {
	try{
		player.moveLeft(9);
		player.moveForward(7);
		player.rotateX(-M_PI*3/4);
		player.rotateY(M_PI/12);
		player.addForce(gravity*-1);

		player.loadObj("crazy.o");
		cube.loadObj("cube.o");
		cube2.loadObj("cube.o");

		setupBuffers(player);
		setupBuffers(cube);
		setupBuffers(cube2);

		addObjectToShader(&cube);
		addObjectToShader(&cube2);
		bool c1 = cube.loadShaders(vertexShaderFileName, fragmentShaderFileName),
			 c2 = cube2.loadShaders(vertexShaderFileName, fragmentShaderFileName),
			 c3 = 1;

		for(int i=0; i< BALLS; i++){
			balls[i].loadObj("crazy.o");
			balls[i].setScale(Vector3(0.25f,0.25f,0.25f));
			setupBuffers(balls[i]);
			addObjectToShader(&(balls[i]));
			c3 *= balls[i].loadShaders(vertexShaderFileName, fragmentShaderFileName);

			balls[i].addVelocity(Vector3(m_rand()-0.5f, m_rand()-0.5f, m_rand()-0.5f).normalize().mult(60.0));
		}
		GLfloat scale_grid = ((GLfloat)DETAIL_GRID*2.0f)/((GLfloat)BOUNDARY);
		for(int i=0; i< DETAIL_GRID; i++){
			for(int j = 0;j < DETAIL_GRID; j++){
				grid[i].loadObj("cube.o");

				grid[i].setScale(Vector3(scale_grid, scale_grid, scale_grid));
				setupBuffers(grid[i]);
				addObjectToShader(&(grid[i]));
				c3 *= grid[i].loadShaders(vertexShaderFileName, fragmentShaderFileName);


				grid[i].setPosition(Vector3(i*scale_grid, j*scale_grid, k*scale_grid - DETAIL_GRID-2.0f));
				/*if(i%6 == 0)
					grid[i].setPosition(Vector3(DETAIL_GRID + 1.0f, (i-3)*scale_grid-DETAIL_GRID, (i-3)*scale_grid-DETAIL_GRID));
				else if(i%6 == 1)
					grid[i].setPosition(Vector3((i-2)*scale_grid-DETAIL_GRID, DETAIL_GRID + 1.0f, (i-2)*scale_grid-DETAIL_GRID));
				else if(i%6 == 2)
					grid[i].setPosition(Vector3((i-1)*scale_grid-DETAIL_GRID, (i-1)*scale_grid-DETAIL_GRID, DETAIL_GRID + 1.0f));
				else if(i%6 == 3)
					grid[i].setPosition(Vector3(-DETAIL_GRID - 1.0f , i*scale_grid-DETAIL_GRID, i*scale_grid-DETAIL_GRID));
				else if(i%6 == 4)
					grid[i].setPosition(Vector3((i+1)*scale_grid-DETAIL_GRID, -DETAIL_GRID - 1.0f, (i+1)*scale_grid-DETAIL_GRID));
				else if(i%6 == 5)
					grid[i].setPosition(Vector3((i+2)*scale_grid-DETAIL_GRID, (i+2)*scale_grid-DETAIL_GRID, -DETAIL_GRID - 1.0f));*/
			}
		}
		Vector3 pos = cube2.getPosition()+ Vector3(0.5f, 3.5f, 1.5f);
		cube2.setPosition(pos);
		//cube2.setRotation(Vector3(30*M_PI/180, 0, 40*M_PI/180));
		return c1 * c2 * c3;
	}catch(int i){
		return 0;
	}
}
Exemplo n.º 18
0
ManualBot::ManualBot()
{
	m_rand(time(0));
}