示例#1
0
/*
 * Allocate memory.
 *
 * size         Number of bytes to allocate.
 * descr        Short description of what this memory will be used for.
 */
void *
mem_alloc(uint size, const char *descr)
{
        UNUSED(descr);
        assert(size > 0 && descr);
        void *ptr = malloc(size);
#if MEMDEBUG
        if (alloc_mutex == NULL)        /* XXX Race condition.. */
                alloc_mutex = SDL_CreateMutex();
        SDL_mutexP(alloc_mutex);
        {
                assert(ptr);
                allocation *alc = malloc(sizeof(allocation));
                alc->ptr = ptr;
                alc->size = size;
                snprintf(alc->descr, sizeof(alc->descr), "%s", descr);
                HASH_ADD_PTR(alloc_hash, ptr, alc);
                
                /* Update total number of allocated bytes. */
                total_bytes += size;
                log_msg("[MEM] Alloc %p=%s for `%s` (total: %s)", ptr,
                        human(size), descr, human(total_bytes));
        }
        SDL_mutexV(alloc_mutex);
#endif
        return ptr;
}
示例#2
0
文件: level5.c 项目: YugeShunki/git
void game(void){//ゲーム内容
  int j;
  
  gsetnonblock(ENABLE);//ノンブロッキングモードに
  while(1){	
    gclr(win);//画面消去
   
    //防護壁のx座標設定(レベル5になるまで値変化)
    defence_x=rand()%400;
    if(defence_x > 320){//x座標が340を超えたら340以下の数を減らす
      defence_x -= rand()%320;
    }
    LEVEL5();//レベル5の動作
    
    newpen(win, 1);
    level();// レベルの表記
    timecount();//時間の表記
    human();// 棒人間
    input();//入力待ち
    
    for(i=0; i<kosu; i++){
      j = rand() % 16;// 色はランダム
      if(j < 3) j = j + rand() % 10 + 3;//色は3〜15のどれか 
      if(a > 2){	 //レベル3、4でときどき黒になって消えて見える
	if(rand()%5 == 0) j = 0;
      }
      newpen(win, j);
      fillrect(win, x_sq[i], y_sq[i], w_sq[i], h_sq[i]);//四角	 
      fillcirc(win, x_circ[i], y_circ[i], r_circ[i], r_circ[i]);//円	        
      LEVEL4();//レベル4のみ出る円(半分を埋め尽くす円)
      
      //落下速度dx,dy
      y_sq[i] -= dy;
      y_circ[i] -= dy;
      
      LEVEL2();//レベル2以上で変化させる
    }
    atari();//当たり判定
    
    msleep(time);// 0.1秒止める
    
    count++;
    if(count/10 == 20*a){// カウント10回=約1秒とする
      dy += rand()%2+1;//速度変化は毎回変わる
      dx += rand()%2;//揺れる大きさ
      a++;//レベル
      kosu+=rand()%2+1;//増やす個数は毎回変わる 
      dh+=3;//通常四角の縦幅変化量
      dw+=3;//通常四角の横幅変化量
      dr+=3;//通常円の半径の変化量
    }
  }    
}
示例#3
0
文件: main.cpp 项目: WebF0x/StrongAI
void manualTesting( NeuralNetAI& ai )
{
    TicTacToeHuman human( 9, 9, 1, 1 );
    TicTacToe game;
    const int NUM_OF_GAMES = 10;

    for( int i = 0; i < NUM_OF_GAMES; i++ )
    {
        TicTacToe::Token winner = game.match(ai, human );
        verboseEndGame( winner );
    }
}
示例#4
0
/*
 * Reallocate memory. 
 * 
 * ptr          Address of a pointer to the resizable memory.
 * size         Number of bytes to allocate.
 * descr        Short description of what this memory will be used for.
 */
