Exemplo n.º 1
0
void init_game() //게임판 초기화
{
	int i, j;
	int x, y;

	nx = ny = 0, count = 0;

	memset(arr_cell, 0, sizeof(arr_cell)); // 배열 초기화

	for (i = 1; i <= 8; i++)
	{
		for (j = 0; j < 2; j++)
		{
			do
			{
				x = make_rand(4), y = make_rand(4); // 두개의 같은 숫자를 난수로 저장
			} while (arr_cell[x][y].Num != 0);
			arr_cell[x][y].Num = i;
		}
	}

	draw_scr(TRUE);
	Sleep(2000);
	system("cls");
	draw_scr(FALSE);
}
Exemplo n.º 2
0
int GetTHData(double *temp, double *humi)
{
	*temp = make_rand(22, 30);
	*humi = make_rand(60, 70);

	log_debug("Temp:%f, Humi:%f\n", *temp, *humi);
	
	return 0;
}
Exemplo n.º 3
0
void main(void)
{
	int nFrame, nStay;
	int x, y;

	SetCursorType(NOCURSOR), init_rand();

	for (; 1;) // 게임이 끝났을 경우 다시 시작하거나 끝내는 루프
	{
		Score = 0, bricknum = 0;
		CLS; // 무한루프에 들어가기전 초기화

		for (x = 0; x < BW + 2; x++) // 외부벽 초기화
		{
			for (y = 0; y < BH + 2; y++)
			{
				board[x][y] = (y == 0 || y == BH + 1 || x == 0 || x == BW + 1) ? WALL : EMPTY;
			}
		}
		DrawScreen();
		nFrame = 10;
		nbrick = make_rand(sizeof(Shape) / sizeof(Shape[0]));

		for (; 2;) // 전체 게임 루프
		{
			bricknum++;
			brick = nbrick;
			nbrick = make_rand(sizeof(Shape) / sizeof(Shape[0])); // 새 벽돌 생성
			DrawNext();
			//DrawPresent()
			nx = BW / 2, ny = 2;
			rot = 0;
			PrintBrick(TRUE);

			if (GetAround(nx, ny, brick, rot) != EMPTY) break; // 게임 끝 점검
			nStay = nFrame;
			for (; 3;) // 벽돌 하나 처리 루프
			{
				if (--nStay == 0)
				{
					nStay = nFrame;
					if (MoveDown()) break; // 벽돌 내림
				}
				if (ProcessKey()) break; // 키처리
				delay(1000 / 20); // 시간 지연
			}
			if (bricknum % 5 == 0 && nFrame > 3)
				nFrame--;
		}
		CLS;
		gotoxy(30, 12), puts("G A M E  O V E R"); // 게임 끝 처리
		gotoxy(23, 14), puts("If you want restart game press [ Y ]"); // 재시작
		gotoxy(27, 16), puts("another any key [ Exit ]");
		if (tolower(getch()) != 'y') break;
	}
	SetCursorType(NORMALCURSOR);
}
Exemplo n.º 4
0
int GetUPSData(int *energy, int *status_cnt, int *error_cnt)
{
	*energy = make_rand(68, 75);
	*status_cnt = make_rand(0, 2);
	*error_cnt = make_rand(0, 2);

	log_debug("Energy:%d\n", *energy);
	
	return 0;
}
Exemplo n.º 5
0
int GetVCData(double *voltage, double *current, double *power)
{
	*voltage = make_rand(190, 230);
	*current = make_rand(3, 6);
	*power = (*voltage) * (*current);

	log_debug("Voltage:%lf, current:%lf, power:%lf\n", *voltage, *current, *power);
	
	return 0;
}
Exemplo n.º 6
0
void Particle::make_particle(){
	
	for(int i = 0;i<MAX_PARTICLE_COUNT;i+=1){
		double x = make_rand(SIZE_LIMIT);
		double y = make_rand(SIZE_LIMIT);
		double z = make_rand(HEIGHT_LIMIT);
		
		Point3D p(x,y,z);
		particle_array[i] = p;
	}
}
Exemplo n.º 7
0
/****************************************************************
FunctionName    :   GAgent_Clean_Config
Description     :   GAgent clean the device config                  
pgc             :   global staruc 
return          :   NULL
Add by Frank Liu     --2015-05-08
****************************************************************/
void GAgent_Clean_Config( pgcontext pgc )
{
    memset( pgc->gc.old_did,0,DID_LEN);
    memset( pgc->gc.old_wifipasscode,0,PASSCODE_MAXLEN + 1);
  
    memcpy( pgc->gc.old_did,pgc->gc.DID,DID_LEN );
    memcpy( pgc->gc.old_wifipasscode,pgc->gc.wifipasscode,PASSCODE_MAXLEN + 1 );
    GAgent_Printf(GAGENT_INFO,"Reset GAgent and goto Disable Device !");  
    Cloud_ReqDisable( pgc );
    GAgent_SetCloudConfigStatus( pgc,CLOUD_RES_DISABLE_DID );

    memset( pgc->gc.wifipasscode,0,PASSCODE_MAXLEN + 1);
    memset( pgc->gc.wifi_ssid,0,SSID_LEN_MAX + 1 );
    memset( pgc->gc.wifi_key,0, WIFIKEY_LEN_MAX + 1 );
    memset( pgc->gc.DID,0,DID_LEN);
    
    memset( (uint8*)&(pgc->gc.cloud3info),0,sizeof( GAgent3Cloud ) );
    
    memset( pgc->gc.GServer_ip,0,IP_LEN_MAX + 1);
    memset( pgc->gc.m2m_ip,0,IP_LEN_MAX + 1);
    make_rand(pgc->gc.wifipasscode);

    pgc->gc.flag &=~XPG_CFG_FLAG_CONNECTED;
    GAgent_DevSaveConfigData( &(pgc->gc) );
}
Exemplo n.º 8
0
//得到甲醛浓度
static int GetMethanalData(void)
{
    int methanal;

	methanal = make_rand(1, 1000);
    Yeelink_Printf(GAGENT_WARNING, "Methanal:%d\n", methanal);
	
	return methanal;
}
Exemplo n.º 9
0
//得到室内湿度
static int GetHumData(void)
{
    int Hum;

	Hum = make_rand(0, 100);
	Yeelink_Printf(GAGENT_WARNING, "Humidity:%d\n", Hum);
	
	return Hum;
}
Exemplo n.º 10
0
//得到室内温度
static int GetTemData(void)
{
    int temp;

	temp = make_rand(-20, 40);
    Yeelink_Printf(GAGENT_WARNING, "Temperature:%d\n", temp);
	
	return temp;
}
Exemplo n.º 11
0
//得到粉尘浓度
static int GetDustData(void)
{
	int Dust;
	
	Dust = make_rand(5, 500);
	Yeelink_Printf(GAGENT_WARNING, "Dust:%d\n", Dust);
	
	return Dust;
}
Exemplo n.º 12
0
//Use circle algorithm for genertaion
void HM::make_circle(int round){
	//Choose a random point from grid to be the circle center
	for(int i = round;i>0;i-=1){	
		Point3D center = height_map[make_rand(map_size)][ make_rand(map_size)];
	
		//Random radius
		double radius =make_rand(map_size/3)+1;
		double disp = get_displacement(i);

		for(int x =0;x< map_size ;x+=1){ 
			for(int y = 0;y< map_size ;y+=1){
				double dis = (height_map[x][y] - center).length();
				double pd = dis*2/radius; 
		
				if(fabs(pd)<= 1.0){
					height_map[x][y][2] += disp/2+cos(pd* M_PI)*disp/2;
				}
			}
		}
		smoothing();
	}
	
}
Exemplo n.º 13
0
/***************************************
*
*   重置WiFi的 wifipasscode,wifi_ssid
*              wifi_key     Cloud_DId
*
****************************************/
void WiFiReset()
{
    memset( g_stGAgentConfigData.wifipasscode,0,16 );
    memset( g_stGAgentConfigData.wifi_ssid,0,32 );  
    memset( g_stGAgentConfigData.wifi_key,0,32 );
    memset( g_stGAgentConfigData.Cloud_DId,0,GAGENT_DID_LEN_MAX );
    
    make_rand(g_stGAgentConfigData.wifipasscode);
    //清楚标志位
    g_stGAgentConfigData.flag &=~XPG_CFG_FLAG_CONNECTED; 
    DRV_GAgent_SaveConfigData(&g_stGAgentConfigData);
    DIdLen = 0;    
    DRV_GAgent_Reset();
    return;
}
Exemplo n.º 14
0
void HM::reset(){
	int offset =  (MAP_BOUND/2);
	int low_bound= -offset;
	int up_bound = 1 + offset;
	
	for(int i = low_bound;i<up_bound;i+=1){
		for(int j = low_bound;j<up_bound;j+=1){
			Point3D p(i,j,0);
			height_map[i+offset][j+offset] = p;
		}
	}
	
	for(int i =0;i<MAP_BOUND-1;i+=1){ 
		for(int j = 0;j<MAP_BOUND-1;j+=1){
			normal_map[i][j][2] = 1;
		}
	}
	
	displacement = make_rand(MAX_DISPLACEMENT)+1;
	
}
Exemplo n.º 15
0
int execute_random(struct rr_state *theState)
{
    long nt;
    long nc;
    struct Cell_head window;
    int nrows, ncols, row, col;
    int infd, cinfd, outfd;
    struct Map_info Out;
    struct field_info *fi;
    dbTable *table;
    dbColumn *column;
    dbString sql;
    dbDriver *driver;
    struct line_pnts *Points;
    struct line_cats *Cats;
    int cat;
    RASTER_MAP_TYPE type;
    int do_check;

    G_get_window(&window);

    nrows = Rast_window_rows();
    ncols = Rast_window_cols();

    /* open the data files, input raster should be set-up already */
    if ((infd = theState->fd_old) < 0)
	G_fatal_error(_("Unable to open raster map <%s>"),
		      theState->inraster);
    if (theState->docover == TRUE) {
	if ((cinfd = theState->fd_cold) < 0)
	    G_fatal_error(_("Unable to open raster map <%s>"),
			  theState->inrcover);
    }

    if (theState->outraster != NULL) {
	if (theState->docover == TRUE)
	    type = theState->cover.type;
	else
	    type = theState->buf.type;
	outfd = Rast_open_new(theState->outraster, type);
	theState->fd_new = outfd;

    }

    if (theState->outvector) {
	if (Vect_open_new(&Out, theState->outvector, theState->z_geometry) < 0)
	    G_fatal_error(_("Unable to create vector map <%s>"),
			    theState->outvector);
	Vect_hist_command(&Out);

	fi = Vect_default_field_info(&Out, 1, NULL, GV_1TABLE);

	driver =
	    db_start_driver_open_database(fi->driver,
					  Vect_subst_var(fi->database, &Out));
	if (!driver)
	    G_fatal_error(_("Unable to open database <%s> by driver <%s>"),
			  Vect_subst_var(fi->database, &Out), fi->driver);
        db_set_error_handler_driver(driver);
        
	Vect_map_add_dblink(&Out, 1, NULL, fi->table, GV_KEY_COLUMN, fi->database,
			    fi->driver);

	if (theState->docover == TRUE)
	    table = db_alloc_table(3);
	else
	    table = db_alloc_table(2);
	db_set_table_name(table, fi->table);

	column = db_get_table_column(table, 0);
	db_set_column_name(column, GV_KEY_COLUMN);
	db_set_column_sqltype(column, DB_SQL_TYPE_INTEGER);

	column = db_get_table_column(table, 1);
	db_set_column_name(column, "value");
	db_set_column_sqltype(column, DB_SQL_TYPE_DOUBLE_PRECISION);

	if (theState->docover == TRUE) {
	    column = db_get_table_column(table, 2);
	    db_set_column_name(column, "covervalue");
	    db_set_column_sqltype(column, DB_SQL_TYPE_DOUBLE_PRECISION);
	}
	if (db_create_table(driver, table) != DB_OK)
	    G_warning(_("Cannot create new table"));

	db_begin_transaction(driver);

	Points = Vect_new_line_struct();
	Cats = Vect_new_cats_struct();
	db_init_string(&sql);
    }

    if (theState->outvector && theState->outraster)
	G_message(_("Writing raster map <%s> and vector map <%s> ..."),
		  theState->outraster, theState->outvector);
    else if (theState->outraster)
	G_message(_("Writing raster map <%s> ..."), theState->outraster);
    else if (theState->outvector)
	G_message(_("Writing vector map <%s> ..."), theState->outvector);

    G_percent(0, theState->nRand, 2);

    init_rand();
    nc = (theState->use_nulls) ? theState->nCells :
	theState->nCells - theState->nNulls;
    nt = theState->nRand;	/* Number of points to generate */
    cat = 1;

    /* Execute for loop for every row if nt>1 */
    for (row = 0; row < nrows && nt; row++) {
	Rast_get_row(infd, theState->buf.data.v, row, theState->buf.type);
	if (theState->docover == TRUE) {
	    Rast_get_row(cinfd, theState->cover.data.v, row,
			 theState->cover.type);
	}

	for (col = 0; col < ncols && nt; col++) {
	    do_check = 0;

	    if (theState->use_nulls || !is_null_value(theState->buf, col))
		do_check = 1;
	    if (do_check && theState->docover == TRUE) {	/* skip no data cover points */
		if (!theState->use_nulls &&
		    is_null_value(theState->cover, col))
		    do_check = 0;
	    }

	    if (do_check && make_rand() % nc < nt) {
		nt--;
		if (is_null_value(theState->buf, col))
		    cpvalue(&theState->nulls, 0, &theState->buf, col);
		if (theState->docover == TRUE) {
		    if (is_null_value(theState->cover, col))
			cpvalue(&theState->cnulls, 0, &theState->cover, col);
		}

		if (theState->outvector) {
		    double x, y, val, coverval;
		    char buf[500];

		    Vect_reset_line(Points);
		    Vect_reset_cats(Cats);

		    x = window.west + (col + .5) * window.ew_res;
		    y = window.north - (row + .5) * window.ns_res;

		    val = cell_as_dbl(&theState->buf, col);
		    if (theState->docover == 1)
			coverval = cell_as_dbl(&theState->cover, col);

		    if (theState->z_geometry)
			Vect_append_point(Points, x, y, val);
		    else
			Vect_append_point(Points, x, y, 0.0);
		    Vect_cat_set(Cats, 1, cat);

		    Vect_write_line(&Out, GV_POINT, Points, Cats);

		    if (theState->docover == 1)
			if (is_null_value(theState->cover, col))
			    sprintf(buf,
				    "insert into %s values ( %d, %f, NULL )",
				    fi->table, cat, val);
			else
			    sprintf(buf,
				    "insert into %s values ( %d, %f, %f )",
				    fi->table, cat, val, coverval);
		    else
			sprintf(buf, "insert into %s values ( %d, %f )",
				fi->table, cat, val);
		    db_set_string(&sql, buf);

		    if (db_execute_immediate(driver, &sql) != DB_OK)
			G_fatal_error(_("Cannot insert new record: %s"),
				      db_get_string(&sql));

		    cat++;
		}
		G_percent((theState->nRand - nt), theState->nRand, 2);
	    }
	    else {
		set_to_null(&theState->buf, col);
		if (theState->docover == 1)
		    set_to_null(&theState->cover, col);
	    }

	    if (do_check)
		nc--;
	}

	while (col < ncols) {
	    set_to_null(&theState->buf, col);
	    if (theState->docover == 1)
		set_to_null(&theState->cover, col);
	    col++;
	}

	if (theState->outraster) {
	    if (theState->docover == 1)
		Rast_put_row(outfd, theState->cover.data.v,
				 theState->cover.type);
	    else
		Rast_put_row(outfd, theState->buf.data.v,
				 theState->buf.type);
	}
    }

    /* Catch any remaining rows in the window */
    if (theState->outraster && row < nrows) {
	for (col = 0; col < ncols; col++) {
	    if (theState->docover == 1)
		set_to_null(&theState->cover, col);
	    else
		set_to_null(&theState->buf, col);
	}
	for (; row < nrows; row++) {
	    if (theState->docover == 1)
		Rast_put_row(outfd, theState->cover.data.v,
				 theState->cover.type);
	    else
		Rast_put_row(outfd, theState->buf.data.v,
				 theState->buf.type);
	}
    }

    if (nt > 0)
	G_warning(_("Only [%ld] random points created"),
		  theState->nRand - nt);

    /* close files */
    Rast_close(infd);
    if (theState->docover == TRUE)
	Rast_close(cinfd);
    if (theState->outvector) {
	db_commit_transaction(driver);
	if (db_create_index2(driver, fi->table, GV_KEY_COLUMN) != DB_OK)
	    G_warning(_("Unable to create index"));
	if (db_grant_on_table
	    (driver, fi->table, DB_PRIV_SELECT,
	     DB_GROUP | DB_PUBLIC) != DB_OK) {
	    G_fatal_error(_("Unable to grant privileges on table <%s>"),
			  fi->table);
	}
	db_close_database_shutdown_driver(driver);
	if (theState->notopol != 1)
	    Vect_build(&Out);
	Vect_close(&Out);
    }
    if (theState->outraster)
	Rast_close(outfd);

    return 0;
}				/* execute_random() */