Exemplo n.º 1
0
void func1(int *seed, int *array, double *arrayX, double *arrayY,
			double *probability, double *objxy, int *index,
			int Ones, int iter, int X, int Y, int Z, int n)
{
	int i, j;
   	int index_X, index_Y;
	int max_size = X*Y*Z;

   	for(i = 0; i < n; i++){
   		arrayX[i] += 1 + 5*rand2(seed, i);
   		arrayY[i] += -2 + 2*rand2(seed, i);
   	}

   	for(i = 0; i<n; i++){
   		for(j = 0; j < Ones; j++){
   			index_X = round(arrayX[i]) + objxy[j*2 + 1];
   			index_Y = round(arrayY[i]) + objxy[j*2];
   			index[i*Ones + j] = fabs(index_X*Y*Z + index_Y*Z + iter);
   			if(index[i*Ones + j] >= max_size)
   				index[i*Ones + j] = 0;
   		}
   		probability[i] = 0;

   		for(j = 0; j < Ones; j++) {
   			probability[i] += (pow((array[index[i*Ones + j]] - 100),2) -
   							  pow((array[index[i*Ones + j]]-228),2))/50.0;
   		}
   		probability[i] = probability[i]/((double) Ones);
   	}
}
Exemplo n.º 2
0
//=================================================================================================
void CreateCharacterPanel::Random(CLASS _clas)
{
	mode = PickClass;
	if(_clas == INVALID_CLASS)
		clas = (CLASS)(rand2()%3);
	else
		clas = _clas;
	for(int i=2; i<5; ++i)
		bts[i].state = ((clas == (i-2)) ? Button::DISABLED : Button::NONE);
	Unit& u = *unit;
	u.data = FindUnitData(g_classes[WARRIOR].id);
	u.human_data->beard = rand2()%MAX_BEARD-1;
	u.human_data->hair = rand2()%MAX_HAIR-1;
	u.human_data->mustache = rand2()%MAX_MUSTACHE-1;
	int id = rand2()%n_hair_colors;
	u.human_data->hair_color = g_hair_colors[id];
	u.human_data->height = random(0.95f,1.05f);
	u.human_data->ApplyScale(game->aHumanBase);
	anim = anim2 = DA_STOI;
	u.ani->Play(NAMES::ani_stand, PLAY_PRIO2|PLAY_NO_BLEND, 0);
	slider[0].val = u.human_data->hair+1;
	slider[0].text = Format("%s %d/%d", txHair, slider[0].val, slider[0].maxv);
	slider[1].val = u.human_data->mustache+1;
	slider[1].text = Format("%s %d/%d", txMustache, slider[1].val, slider[1].maxv);
	slider[2].val = u.human_data->beard+1;
	slider[2].text = Format("%s %d/%d", txBeard, slider[2].val, slider[2].maxv);
	slider[3].val = id;
	slider[3].text = Format("%s %d/%d", txHairColor, slider[3].val, slider[3].maxv);
	slider[4].val = int((u.human_data->height-0.9f)*500);
	height = slider[4].val;
	slider[4].text = Format("%s %d/%d", txSize, slider[4].val, slider[4].maxv);
	InitInventory();
}
Exemplo n.º 3
0
Arquivo: funcj.c Projeto: Rekoz/CS33
void func1(int *seed, int *array, double *arrayX, double *arrayY,
			double *probability, double *objxy, int *index,
			int Ones, int iter, int X, int Y, int Z, int n)
{
	int i, j;
      	int index_X, index_Y;
	int max_size = X*Y*Z;
	double dO = (double)Ones;

#pragma omp parallel for private (j, index_X, index_Y)
	for(i = 0; i<n; i++){
	        arrayX[i] += 1 + 5*rand2(seed, i);
	        arrayY[i] += -2 + 2*rand2(seed, i);
   		probability[i] = 0;
		int roundX = round(arrayX[i]);
		int roundY = round(arrayY[i]);
		for(j = 0; j < Ones; j++){
   			index_X = roundX + objxy[j*2 + 1];
   			index_Y = roundY + objxy[j*2];
   			index[i*Ones + j] = fabs(index_X*Y*Z + index_Y*Z + iter);
   			if(index[i*Ones + j] >= max_size)
			  index[i*Ones + j] = 0;

   			probability[i] += (pow((array[index[i*Ones + j]] - 100),2) -
   							  pow((array[index[i*Ones + j]]-228),2))/50.0;
   		}
   		probability[i] = probability[i]/dO;
   	}
}
Exemplo n.º 4
0
double gauss(double mu, double sigma)
{
    double x, y, s, sq, z;
    // есть вычисленное раньше число?
    if(g_State)
    {
        // было, мы его вернем и его не станет
        g_State = false;
        // преобразуем и возвращаем
        return mu + g_Value * sigma;
    }

    // генерируем два равномерно распредел. числа из интервала [-1, 1],
    // попадающих в круг единичного радиуса
    do
    {
        x = rand2(-1, 1);
        y = rand2(-1, 1);
        s = x*x + y*y;
    } while(!(s > 0 && s <= 1));

    // преобразование
    sq = sqrt(-2*log(s)/s);
    // первое случайное число
    z = x * sq;
    // второе случайное число
    g_Value = y * sq;
    // теперь у нас есть вычисленное случайное число
    g_State = true;
    // преобразуем и вернем первое из чисел
    return mu + z * sigma;
}
Exemplo n.º 5
0
void SimplexSphereGenerator::spawnPopup()
{
	srand(time(NULL));
	uniform_int_distribution<int> rand2(0, spherePoints.size() - 1);
	static default_random_engine e_rand;
	int iterCount = 1000;

	while (iterCount-- > 0)
	{
		int ind = rand2(e_rand);
		D3DXVECTOR3 p = spherePoints[ind];
		p.y = 0;
		D3DXVec3Normalize(&p, &p);
		D3DXVECTOR4 t;
		D3DXVec3Transform(&t, &p, &matWorld);

		if (t.z > .5f && t.x < -0.2f)
		{
			popupsMutex.lock();
			for (int i = 0; i < POPUPS_COUNT; i++)
				if (!popups[i])
				{
					int x, y;
					while (true)
					{
						windowGenStart:
						x = (int)Window::GetWidth() / 6;
						x = rand() % (x * 2) - x;
						if (abs(x) < 40)
							x = 40 * sign(x);
						if (x < 0)
							x += Window::GetWidth() - 192;
						y = rand() % ((int)Window::GetHeight() - 80 - 128) + 40;
						for (int i = 0; i < POPUPS_COUNT; i++)
							if (popups[i])
								if (popups[i]->IsIn(x, y) || popups[i]->IsIn(x + 192, y) || popups[i]->IsIn(x, y + 128) || popups[i]->IsIn(x + 192, y + 128))
									goto windowGenStart;
						break;
					}
					auto p = new SpherePopup();
					try
					{
						p->SetVars(D3DXVECTOR2(x, y), parrtriangle[ind], ind);
					}
					catch (...)
					{
						delete p;
						popupsMutex.unlock();
						return;
					}
					p->Initialize();
					popups[i] = p;
					break;
				}
			popupsMutex.unlock();
			break;
		}
	}
}
Exemplo n.º 6
0
void prot_login_send_info( struct qqclient* qq )
{
    static uchar unknown5[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,
                               0x00,0x00,0x00
                              };
    static uchar unknown6[] = {0xE9,0xC4,0xD6,0x5C,0x4D,0x9D,
                               0xA0,0x17,0xE5,0x24,0x6B,0x55,0x57,0xD3,0xAB,0xF1
                              };
    static uchar unknown7[] = {0xCB,0x8D,0xA4,0xE2,0x61,0xC2,
                               0xDD,0x27,0x39,0xEC,0x8A,0xCA,0xA6,0x98,0xF8,0x9B
                              };

    qqpacket* p = packetmgr_new_send( qq, QQ_CMD_LOGIN_SEND_INFO );
    if( !p ) return;
    bytebuffer *buf = p->buf;
    //prepare sth.
    randkey( unknown6 );
    randkey( unknown7 );

    put_word( buf, 0x0001 );
    put_data( buf, qq->data.version_spec, sizeof(qq->data.version_spec) );
    put_int( buf, qq->data.login_info_unknown2 );
    put_int( buf, qq->server_time );
    put_int( buf, qq->client_ip );
    put_int( buf, 00000000 );
    put_word( buf, qq->data.login_info_large.len );
    put_data( buf, qq->data.login_info_large.data, qq->data.login_info_large.len );
    buf->pos += 35;
    put_data( buf, qq->data.exe_hash, sizeof(qq->data.exe_hash) );
    put_byte( buf, rand2() );	//unknown important byte
    put_byte( buf, qq->mode );
    put_data( buf, unknown5, sizeof(unknown5) );
    put_data( buf, qq->data.server_data, sizeof(qq->data.server_data) );
    put_data( buf, qq->data.locale, sizeof(qq->data.locale) );
    buf->pos += 16; //16 zeros
    put_word( buf, qq->data.token_c.len );
    put_data( buf, qq->data.token_c.data, qq->data.token_c.len );
    put_int( buf, 0x00000007 );
    put_int( buf, 0x00000000 );
    put_int( buf, 0x08041801 );
    put_byte( buf, 0x40 );	//length of the following
    put_byte( buf, 0x01 );
    put_int( buf, rand2()  );
//	put_int( buf, 0x0741E9748  );
    put_word( buf, sizeof(unknown6) );
    put_data( buf, unknown6, sizeof(unknown6) );
    put_data( buf, unknown5, sizeof(unknown5) );
    put_data( buf, qq->data.server_data, sizeof(qq->data.server_data) );
    put_byte( buf, 0x02 );
    put_int( buf, rand2()  );
//	put_int( buf, 0x8BED382E  );
    put_word( buf, sizeof(unknown7) );
    put_data( buf, unknown7, sizeof(unknown7) );
    buf->pos += 249;	//all zeros
    memcpy( p->key, qq->data.login_info_key1, sizeof(qq->data.login_info_key1) );
    post_packet( qq, p, RANDOM_KEY );
}
Exemplo n.º 7
0
static void test_peephole() {
    SkRandom rand;

    SkPictureRecorder recorder;

    for (int j = 0; j < 100; j++) {
        SkRandom rand2(rand); // remember the seed

        SkCanvas* canvas = recorder.beginRecording(100, 100);

        for (int i = 0; i < 1000; ++i) {
            rand_op(canvas, rand);
        }
        sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());

        rand = rand2;
    }

    {
        SkCanvas* canvas = recorder.beginRecording(100, 100);
        SkRect rect = SkRect::MakeWH(50, 50);

        for (int i = 0; i < 100; ++i) {
            canvas->save();
        }
        while (canvas->getSaveCount() > 1) {
            canvas->clipRect(rect);
            canvas->restore();
        }
        sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());
    }
}
Exemplo n.º 8
0
static void test_peephole(skiatest::Reporter* reporter) {
    SkRandom rand;

    for (int j = 0; j < 100; j++) {
        SkRandom rand2(rand.getSeed()); // remember the seed

        SkPicture picture;
        SkCanvas* canvas = picture.beginRecording(100, 100);

        for (int i = 0; i < 1000; ++i) {
            rand_op(canvas, rand);
        }
        picture.endRecording();
    }

    {
        SkPicture picture;
        SkCanvas* canvas = picture.beginRecording(100, 100);
        SkRect rect = SkRect::MakeWH(50, 50);

        for (int i = 0; i < 100; ++i) {
            canvas->save();
        }
        while (canvas->getSaveCount() > 1) {
            canvas->clipRect(rect);
            canvas->restore();
        }
        picture.endRecording();
    }
}
Exemplo n.º 9
0
Arquivo: graph.c Projeto: doofy/ae2015
void main(int argc,char **argv)
{ int i,j,n,dist,c;
  double density,r;
  long seed=0;
  short **con;
  short *labeled;
  
  if((argc != 3 && argc != 5) || (density=atof(argv[2])) >1 || density < 0 ||
     (n=atoi(argv[1])) <= 1){
    fprintf(stderr,"USAGE: %s <number of nodes> <density> [-R <rand seed>]\n"
	    "Density is a fraction in (0,1] giving the proability of any of\n"
	    "the n*(n-1)/2 possible edges being in the graph\n"
	    "OUTPUT table of numbers representing lower triangular matrix\n"
	    "of a distance matrix for a set of n nodes with costs in 1--1000\n"
	    "Disconnected nodes have a cost of n*1000\n",
	    argv[0]);
    exit(1);
  }
  if(argc == 5){
    seed = atol(argv[1]);
    seed_all(seed);
  }else
    seed = seed_time();		/* initialise random number generator */
  con = (short **)malloc(n * sizeof(short *));
  labeled = (short *)malloc(n * sizeof(short));
  do{	   	    /* keep generating until a connected graph exists */
    for(i=0;i<n;i++) labeled[i] = FALSE;
    labeled[n-1] = TRUE;
    for(i=n-1;i>0;i--){
      con[i] = (short *)malloc(i * sizeof(short));    
      for(j=0;j<i;j++){
	r = rand2();
	con[i][j] = (r < density); /* nodes i & j connected */
	if(labeled[i] && con[i][j]) labeled[j] = TRUE;
	if(labeled[j] && con[i][j]) labeled[i] = TRUE;
      }
    }
    do{		/* check if there are any other reachable unlabeled nodes */
      c = FALSE;
      for(i=0;i<n;i++)
	for(j=0;j<i;j++)
	  if(con[i][j]){
	    if(!labeled[i] && labeled[j]) c = labeled[i] = TRUE;
	    if(labeled[i] && !labeled[j]) c = labeled[j] = TRUE;
	  }
    }while(c);
    c=TRUE;			/* connected */
    for(i=0;i<n;i++) c = (c && labeled[i]);
  }while(!c);			/* try again if graph is not connected */
 
  for(i=0;i<n;i++){
    for(j=0;j<i;j++)
      printf("%d%c",((con[i][j]) ? irand2(999)+1 : (n*1000)),
	     ( ((j+1)%10) ? ' ' : '\n'));
    printf("\n");
  }
}
Exemplo n.º 10
0
//********************************************************************
CPacketList::CPacketList(uint mutex_timeout, uint flags) :
      rx_pkt_list_top(0),
      rx_pkt_list_tail(0),
      eth_rx_queueing_enabled(false),
      hListAccessMutex(0),
      mutex_timeout_secs(mutex_timeout),
      // first_construct(false),
      rx_event_active(false),
      hdlRxEvent(0),
      reporting_func(NULL),
      rpt_private_data(NULL)
{
   // ZeroMemory((char *) this, sizeof(CPacketList)) ;
   mutex_timeout_secs = mutex_timeout ;

   // wsprintfA(bfr, "EVENT%u", (uint) time(NULL)) ;
   if (!first_construct) {
      first_construct = true ;
      srand2(time(NULL)) ;
      // syslog("CPacketList: init rand2\n") ;
   }

   // rpt_private_data = NULL ;
   // reporting_func = NULL ;
   //  make this default to TRUE
   eth_rx_queueing_enabled = (flags & EPL_QUEUEING_DISABLED) ? false : true ;
   if (flags & EPL_USE_RX_EVENT) {
      rx_event_active = true ;
      char bfr[40] ;
      // wsprintfA(bfr, "EVENT%u", (uint) time(NULL)) ;
      wsprintfA(bfr, "EVENT%u", (uint) rand2()) ;
      // syslog("CPacketList starting [%X] [%s]\n", flags, bfr) ;
      hdlRxEvent = CreateEventA(NULL, false, false, bfr) ;
      if (hdlRxEvent == NULL)
         syslog("CreateEvent: %s\n", get_system_message()) ;
      // else
      //    syslog("hdlRxEvent handle created\n") ;
      
   } 
   hListAccessMutex = CreateMutex(NULL, false, NULL) ;
   if (hListAccessMutex == NULL) {
      report_func("CreateMutex [CPacketList]: %s\n", get_system_message()) ;
   } else {
      //  note: this is not actually an error!
      if (GetLastError() == ERROR_ALREADY_EXISTS) {
         report_func("CreateMutex [CPacketList]:  mutex already exists!!\n") ;
      }
   }
}
Exemplo n.º 11
0
	HeapNode *merge(HeapNode *p, HeapNode *q){
		if ( p == NULL || q == NULL )
			return p == NULL ? q : p;
		if ( p->key > q->key ) 
			swap(p, q);
		HeapNode *np = alloc();
		np->key = p->key, np->ed = p->ed;
	   	np->ch[0] = p->ch[0], np->ch[1] = p->ch[1];
		int t = rand2();
		np->ch[t] = merge(np->ch[t], q);
		if ( np->ch[0] )
			dia::addEdge(np->id, np->ch[0]->id, np->ch[0]->key - np->key);
		if ( np->ch[1] )
			dia::addEdge(np->id, np->ch[1]->id, np->ch[1]->key - np->key);
		return np;
	}