void
mem_realloc(void **ptr, uint size, const char *descr)
{
        assert(ptr && descr);
        
        /* If *ptr is NULL, then do mem_alloc(). */
        if (*ptr == NULL) {
                *ptr = mem_alloc(size, descr);
                return;
        }
        
        *ptr = realloc(*ptr, size);
#if MEMDEBUG
        SDL_mutexP(alloc_mutex);
        {
                /* Find previous allocation. */
                assert(*ptr);
                allocation *alc;
                HASH_FIND_PTR(alloc_hash, ptr, alc);
                assert(alc != NULL);
                
                /* Update total number of allocated bytes. */
                total_bytes += (size - alc->size);
                log_msg("[MEM] Realloc %p=%s -> %p=%s for `%s` (total: %s)",
                        alc->ptr, human(alc->size), *ptr, human(size), descr,
                        human(total_bytes));
                
                /* Remove from hash and update allocation data. */
                HASH_DEL(alloc_hash, alc);
                alc->ptr = *ptr;
                alc->size = size;
                assert(strcmp(descr, alc->descr) == 0);
                
                /* Re-add to hash. */
                HASH_ADD_PTR(alloc_hash, ptr, alc);
        }
        SDL_mutexV(alloc_mutex);
#endif
}
示例#5
0
int main( int argc, char** argv )
{
    fs_info sInfo;
    char    zSize[64];
    char    zUsed[64];
    char    zAvail[64];
    
    if ( argc != 2 ) {
	fprintf( stderr, "USAGE: %s dev_path\n", argv[0] );
	return( 1 );
    }
    if ( probe_fs( argv[1], &sInfo ) < 0 ) {
	fprintf( stderr, "Error: failed to probe device: %s\n", strerror(errno) );
	return( 1 );
    }
    human( zSize, sInfo.fi_total_blocks * sInfo.fi_block_size );
    human( zUsed, (sInfo.fi_total_blocks - sInfo.fi_free_blocks) * sInfo.fi_block_size );
    human( zAvail, sInfo.fi_free_blocks * sInfo.fi_block_size );
    
    printf( "Type        Size  Used  Avail  Use%\n" );
    printf( "%-10s  %-5s %-5s %-6s %.1f%%\n", sInfo.fi_driver_name, zSize, zUsed, zAvail,
	    (1.0 - ((double)sInfo.fi_free_blocks) / ((double)sInfo.fi_total_blocks)) * 100.0 );
}
示例#6
0
/*
 * Free memory.
 */
void
mem_free(void *ptr)
{
#if MEMDEBUG
        SDL_mutexP(alloc_mutex);
        {
                assert(ptr);
                allocation *alc;
                HASH_FIND_PTR(alloc_hash, &ptr, alc);
                assert(alc != NULL);
                
                /* Update total numer of allocated bytes. */
                total_bytes -= alc->size;
                log_msg("[MEM] Free %p=%s for `%s` (total: %s)", ptr,
                        human(alc->size), alc->descr, human(total_bytes));
                
                /* Remove from hash and free allocation. */
                HASH_DEL(alloc_hash, alc);
                free(alc);
        }
        SDL_mutexV(alloc_mutex);
#endif
        free(ptr);
}
int main(int argc, char* argv[])
{
    MinimaxSearcher ms;
    AlphaBetaSearcher abs;
    NegamaxSearcher ns;
    NegamaxAlphaBetaSearcher nabs;


    AlphaBetaSearcher as;
    HumanPlayer human("张三");
    //ComputerPlayer computer1("KA47");
    //computer1.SetSearcher(&as, SEARCH_DEPTH);
    ComputerPlayer computer("ThinkPad X200");
    computer.SetSearcher(&nabs, SEARCH_DEPTH);

    WzEvaluator wzFunc;
    FeEvaluator feFunc;
    GameState init_state;
    init_state.InitGameState(PLAYER_A);
    init_state.SetEvaluator(&feFunc);
    /*
        init_state.SetGameCell(0, PLAYER_A);
        init_state.SetGameCell(1, PLAYER_B);
        init_state.SetGameCell(3, PLAYER_B);
        init_state.SetGameCell(4, PLAYER_B);
        init_state.SetGameCell(5, PLAYER_A);
        init_state.SetGameCell(6, PLAYER_A);
    */
    /*
        init_state.SetGameCell(0, PLAYER_B);
        init_state.SetGameCell(3, PLAYER_B);
        init_state.SetGameCell(4, PLAYER_A);
        init_state.SetGameCell(5, PLAYER_A);
        init_state.SetGameCell(6, PLAYER_A);
        init_state.SetGameCell(8, PLAYER_B);
    */
    GameControl gc;
    gc.SetPlayer(&computer, PLAYER_A);
    gc.SetPlayer(&human, PLAYER_B);
    //gc.SetPlayer(&computer1, PLAYER_B);
    gc.InitGameState(init_state);
    gc.Run();

    return 0;
}
示例#8
0
Players::Players(Configuration config) {

	if(!config.AutoMode) {
		// first player is human for faster lookup.
		std::unique_ptr<Player> human(new Player());

		human->chips.set(config.StartingChips);
		human->Name = "You";

		std::unique_ptr<HumanAI> human_ai(new HumanAI());
		human->AI = std::move(human_ai);
	
		this->items.push_back(std::move(human));
	}
	
	// seed other players
	for(int i=0;i < config.PlayerNames.size(); i++){

		std::unique_ptr<Player> player(new Player());
		player->chips.set(config.StartingChips);
		player->Name = config.PlayerNames[i];

		std::unique_ptr<StockAI> stock_ai(new StockAI());
		player->AI = std::move(stock_ai);
	
		this->items.push_back(std::move(player));
	}

	// set dealer
	std::default_random_engine generator(std::random_device{}());
	std::uniform_int_distribution<int> distribution(0, this->items.size()-1);
	int startingDealer = distribution(generator);

	// we set the dealer then iterator one to also properly seed the big and small blinds.
	this->Dealer = startingDealer;
	nextDealer();
}
示例#9
0
int main (void){
    int game[3], turn, counter=1;
    turn = init(game);
    while (gameCount(game)>0){
        printf("Runde: %d\n",counter);
        printGame(game);
        if(turn){
            human(game);
        }
        else{
            bot(game);
        }
        printf("--------\n");
        turn = !turn;
        counter++;
    }
    if (turn){
        printf("Bot hat gewonnen :(\n");
    }
    else{
        printf("Glückwunsch, Du hast gewonnen!\n");
    }
    return 0;
}
示例#10
0
	void ZombieGame::init() {
		keyboard_ = DevicePtr(new InputKeyboard(SDLK_UP, SDLK_DOWN, SDLK_LEFT,
			SDLK_RIGHT, SDLK_SPACE, SDLK_r, SDLK_LSHIFT, SDLK_e));		
		clipsize_ = 0;
		bulletsInWeapon_ = 0;
		health_ = 0;
		scale_ = 1.f;
		lastSpawnTime_ = engine_.getTime();
		spawnPeriod_ = 0.5f;

		addKeyListener([&](gui::Component& component, const SDL_Event& keyEvent) {
			keyboard_->eventUpdate(keyEvent);
		});

		if (zombieEntry_.getDeepChildEntry("music switch").getBool()) {
			music_ = zombieEntry_.getDeepChildEntry("music track").getMusic();
			music_.setVolume(zombieEntry_.getDeepChildEntry("music volume").getFloat());
			music_.play(-1);
		}

		tree_ = zombieEntry_.getDeepChildEntry("tree image").getSprite();
		wall_ = zombieEntry_.getDeepChildEntry("buildings wallImage").getSprite();
		nbrUnits_ = 0;

		unitMaxLimit_ = zombieEntry_.getDeepChildEntry("settings unitLimit").getInt();

		innerSpawnRadius_ = zombieEntry_.getDeepChildEntry("settings innerSpawnRadius").getFloat();
		outerSpawnRadius_ = zombieEntry_.getDeepChildEntry("settings outerSpawnRadius").getFloat();
		
		terrain_.loadRoadSprites(zombieEntry_.getDeepChildEntry("roads"));
		loadTerrain();
		
		explosionProperties_ = zombie::loadExplosion(zombieEntry_.getDeepChildEntry("explosion"));

		humanInjured_ = zombieEntry_.getDeepChildEntry("human injuredAnimation").getAnimation();
		humanDie_ = zombieEntry_.getDeepChildEntry("human dieAnimation").getAnimation();
		Unit2D human(loadUnit(this, "human", zombieEntry_, false));
		human.setDieSound(zombieEntry_.getDeepChildEntry("human dieSound").getSound());
		human.setHitSound(zombieEntry_.getDeepChildEntry("human hitSound").getSound());
		
		zombieInjured_ = zombieEntry_.getDeepChildEntry("zombie injuredAnimation").getAnimation();
		zombieDie_ = zombieEntry_.getDeepChildEntry("zombie dieAnimation").getAnimation();
		Unit2D zombie(loadUnit(this, "zombie", zombieEntry_, true));
		zombie.setDieSound(zombieEntry_.getDeepChildEntry("zombie dieSound").getSound());
		zombie.setHitSound(zombieEntry_.getDeepChildEntry("zombie hitSound").getSound());

		// Add human to engine.
		{
			State state(Position(85,120), ORIGO, 0);
			//Position p = generatePosition(spawningPoints_);
			//State state(Position(200,200), ORIGO, 0);
			Unit* unit = units_.pushBack(human);
			engine_.add(unit);
			unit->setState(state);
			unit->setActive(true);
			unit->setAwake(true);
			players_.push_back(std::unique_ptr<HumanPlayer>(new HumanPlayer(keyboard_, unit)));
			viewPosition_ = state.position_;
			refViewPosition_ = viewPosition_;
			++nbrUnits_;
		}

		// Add zombies to engine.
		calculateValidSpawningPoints(units_[0]);
		unsigned int unitLevel = zombieEntry_.getDeepChildEntry("settings unitLevel").getInt();
		for (unsigned int i = 1; i <= unitLevel && i < units_.getMaxSize(); ++i) {
			Position p = generatePosition(vaildSpawningPoints_);
			float angle = calculateAnglePointToPoint(p, units_[0].getPosition());
			State state(p, ORIGO, angle);
			Unit* unit = units_.pushBack(zombie);
			engine_.add(unit);
			unit->setState(state);
			unit->setActive(true);
			unit->setAwake(true);
			players_.push_back(std::unique_ptr<ZombieBehavior>(new ZombieBehavior(unit)));
		}
	
		// Add cars to engine.
		Car2D car(zombie::loadCar(zombieEntry_.getDeepChildEntry("car")));
		for (unsigned int i = 0; i < 8 && i < units_.getMaxSize(); ++i) {
			State state(Position(85,130), ORIGO, 0);
			Car* c = cars_.pushBack(car);
			engine_.add(c);
			c->setState(state);
			c->setActive(true);
			c->setAwake(true);
		}

		// Add missile to engine.
		Missile2D missile(loadMissile2D(this, zombieEntry_.getDeepChildEntry("equipment missile")));
		for (unsigned int i = 0; i < 10 && i < units_.getMaxSize(); ++i) {
			engine_.add(missiles_.emplaceBack(missile));
		}

		setBackgroundColor(0, 0.1f, 0);
		zombiesKilled_ = 0;

		drawBuildings_.createVBO(buildings_, wall_.getTexture());
	}