//################################################################################################################################
 // Get the 68% confindence interval of mu1/mu2
void getPoissonIntervalls(double mu1, double mu2){

  double result = mu1/mu2;
  TH1D *expHist = new TH1D("mu1/mu2","mu1/mu2",1000,0,1);
  TRandom3 rand1(0);
  TRandom3 rand2(0);

  cout<<"mu1 = "<<mu1<<endl;
  cout<<"mu2 = "<<mu2<<endl;
  cout<<"ratio = "<<result<<endl;

  for(int i=0; i<10000000; i++){

    expHist->Fill(1.*rand1.Poisson(mu1)/rand2.Poisson(mu2));
  }

  // Get now the 68% upper and lower interval
  double errUp  = 0;
  double errLow = 0;
  for(int i=1; i<=expHist->GetNbinsX();i++){

    double upperIntegral = expHist->Integral(i,expHist->GetNbinsX());
    double lowerIntegral = expHist->Integral(1,i);

    if(abs(upperIntegral/expHist->Integral()-0.32)<0.02){
      cout<<"upper bound = "<<expHist->GetBinCenter(i)<<endl;
      errUp = expHist->GetBinCenter(i)-result;
    }
    if(abs(lowerIntegral/expHist->Integral()-0.32)<0.02){
      cout<<"lower bound = "<<expHist->GetBinCenter(i)<<endl;
      errLow = result - expHist->GetBinCenter(i);
    }
  }


  cout<<"error Up = "<<errUp<<endl;
  cout<<"error Low = "<<errLow<<endl;

  TCanvas *c = new TCanvas("cExp","cExp",0,0,500,500);
  c->cd();
  expHist->Draw();
}    
Exemplo n.º 13
0
int main( int argc, char* argv[])
{

    if( argc != 3)
    {
        std::cerr << "Usage: "<<argv[0]<<" [input.nc] [output.nc]\n";
        return -1;
    }
    std::cout << argv[1]<< " -> "<<argv[2]<<std::endl;   
    //----------------
    const unsigned Nhist = 50; 
    const unsigned nhist = 1;
    const unsigned Ninput =100;
    const double Nsigma =4.;
    std::vector<double> input1(Ninput,0.);    
    std::vector<double> input2(Ninput,0.);    

    thrust::random::minstd_rand generator;
    thrust::random::normal_distribution<double> d1;
    thrust::random::normal_distribution<double> d2;
    std::vector<double> rand1(Ninput,0.);    
    std::vector<double> rand2(Ninput,0.);    
    for (unsigned i=0;i<rand1.size();i++)  {  rand1[i] = d1(generator); }
    for (unsigned i=0;i<rand2.size();i++)  {  rand2[i] = d2(generator); }

    for (unsigned i=0;i<input1.size();i++)  {
        double t = (double)(i/(input1.size()-1));
        double omega1 =2.*M_PI* 20.;
        input1[i] = (rand1[i]*0.1*cos( omega1*t)+1.); 
    }
    for (unsigned i=0;i<input2.size();i++)  {
        double t = (double)(i/(input2.size()-1));
        //double omega1 = 2.*M_PI*20.;
        double omega2= 2.*M_PI*30.;
        //double phase = 0.5*M_PI;
//         input2[i] =input1[i];  //perfectly correlated
//         input2[i] = (-rand1[i]*0.1*cos(omega1*t)+1.);//perfectly anticorrelated
//         input2[i] = (rand2[i]*0.001*cos(omega2*t)+3.);//perfectly uncorrelated
        input2[i] = (rand2[i]*0.001*cos(omega2*t)+3.);//uncorrelated
    } 

    //normalize grid and compute sigma
    NormalizeToFluc(input1);
    NormalizeToFluc(input2);
    dg::Grid1d  g1d1(-Nsigma,Nsigma, nhist, Nhist,dg::DIR);
    dg::Grid1d  g1d2(-Nsigma,Nsigma, nhist, Nhist,dg::DIR); 
    dg::Grid2d  g2d( -Nsigma,Nsigma,-Nsigma,Nsigma, nhist, Nhist,Nhist,dg::DIR,dg::DIR); 
    dg::Histogram<dg::HVec> hist1(g1d1,input1);  
    dg::Histogram<dg::HVec> hist2(g1d2,input2);    
    dg::Histogram2D<dg::HVec> hist12(g2d,input1,input2);    

 
    dg::HVec PA1 = dg::evaluate(hist1,g1d1);
    dg::HVec A1 = dg::evaluate(dg::cooX1d,g1d1);
    dg::HVec PA2= dg::evaluate(hist2,g1d2);
    dg::HVec A2 = dg::evaluate(dg::cooX1d,g1d2);
    dg::HVec PA1A2= dg::evaluate(hist12,g2d);
    
    //-----------------NC output start
    int dataIDs1[2],dataIDs2[2],dataIDs12[1];
    int dim_ids1[1],dim_ids2[1],dim_ids12[2];
    int ncid;
    file::NC_Error_Handle err; 
    err = nc_create(argv[2],NC_NETCDF4|NC_CLOBBER, &ncid); 
    //plot 1
    err = file::define_dimension( ncid,"A1_", &dim_ids1[0],  g1d1);
    err = nc_def_var( ncid, "P(A1)",   NC_DOUBLE, 1, &dim_ids1[0], &dataIDs1[0]);
    err = nc_def_var( ncid, "A1",    NC_DOUBLE, 1, &dim_ids1[0], &dataIDs1[1]);
    err = nc_enddef( ncid);
    err = nc_put_var_double( ncid, dataIDs1[0], PA1.data() );
    err = nc_put_var_double( ncid, dataIDs1[1], A1.data() );
    err = nc_redef(ncid);
    //plot 2
    err = file::define_dimension( ncid,"A2_", &dim_ids2[0],  g1d2);
    err = nc_def_var( ncid, "P(A2)",   NC_DOUBLE, 1, &dim_ids2[0], &dataIDs2[0]);
    err = nc_def_var( ncid, "A2",    NC_DOUBLE, 1, &dim_ids2[0], &dataIDs2[1]);
    err = nc_enddef( ncid);
    err = nc_put_var_double( ncid, dataIDs2[0], PA2.data() );
    err = nc_put_var_double( ncid, dataIDs2[1], A2.data() );
    err = nc_redef(ncid);
    //plot12
//     dim_ids12[0]=dim_ids1[0];
//     dim_ids12[1]=dim_ids2[0];
    dim_ids12[0]=dataIDs1[0];
    dim_ids12[1]=dataIDs2[0];
    err = file::define_dimensions( ncid, &dim_ids12[0],  g2d);
    err = nc_def_var( ncid, "P(A1,A2)",   NC_DOUBLE, 2, &dim_ids12[0], &dataIDs12[0]);
    err = nc_enddef( ncid);
    err = nc_put_var_double( ncid, dataIDs12[0], PA1A2.data() );
    err = nc_redef(ncid);
    nc_close( ncid);

    return 0;
}
Exemplo n.º 14
0
GF2m random2(void)
{
    GF2m z;
    rand2(z.fn);
    return z;
}
Exemplo n.º 15
0
//=================================================================================================
void CreateCharacterPanel::UpdateUnit(float dt)
{
	// aktualizacja postaci	
	t -= dt;
	if(t <= 0.f)
	{
		switch(anim)
		{
		case DA_ATAK:
		case DA_SCHOWAJ_BRON:
		case DA_SCHOWAJ_LUK:
		case DA_STRZAL:
		case DA_WYJMIJ_BRON:
		case DA_WYJMIJ_LUK:
		case DA_ROZGLADA:
			assert(0);
			break;
		case DA_BLOK:
			if(rand2()%2 == 0)
				anim = DA_ATAK;
			else
				anim = DA_BOJOWY;
			break;
		case DA_BOJOWY:
			if(unit->wyjeta == B_JEDNORECZNA)
			{
				int co = rand2()%(unit->HaveShield() ? 3 : 2);
				if(co == 0)
					anim = DA_ATAK;
				else if(co == 1)
					anim = DA_SCHOWAJ_BRON;
				else
					anim = DA_BLOK;
			}
			else
			{
				if(rand2()%2 == 0)
					anim = DA_STRZAL;
				else
					anim = DA_SCHOWAJ_LUK;
			}
			break;
		case DA_STOI:
		case DA_IDZIE:
			{
				int co = rand2()%(unit->HaveBow() ? 5 : 4);
				if(co == 0)
					anim = DA_ROZGLADA;
				else if(co == 1)
					anim = DA_STOI;
				else if(co == 2)
					anim = DA_IDZIE;
				else if(co == 3)
					anim = DA_WYJMIJ_BRON;
				else
					anim = DA_WYJMIJ_LUK;
			}
			break;
		default:
			assert(0);
			break;
		}
	}

	if(anim != anim2)
	{
		anim2 = anim;
		switch(anim)
		{
		case DA_ATAK:
			unit->attack_id = unit->GetRandomAttack();
			unit->ani->Play(NAMES::ani_attacks[unit->attack_id], PLAY_PRIO2|PLAY_ONCE, 0);
			unit->ani->groups[0].speed = unit->GetAttackSpeed();
			unit->etap_animacji = 0;
			t = 100.f;
			unit->ani->frame_end_info = false;
			break;
		case DA_BLOK:
			unit->ani->Play(NAMES::ani_block, PLAY_PRIO2, 0);
			t = 1.f;
			break;
		case DA_BOJOWY:
			unit->ani->Play(NAMES::ani_battle, PLAY_PRIO2, 0);
			t = 1.f;
			break;
		case DA_IDZIE:
			unit->ani->Play(NAMES::ani_move, PLAY_PRIO2, 0);
			t = 2.f;
			break;
		case DA_ROZGLADA:
			unit->ani->Play("rozglada", PLAY_PRIO2|PLAY_ONCE, 0);
			t = 100.f;
			unit->ani->frame_end_info = false;
			break;
		case DA_SCHOWAJ_BRON:
			unit->ani->Play(unit->GetTakeWeaponAnimation(true), PLAY_PRIO2|PLAY_ONCE|PLAY_BACK, 0);
			unit->ani->groups[1].speed = 1.f;
			t = 100.f;
			unit->etap_animacji = 0;
			unit->stan_broni = BRON_CHOWA;
			unit->wyjeta = B_BRAK;
			unit->chowana = B_JEDNORECZNA;
			unit->ani->frame_end_info = false;
			break;
		case DA_SCHOWAJ_LUK:
			unit->ani->Play(NAMES::ani_take_bow, PLAY_PRIO2|PLAY_ONCE|PLAY_BACK, 0);
			unit->ani->groups[1].speed = 1.f;
			t = 100.f;
			unit->etap_animacji = 0;
			unit->stan_broni = BRON_CHOWA;
			unit->wyjeta = B_BRAK;
			unit->chowana = B_LUK;
			unit->ani->frame_end_info = false;
			break;
		case DA_STOI:
			unit->ani->Play(NAMES::ani_stand, PLAY_PRIO2, 0);
			t = 2.f;
			break;
		case DA_STRZAL:
			unit->ani->Play(NAMES::ani_shoot, PLAY_PRIO2|PLAY_ONCE, 0);
			unit->ani->groups[0].speed = unit->GetBowAttackSpeed();
			unit->etap_animacji = 0;
			t = 100.f;
			if(game->bow_instances.empty())
				unit->bow_instance = new AnimeshInstance(unit->GetBow().ani);
			else
			{
				unit->bow_instance = game->bow_instances.back();
				game->bow_instances.pop_back();
				unit->bow_instance->ani = unit->GetBow().ani;
			}
			unit->bow_instance->Play(&unit->bow_instance->ani->anims[0], PLAY_ONCE|PLAY_PRIO1|PLAY_NO_BLEND, 0);
			unit->bow_instance->groups[0].speed = unit->ani->groups[0].speed;
			unit->ani->frame_end_info = false;
			break;
		case DA_WYJMIJ_BRON:
			unit->ani->Play(unit->GetTakeWeaponAnimation(true), PLAY_PRIO2|PLAY_ONCE, 0);
			unit->ani->groups[1].speed = 1.f;
			t = 100.f;
			unit->etap_animacji = 0;
			unit->stan_broni = BRON_WYJMUJE;
			unit->wyjeta = B_JEDNORECZNA;
			unit->chowana = B_BRAK;
			unit->ani->frame_end_info = false;
			break;
		case DA_WYJMIJ_LUK:
			unit->ani->Play(NAMES::ani_take_bow, PLAY_PRIO2|PLAY_ONCE, 0);
			unit->ani->groups[1].speed = 1.f;
			t = 100.f;
			unit->etap_animacji = 0;
			unit->stan_broni = BRON_WYJMUJE;
			unit->wyjeta = B_LUK;
			unit->chowana = B_BRAK;
			unit->ani->frame_end_info = false;
			break;
		default:
			assert(0);
			break;
		}
	}

	switch(anim)
	{
	case DA_ATAK:
		if(unit->ani->frame_end_info)
		{
			unit->ani->groups[0].speed = 1.f;
			if(rand2()%2==0)
			{
				anim = DA_ATAK;
				anim2 = DA_STOI;
			}
			else
				anim = DA_BOJOWY;
		}
		break;
	case DA_SCHOWAJ_BRON:
	case DA_SCHOWAJ_LUK:
		if(unit->etap_animacji == 0 && (unit->ani->GetProgress() <= unit->data->frames->t[F_TAKE_WEAPON] || unit->ani->frame_end_info))
			unit->etap_animacji = 1;
		if(unit->ani->frame_end_info)
		{
			unit->stan_broni = BRON_SCHOWANA;
			unit->chowana = B_BRAK;
			anim = DA_STOI;
			t = 1.f;
		}
		break;
	case DA_STRZAL:
		if(unit->ani->GetProgress() > 20.f/40 && unit->etap_animacji < 2)
			unit->etap_animacji = 2;
		else if(unit->ani->GetProgress() > 35.f/40)
		{
			unit->etap_animacji = 3;
			if(unit->ani->frame_end_info)
			{
				assert(unit->bow_instance);
				game->bow_instances.push_back(unit->bow_instance);
				unit->bow_instance = NULL;
				unit->ani->groups[0].speed = 1.f;
				if(rand2()%2 == 0)
				{
					anim = DA_STRZAL;
					anim2 = DA_STOI;
				}
				else
					anim = DA_BOJOWY;
				break;
			}
		}
		unit->bow_instance->groups[0].time = min(unit->ani->groups[0].time, unit->bow_instance->groups[0].anim->length);
		unit->bow_instance->need_update = true;
		break;
	case DA_WYJMIJ_BRON:
		if(unit->etap_animacji == 0 && (unit->ani->GetProgress() >= unit->data->frames->t[F_TAKE_WEAPON] || unit->ani->frame_end_info))
			unit->etap_animacji = 1;
		if(unit->ani->frame_end_info)
		{
			unit->stan_broni = BRON_WYJETA;
			anim = DA_ATAK;
		}
		break;
	case DA_WYJMIJ_LUK:
		if(unit->etap_animacji == 0 && (unit->ani->GetProgress() >= unit->data->frames->t[F_TAKE_WEAPON] || unit->ani->frame_end_info))
			unit->etap_animacji = 1;
		if(unit->ani->frame_end_info)
		{
			unit->stan_broni = BRON_WYJETA;
			anim = DA_STRZAL;
		}
		break;
	case DA_ROZGLADA:
		if(unit->ani->frame_end_info)
			anim = DA_STOI;
		break;
	case DA_BLOK:
	case DA_BOJOWY:
	case DA_STOI:
	case DA_IDZIE:
		break;
	default:
		assert(0);
		break;
	}

	unit->ani->Update(dt);
}
Exemplo n.º 16
0
void prot_login_verify( struct qqclient* qq )
{
    qqpacket* p = packetmgr_new_send( qq, QQ_CMD_LOGIN_VERIFY );
    if( !p ) return;
    bytebuffer *buf = p->buf;
    bytebuffer *verify_data;
    NEW( verify_data, sizeof(bytebuffer) );
    if( !verify_data ) {
        packetmgr_del_packet( &qq->packetmgr, p );
        return;
    }
    verify_data->size = PACKET_SIZE;
    put_int( verify_data, rand2() );	//random??
    put_word( verify_data, 0x0001 );
    put_int( verify_data, qq->number );
    put_data( verify_data, qq->data.version_spec, sizeof(qq->data.version_spec) );
    put_byte( verify_data, 00 );
    put_word( verify_data, 00 );	//0x0001 什么来的?
    put_data( verify_data, qq->md5_pass1, 16 );
    put_int( verify_data, qq->server_time );
    verify_data->pos += 13;
    put_int( verify_data, qq->server_ip );
    put_int( verify_data, 0 );
    put_int( verify_data, 0 );
    put_word( verify_data, 0x0010 );
    put_data( verify_data, qq->data.verify_key1, 0x10 );
    put_data( verify_data, qq->data.verify_key2, 0x10 );
    //
    put_word( buf, 0x00CA );	//sub cmd??
    put_word( buf, 0x0001 );
    put_data( buf, qq->data.locale, sizeof(qq->data.locale) );
    put_data( buf, qq->data.version_spec, sizeof(qq->data.version_spec) );
    put_word( buf, qq->data.token_c.len );
    put_data( buf, qq->data.token_c.data, qq->data.token_c.len );
    if( verify_data->pos != 104 ) {
        DBG("wrong pos!!!");
    }

    int out_len = 120;
    uchar encrypted[120+10];
    qqencrypt( verify_data->data, verify_data->pos, qq->md5_pass2, encrypted, &out_len );
    put_word( buf, out_len );
    put_data( buf, encrypted, out_len );

    put_word( buf, 0x0000 );
    put_word( buf, 0x018B );
    put_byte( buf, 0x2E );	//length of the following info
    static uchar unknown6[] = {0xE9,0xC4,0xD6,0x5C,0x4D,0x9D,
                               0xA0,0x17,0xE5,0x24,0x6B,0x55,0x57,0xD3,0xAB,0xF1
                              };
    static uchar unknown7[] = {0xCB,0x8D,0xA4,0xE2,0x61,0xC2,
                               0xDD,0x27,0x39,0xEC,0x8A,0xCA,0xA6,0x98,0xF8,0x9B
                              };
    randkey( unknown6 );
    randkey( unknown7 );
    put_byte( buf, 0x01 );
    put_int( buf, rand2()  );
//	put_int( buf, 0x0741E9748  );
    put_word( buf, sizeof(unknown6) );
    put_data( buf, unknown6, sizeof(unknown6) );
    put_byte( buf, 0x02 );
    put_int( buf, rand2()  );
//	put_int( buf, 0x8BED382E  );
    put_word( buf, sizeof(unknown7) );
    put_data( buf, unknown7, sizeof(unknown7) );
    buf->pos += 0x015C;	//395 zeros?  348

    DEL( verify_data );
    post_packet( qq, p, RANDOM_KEY );
}
Exemplo n.º 17
0
void Game::Render(float dt)
{
    graphics->ClearColor(sf::Color::Black);

    // Particles
    window->draw(system);

    graphics->Rectangle(0,15, 320, 75, sf::Color(0, 0, 0, 200));

    // Display score
    graphics->Print(50, 0, "SCORE: " + std::to_string(score));
    graphics->Print(150, 0, "BEST: " + std::to_string(high));

    // Lanes
    for (sf::Vector2f &lane : lanes)
        graphics->Rectangle(lane.x, lane.y, 320, 2);

    // Enemies
    for (Enemie &e : enemies)
        graphics->Rectangle(e.x, lanes[e.y].y-5, 10, 10, sf::Color::Red);

    // Player
    graphics->Rectangle(player.x, lanes[player.y].y-5, 10, 10, sf::Color::Green);

    // Score messages
    if (score % 20 == 0 && score > 0) {
        saying_timer = 3;
        current_saying = rand()%sayings.size();
    }
    if (saying_timer > 0) {
        saying_timer -= dt;

        graphics->Print(50+rand2(3), 100+rand2(3), sayings[current_saying], 24, sf::Color(rand()%255, rand()%255, rand()%255));
        graphics->Print(50+rand2(3), 100+rand2(3), sayings[current_saying], 24, sf::Color(rand()%255, rand()%255, rand()%255));
    }

    if (newhighscore)
    {
        graphics->Print(50+rand2(3), -20+rand2(3), "HIGHSCORE", 24, sf::Color(rand()%255, rand()%255, rand()%255));
        graphics->Print(50+rand2(3), -20+rand2(3), "HIGHSCORE", 24, sf::Color(rand()%255, rand()%255, rand()%255));
    }

    // Dead
    if (dead) {
        graphics->Rectangle(-50, -240, 370, 240*2, sf::Color(0, 0, 0, 200));
        graphics->Print(20, -20, "DEAD", 100);
        graphics->Print(50, -50, "R to restart", 30);
        graphics->Print(50, -20, "ESCAPE for menu");

        graphics->Print(50+rand2(3), 100+rand2(3), dead_sayings[current_saying_dead], 24, sf::Color(rand()%255, rand()%255, rand()%255));
        graphics->Print(50+rand2(3), 100+rand2(3), dead_sayings[current_saying_dead], 24, sf::Color(rand()%255, rand()%255, rand()%255));
    } else if (menu) {
        graphics->Rectangle(-50, -240, 370, 240*2, sf::Color(0, 0, 0, 200));
        graphics->Print(20, -20, "SLIDE", 100);
        graphics->Print(50, -50, "R to start", 30);

        graphics->Print(50+rand2(3), 100+rand2(3), menu_sayings[current_saying_menu], 24, sf::Color(rand()%255, rand()%255, rand()%255));
        graphics->Print(50+rand2(3), 100+rand2(3), menu_sayings[current_saying_menu], 24, sf::Color(rand()%255, rand()%255, rand()%255));
    }

}
Exemplo n.º 18
0
static void randkey(uchar* key)
{
    int i;
    for( i=0; i<16; i++ )
        key[i] = rand2();
}
Exemplo n.º 19
0
TEST(ParticleCUDA, Random) {
	rand2_seed(1080);
	ASSERT_DOUBLE_EQ(rand2(), 0.6554163483485531);
	ASSERT_DOUBLE_EQ(rand2(), 0.2009951854518572);
	ASSERT_DOUBLE_EQ(rand2(), 0.8936223876466522);
	ASSERT_DOUBLE_EQ(rand2(), 0.2818865431288053);
	ASSERT_DOUBLE_EQ(rand2(), 0.5250003829714993);
	ASSERT_DOUBLE_EQ(rand2(), 0.3141267749950177);
	ASSERT_DOUBLE_EQ(rand2(), 0.4446156782993733);
	ASSERT_DOUBLE_EQ(rand2(), 0.2994744556282315);
	ASSERT_DOUBLE_EQ(rand2(), 0.4712494933308135);
	ASSERT_DOUBLE_EQ(rand2(), 0.5913675200502571);

	rand2_seed(1080);
	ASSERT_DOUBLE_EQ(rand2(), 0.6554163483485531);
	ASSERT_DOUBLE_EQ(rand2(), 0.2009951854518572);
	ASSERT_DOUBLE_EQ(rand2(), 0.8936223876466522);
	ASSERT_DOUBLE_EQ(rand2(), 0.2818865431288053);
	ASSERT_DOUBLE_EQ(rand2(), 0.5250003829714993);
	ASSERT_DOUBLE_EQ(rand2(), 0.3141267749950177);
	ASSERT_DOUBLE_EQ(rand2(), 0.4446156782993733);
	ASSERT_DOUBLE_EQ(rand2(), 0.2994744556282315);
	ASSERT_DOUBLE_EQ(rand2(), 0.4712494933308135);
	ASSERT_DOUBLE_EQ(rand2(), 0.5913675200502571);
}
Exemplo n.º 20
0
//*************************************************************
//  Notes stolen from the Linux man page for rand():
//  
// In Numerical Recipes in C: The Art of Scientific Computing 
//  (William H. Press, Brian P. Flannery, Saul A. Teukolsky, 
//   William T. Vetterling; New York: Cambridge University Press,
//   1990 (1st ed, p. 207)), the following comments are made: 
// 
// "If you want to generate a random integer between 1 and 10, 
//  you should always do it by 
// 
//    j=1+(int) (10.0*rand()/(RAND_MAX+1.0)); 
// 
// and never by anything resembling 
// 
//    j=1+((int) (1000000.0*rand()) % 10); 
// 
// (which uses lower-order bits)." 
//*************************************************************
//  return a random number between 0-(Q-1)
//*************************************************************
unsigned random(unsigned Q)
{
   unsigned j = (unsigned) ((Q * rand2()) / (RAND_MAX+1)); 
   return j;
}         
Exemplo n.º 21
0
void main(void)
{
//	void* foo = 0, bar = 0, echo = 0, num = 0;
	unsigned char foo = 0, bar = 0, echo = 0, num = 0, error = 0;		//counter
	/*reset contents of string*/
	foo = 0;
	while(foo<30)
    {
        string[foo] = ' ';
        ++foo;
    }//end while


	//LCD init
	LCDInit();
	/*switch init*/
	/*RB0*/
	INTCON2bits.RBPU = 0; // enable PORTB internal pullups
	TRISBbits.TRISB0 = 1; // PORTB bit 0 (connected to switch) is input (1)

	/*RA5*/
	WDTCONbits.ADSHR = 1;
	ANCON0 = 0x1f;
	TRISAbits.TRISA5 = 1;

	/*prompt for start*/
	lcd_write(2,3);

    //hold the start info until the SWITCH being pressed
	while( SWITCH_0 == 1 && SWITCH_1 == 1)
		;
	release();

	//gen 30 numbers of 1 or 0 then store into var[]
	foo = 0;
	while(foo < 30)
	{
		num = rand2()%2;
		if(num==1)
			var[foo] = '1';
		else
			var[foo] = '0';
		++foo;
	}//end while


	//loop game 3 to 30
	bar = 3;
	/*-----------------------------------------------------------------------------------------------------------------------
	 *while loop switch check, for the current bar*/
	while( bar <= 3)				//total game process
	{



		start:
		
		/*display current string interval*/
		foo = 0;
		while(foo<bar)
		{
		
			string[0] = var[foo]; 

			/*display num for 0.8s*/
			lcd_write(0,1);
			Delay10KTCYx(80);
			
			/*display interval for 0.2s*/
			lcd_write(1,1);
			Delay10KTCYx(20);
				
			
			++foo;
		}//end while
		/*-----------------------------------------------------------------------------------------------------------------------
		 *switch check, for the current char(echo)*/
		
		echo = 0;
		while(echo < bar)
		{

			/*switch input*/
			while(1)
			{
		

				/*switch input CORRECT---------------------------------------------------------*/
				if((SWITCH_0 == 0&& var[echo]=='0')||(SWITCH_1 == 0&&var[echo]=='1'))
				{
					release();
					break;
				}//end if

				/*switch input WRONG-----------------------------------------------------------*/
				else if((SWITCH_0 == 0&& var[echo]=='1')||(SWITCH_1 == 0&&var[echo]=='0')||(SWITCH_0 == 0&&SWITCH_1 == 0))	
				{
					release();
					/*increment error count*/
					error++;

					/*display wrong msg*/
					lcd_write(4,5);
					
					/*end the game when second error occur*/
					if(error >= 2)
						goto error;

					/*pending switch input------------------------------------------------*/
					Delay10KTCYx(50);
					while(1)
					{
						/*play again with same bar length---------------------*/
						if(SWITCH_0 == 0)		//play again with same length
						{
							release();
							goto start;
						}//end if

						/*end of the game, starting new round-----------------*/
						else if(SWITCH_1 == 0)	//end of game, new round
						{
							release();
							error:
							/*length-------------------------------------*/
							/*determine length & renew string*/
							if(bar/10==0)
							{
								string[175] = bar%10+'0';	
							}//end if
							else
							{
								string[174] = bar/10+'0';
								string[175] = bar%10+'0';
							}//end else

							/*display & delay*/
							lcd_write(10,10);
							Delay10KTCYx(200);

							/*display exit answer info------------------*/
							lcd_write(8,9);	
							Delay10KTCYx(200);
							
							/*renew correct sequence*/
							num = 0;
							while(num<30)
							{
								string[num] = var[num];
								++num;
							}//end while

							/*display correct sequence--------------------*/
							lcd_write(0,1);
							Delay10KTCYx(200);

							goto end;
						}//end else if
					}//end while

					break;
				}//end else if
				else if(SWITCH_0 == 1 && SWITCH_1 == 1)			//unpressed
					continue;

			}//end while


			/*check right -> continue move on to the next char*/
			++echo;

		}//end while

		/*increment the length of bar and continue-----------------------------------------------*/
		++bar;
		/*reset error count*/
		error = 0;

	}//end while


	//end display
	lcd_write(6,7);
	Delay10KTCYx(100);

	/*renew correct sequence*/
	num = 0;
	while(num<30)
	{
		string[num] = var[num];
		++num;
	}//end while

	/*pending for switch input and flicking LED, display correct sequence*/
	TRISD = 0;
	while(SWITCH_0 == 1 && SWITCH_1 == 1)
	{
		lcd_write(0,1);
		LATD = 0xff;
		Delay10KTCYx(3);
		LATD = 0;
		Delay10KTCYx(3);
	}//end while
	release();
	LATD = 0;
	end:
	main();

}//end main