示例#11
0
文件: level5.c 项目: YugeShunki/git
void LEVEL5(void){//レベル5の動作
  if(a==5){
    while(1){
      gclr(win);
      human();//棒人間
      input();//入力待ち
      
      newpen(win, 1);//色は白
      //防護壁表記
      fillrect(win,defence_x, defence_y, defence_w, defence_h1);
      fillrect(win,defence_x+40.0, defence_y+60.0, defence_w, defence_h2);
      fillrect(win,defence_x+80.0, defence_y, defence_w, defence_h3);
      defence_y -= 15.0;//速度
      
      atari();//当たり判定
      //一番下まで落ちたら    
      if(defence_y == 0){
	while(1){
	  gclr(win);//画面消去
	  human();//棒人間
	  input();//入力待ち
	  bougoheki();//防護壁	
	  atari();//当たり判定
	  newpen(win, 2);//太陽の色は赤で
	  fillcirc(win,all_x, all_y, 200, 200);//太陽
	  all_y-=5.0;//落下速度
	  
	  //太陽が防護壁に当たったら
	  if(all_y==280.0){
	    while(1){
	      gclr(win);//画面消去
	      human();//棒人間
	      input();//入力待ち
	      bougoheki();//防護壁
	      atari();//当たり判定
	      newpen(win, 2);//線は赤
	      
	      //太陽ぶつかった後の線
	      lastline();
	      msleep(time);
	      
	      if(explo_y1<0){//下に伸びた線が0以下になったら
		if(defence_x+40 < x && x < defence_x+80){//中にいれば
		  newpen(win, 1);
		  drawstr(win, 180, 250, 24, 0, "SAFE");
		  msleep(time*10);
		  gclr(win);
		  newpen(win, 1);
		  drawstr(win, 100, 300, 24, 0.0, "CONGRATULATIONS!");
		  drawstr(win, 170, 250, 24, 0.0, "CLEAR");
		  msleep(time*30);
		  exit(0);
		}
		else {//外にいれば
		  newpen(win, 1);
		  drawstr(win, 190, 250, 24, 0, "OUT");
		  msleep(time*10);
		  gclr(win);
		  newpen(win, 1);
		  drawstr(win, 150, 250, 24, 0.0, "GAMEOVER");
		  msleep(time*30);
		  exit(0);
		}
	      }
	    }
	  }
	  msleep(time);
	} 
      }
      msleep(time);   
    } 
  }
}
示例#12
0
int main(int argc, char *argv[])
{
	int ready = 0;					//Variable die das ende des Spiels signalisiert 
	char *player;
	player = *argv++;

	init();
	printf("*********VIER GEWINNT***********\n\n");

	player = *argv++;					
	
	if(player != NULL)					//checken ob Argumente uebergeben wurde
	{
		check_player(player);

		player = *argv++;

		if(player != NULL)					//checken ob 2. Argument angeben wurde
		{
			check_player(player);
		}
	}
	

	while(ready != 1)
	{
		print_spielfeld();
		printf("Player ");

		if(two_human == 1 && two_player == 1)				//player vs. bot
		{
			if(human_first == 1)
			{
				if(player_first == 2)
				{
					human(1);					//mensch faengt an
					if(check_who_win(1)==1)
					{
						print_spielfeld();
						printf("Human Player 'X' hat gewonnen!\n");
						ready = 1;
					}
				}
				else
				{
					human(2);					//player faengt an
					if(check_who_win(1)==1)
					{
						print_spielfeld();
						printf("Human Player 'O' hat gewonnen!\n");
						ready = 1;
					}
				}
				human_first = 0;
			}else
			{
				karl(player_first,spielfeld);

				if(check_who_win(player_first)==1)
				{
					print_spielfeld();
					if(player_first == 2)
					{
						printf("Bot 'O' hat gewonnen!\n");
					}
					else
					{
						printf("Bot Player 'X' hat gewonnen!\n");
					}
					ready = 1;
				}
				human_first = 1;

			}
		}
		else if(two_human == 1)								//player vs. player
		{
			if(human_first == 1)
			{
				human(1);
				human_first = 0;
				if(check_who_win(1)==1)
				{
					print_spielfeld();
					printf("Human Player 1 'X' hat gewonnen!\n");
					ready = 1;
				}
			}else
			{
				human(2);
				human_first = 1;
				if(check_who_win(2)==1)
				{
					print_spielfeld();
					printf("Human Player 2 'O' hat gewonnen!\n");
					ready = 1;
				}
			}
		}
		else												//bot vs. bot
		{
			if(human_first == 1)
			{
				karl(1,spielfeld);
				if(check_who_win(1)==1)
				{
					print_spielfeld();
					printf("Karl Player 1 'X' hat gewonnen!\n");
					ready = 1;
				}
				human_first = 0;
			}else
			{
				karl(2,spielfeld);
				if(check_who_win(2)==1)
				{
					print_spielfeld();
					printf("Karl Player 2 'O' hat gewonnen!\n");
					ready = 1;
				}
				human_first = 1;
			}
		}
	}

	return 0;
}