示例#1
0
// DO NOT TOUCH ANYTHING {{{
int main() { 
	AI* instance = new AI();
	int n, m, T, x, y;
	cin >> n >> m >> T >> x >> y;

	instance->init(n, m, T, x, y);

	cout << "READY" << endl;
	for(int turn = 1; turn <= T; ++ turn) {
		vector<string> S1;
		for(int i=0; i<	n; ++i) {
			string buf;
			cin >> buf;
			S1.push_back(buf);
		}
		vector< vector<int> > S2;
		for(int i = 0; i < n; ++ i) {
			S2.push_back(vector<int>(m));
			for(int j = 0; j < m; ++ j) {
				cin >> (S2.back()[j]);
			}
		}
		int ox, oy;
		cin >> ox >> oy;
		string act = instance->action(S1, S2, ox, oy);
		cout << act.c_str() << endl;
	}
	delete instance;
	return 0;
}
示例#2
0
//
// This function generates a boss AI for the dungeon at specified coordinates.
//
// @Param x - x coordinate of the spawn point
// @Param y - y coordinate of the spawn point
//
void AI_Group::SpawnBoss(int x, int y)
{
	AI* ai;
	std::random_device rd;
	int sight, speed, type, health, ATK;
	int lv = dungeon->Get_DungeonLevel();
	BossActive = true;

	type = rd() % 2;                             // Randomly pick either 0 or 1 (0 = Melee, 1 = Ranger)
	BossID = rd() % 99999 + 1;                   // Get random ID value (up to 5 digits)
	while (IDExists(BossID))                     // Ensure the ID is unique
		BossID = rd() % 99999 + 1;
	sight = rd() % 3 + 3;                        // Sight ranges from 3 to 5
	speed = rd() % 3 + 2;                        // Speed ranges from 2 to 4
	health = rd() % 11 + 40 + (30 * (lv - 1));   // Health ranges from 40 to 50 (values get higher by 30 per level as dungeon level increases)
	ATK = rd() % 4 + 10 + (5 * (lv - 1));        // ATK ranges from 10 to 13 (values get higher by 5 per level as dungeon level increases)

	if (!type)
		ai = new AI(e_queue, boss_melee_sprite, BOSS_MELEE, sight, speed, health, ATK);
	else
		ai = new AI(e_queue, boss_ranger_sprite, BOSS_RANGER, sight, speed, health, ATK);

	ai->SetSpawn(*dungeon);
	ai->SetXPosition(x);
	ai->SetYPosition(y);

	group.insert(std::pair<int, AI*>(BossID, ai));
}
示例#3
0
int main(int argc, char* argv[]) {
    if(argc != 3 && argc != 2){
        std::cerr << "<usage>: client ip [port]" << std::endl;
        return 1;
    }
    std::string message;
    
    std::string port = argc == 3 ? argv[2] : "12345";
    IO client(argv[1], port);
    client.receive(message);
    
    srand(static_cast<unsigned int>(time(0)+message[0]));
    AI* ai = new AI(message[0]-'0');
    
    client.send(ai->name() + '\n');
    while (true) {
        client.receive(message);
        
        if (message == "game end") {
            break;
        } else if (message == "action") {
            const Operation& op = ai->makeDecision();
            auto decision = boost::format("%d %d %d\n") % op.source.x % op.source.y % DIR_CHAR[op.direction];
            client.send(decision.str());
        } else {
            const int id = message[0]-'0';
            const Point src(message[2]-'0', message[4]-'0');
            const Point tar(message[6]-'0', message[8]-'0');
            ai->update(id, src, tar);
        }
    }
}
void Engine::do_turn( int allegiance ){
	AI* ai = new AI( world );
	Round* r = ai->create_round( allegiance );
	create_controls( r );
	delete ai;
	set_turn( 0 );
}
示例#5
0
文件: Map.cpp 项目: repesorsa/TDpeli
void Map::CreateUnit(float x, float y, UNITTYPE utype, OWNER owner)
{
	AI *ai = new AI(*this);
	Animation *animation = new Animation(m_conf);
	Unit *unit = new Unit(x, y, utype, owner, ai, animation);
	ai->SetOwner(unit);
	m_units.push_back(unit);
}
int main( int argc, const char* argv[] ){
	int motor_ports[8] = {1, 2, 3, 4, 5, 6, 7, 8}
	
	Robot robot = new Robot(motor_ports);
	
	AI ai = new AI(robot);
	
	ai.winTheRace();
}
示例#7
0
文件: game.cpp 项目: sunxfancy/GtkFIR
void Game_private::runAI() {
	printf("Thread AI run\n");
	mp_AI->RunAI(mp_chess);
	if (mp_AI->get_ans_tx()) { printf("电脑投降了\n"); gameWin(); return;  }
	mp_chess->setOneData(mp_AI->get_ans_x(), mp_AI->get_ans_y(), 2);
	int judge_ans = mp_chess->judge();
	if (judge_ans == 1) { gameWin(); return; }
	if (judge_ans == 2) { gameOver(); return; }
	mp_area->queue_draw();
	mp_area->setCanUserclick(true);
}
示例#8
0
  static void turnTest(){
    AI ar = AI("Arun", 5);
    Deck inPlay;
    inPlay.initialize();
    Table blds;

    for (int i = 0; i < 20; ++i) {
      ar.stockPile.push(inPlay.draw(blds.getOutofPlay()));
    }
    ar.takeTurn(inPlay, blds);
    }
示例#9
0
int main()
{
    char ch;
    AI ai;

    while(ai.cget()) {
        while(scanf(" %c", &ch) != EOF && ai.doit(ch));
        ai.cput();
    }

    return 0;
}
示例#10
0
//================================================================================
// Основная нить сервера
//
DWORD WINAPI AIMainThread(LPVOID Param)
{
	AI* ai = (AI*)Param;

	while (true)
	{
		ai->Frame();
		Sleep(10);
	}
	
	return 0;

}
示例#11
0
void NetworkManager::GameInit()
{
	if (m_player->GetType() == Ai)
	{
		AI* ai = (AI*) m_player;
		ai->PlayerInit();
	}
	else
	{
		m_player->PlayerInit();
	}
	
}
示例#12
0
void moveAI()
{

	if(myAI.win() == false)
	{
		if(myAI.block() == false)
		{
			myAI.random_move();
		}
		
	}

}
示例#13
0
int	main(int ac, char **av)
{
  AI	ai;

  if (!parse_args(ac, av, ai))
    return (-1);
  if (!ai.connectToServer())
    return (-1);
  ai.incPid();
  if (!ai.getHeader())
    return (-1);
  ai.actionLoop();
  return (0);
}
		int AIScriptRelay::cpp_nearestEntityId(lua_State *lua, String type)
		{
			AI *nearest = nearestEntity(type);

			if (nearest)
			{
				mCurrentScript->addRecentAiReference(nearest);
				lua_pushnumber(lua, nearest->getHost());

				return 1;
			}

			return 0;
		}
示例#15
0
文件: AI.cpp 项目: MrYD/DxREVERSI
int AI::answerB(Board board)
{
	AI* ai = new AI(board);
	ai->ininB(board);
	if (board.getThisTurn() < ai->startFinalRead)
	{
		return ai->basicRead->answer(ai->readNumber);
	}
	else
	{
		return ai->finalRead->answer();
	}
	delete ai;
}
示例#16
0
/* Callback handler for window re-paint event */
void display() {
    glClear(GL_COLOR_BUFFER_BIT);  // Clear the color buffer
    glMatrixMode(GL_MODELVIEW);    // To operate on the model-view matrix
    glLoadIdentity();              // Reset model-view matrix
    paddleRight.move();
    ball.draw();
    paddleRight.draw();
    paddleLeft.draw();

    glutSwapBuffers();  // Swap front and back buffers (of double buffered mode)

    // Animation Control - compute the location for the next refresh
    ball.contactLeft(paddleLeft);
    ball.contactRight(paddleRight);
    ball.move();
    ai.AIPaddleMove(ball);
    //ai2.AIPaddleMove(ball);
    if (ball.didRoundEnd() == 'R') {
        ++scoreRight;
        ball.resetBallPos();
    }
    else if (ball.didRoundEnd() == 'L') {
        ++scoreLeft;
        ball.resetBallPos();
    }
    else
        return;


}
示例#17
0
文件: Board.cpp 项目: magdy-hasan/XO
void Board::get_move(bool is_2_player_game, AI &_AI,int cur_player){
	Board cur_board_ = *this;
	if (is_2_player_game == false && cur_player == _AI._AI_player)
		place(_AI.get_move(cur_board_, cur_player,-(1<<30),(1<<30)).position, cur_player);
	else{
		while (readMove(cur_player) == false);
	}
	return;
}
		int AIScriptRelay::cpp_nearestEntityId(lua_State *lua)
		{
			String arg = mCurrentScript->getArgString(1);

			if (arg != "")
				return cpp_nearestEntityId(lua, arg);

			AI *nearest = nearestEntity();

			if (nearest)
			{
				mCurrentScript->addRecentAiReference(nearest);
				lua_pushnumber(lua, nearest->getHost());

				return 1;
			}

			return 0;
		}
示例#19
0
  void onTurn(Board& board,Reversi::Point p)
  {
      cout << "コンピュータが思考中";
      
      Ai->move(board);
      
      cout << "完了" << endl;
      if(board.isGameOver()) throw GameOverException();
 
  }
示例#20
0
unsigned _stdcall ArtificialIntelligence(void *clc){
	int kkl;
	while (1){
		kkl = clock() - timeai;
		if (kkl >= 50){
			timeai = clock();
			EnterCriticalSection(&regen);
			_AI.Update(kkl);
			LeaveCriticalSection(&regen);
		}
	}
}
示例#21
0
int main(int argc, char** argv) {
	string input;
	cout << "Color type: Black or White" << endl;
	cin >> input;
	Board* Othello = new Board;
	Othello->SetSquare();
	Player* player = Board::player;
	AI* ai = Board::ai;
	if(input.compare("Black") == 0) {
		player->setType(BLACK);
		ai->setType(WHITE);
		Othello->initializeBoard(argc, argv);
	}
	else if(input.compare("White") == 0) {
		player->setType(WHITE);
		ai->setType(BLACK);
		Othello->initializeBoard(argc, argv);
	}
	else {
		cout << "Invalid choice." << endl;
	}
}
示例#22
0
int main(int argc, char *argv[])
{
    srand(time(NULL));
    cout << "Welcome to Battleship!\nYou will be placing your ships on the bottom half while the\ntop half keeps "
         << "up with your hits and misses" << endl << endl;
    Board board;
    AI ai;
    //setup game
    board.print();
    board.setShips();
    board.setCPUShips();
    cout << endl;
    //play game
    QProcess::execute("clear");

    while(board.getPHits() > 0 && ai.getCPUHits() > 0){
        board.print();
        board.chooseHitSpot();
        ai.runAI(board);
    }

    return 0;
}
int main(int nArgs, char* args[]) {
	
	if (nArgs < 2) {
		return 666;
	}
	
	string fileLoc = "player.data";
	string board = args[1];
	string team = args[2];
	bool isRed = (team.compare("red") == 0);
	
	ifstream playerFile("fileLoc");
	
	Board b(board);
	b.redTurn = isRed;
	AI player;
	playerFile >> player;
	player.playAsRed = isRed;
	player.thinker.maxtime = 14.0;

	cout << player.makeMove(b).toString();
	
}
示例#24
0
文件: 2049.cpp 项目: horazont/2048-ai
int main()
{
    logfile.open("ai++.log", std::ios_base::out | std::ios_base::trunc);
    if (!logfile.is_open()) {
        std::cerr << "ai: cannot open log. terminating." << std::endl;
        return 1;
    }

    RawBoard board;
    uint8_t state;
    AI ai;
    while (true) {
        read_board(std::cin, board);
        read_state(std::cin, state);

        AnalyzeResult result = ai.actuate(board);
        if (std::get<1>(result)) {
            std::cout << (uint8_t)std::get<0>(result) << std::flush;
        } else {
            std::cerr << "ai: no further options. terminating." << std::endl;
            return 0;
        }
    }
}
示例#25
0
void CollidePlayerDino(GameObject* go1, GameObject* go2)
{
  Player* player = dynamic_cast<Player*>(go1);
  Assert(player);
  Dino* dino = dynamic_cast<Dino*>(go2);
  Assert(dino);

  if (dino->IsDead())
  {
    return; // this actually happened!
  }

  // Get the pets to flee the dino
  PetList pets = player->GetPets();
  player->DropPets();
  for (PetList::iterator it = pets.begin(); it != pets.end(); ++it)
  {
    Pet* pet = *it;
    AI* ai = pet->GetAI(AIFlee::NAME);
    ai->SetTarget(dino);
    pet->SetAI(ai);
    pet->SetIsFalling(true);
  }

  Vec3f vel = player->GetVel();
  player->SetVel(-vel);

  vel = dino->GetVel();
  dino->SetVel(Vec3f(0, 0, 0));
  dino->SetAI(AIStunned::NAME);

  PlayWav("hammer_anvil3"); // NB No file ext
  WWCamera* cam = GetActiveCamera();
  Assert(cam);
  cam->SetEarthquake(1.0f); // TODO CONFIG
}
示例#26
0
void statusDraw(WINDOW *win, Player p, AI ai) {
	bool isPlayer = p->getID(p) == 1;

	wattron(win, A_BOLD);
	mvwprintw(win, 1, 1, "Versus AI: Hard");
	mvwprintw(win, 5, 1, "Turn: "); wclrtoeol(win);
	wattron(win, COLOR_PAIR(isPlayer?1:2));
	wprintw(win, "%s", isPlayer?"Player":"AI");
	wattroff(win, COLOR_PAIR(isPlayer?1:2));
	mvwprintw(win, 9, 1, "AI Status:");
	wmove(win, 10, 1); wclrtoeol(win);
	wmove(win, 11, 1); wclrtoeol(win);
	wprintw(win, "%s", !isPlayer?ai->getStatus(ai):"");
	wattroff(win, A_BOLD);
	wrefresh(win);
}
示例#27
0
文件: ai.cpp 项目: felix-halim/scrack
int view_query(int a, int b){
  ai.examined = 0;

  #ifdef AICC // hybrid crack-crack
    int cnt = ai.crack_crack(a,b,marr);
  #endif

  #ifdef AICS // hybrid crack-sort
    int cnt = ai.crack_sort(a,b,marr);
  #endif

  #ifdef AISS // hybrid sort-sort
    int cnt = ai.sort_sort(a,b,marr);
  #endif

  #ifdef AICC1R // hybrid crack-crack with 1 stochastic crack
    int cnt = ai.scrack_scrack(a,b,marr);
  #endif

  #ifdef AICS1R // hybrid crack-sort with 1 stochastic crack
    int cnt = ai.scrack_sort(a,b,marr);
  #endif
  
  #ifdef AICCRP2 // hybrid crack-crack with rounding to nearest power of two
    int aa = a, bb;
    while (aa&(aa-1)) aa &= aa-1;
    if (aa == (1<<30)) bb = 2147483647; else bb = aa<<1;
    ai.crack_crack(aa,bb,marr);
    int cnt = ai.crack_crack(a,b,marr);
  #endif

  #ifdef AICCRMSZ // hybrid crack-crack with rounding to a partition with minimum size = RMSZ
    int aa = (a/RMSZ)*RMSZ, bb = (int) min((long long)b - (b%RMSZ) + RMSZ, 2147483647LL);
    ai.crack_crack(aa,bb,marr);
    int cnt = ai.crack_crack(a,b,marr);
  #endif

  n_touched = ai.examined;
  return cnt;
}
示例#28
0
文件: Main.cpp 项目: yuki74w/Reversi
	void init()override{
		this->dif = m_data->dif;
		board.Init({ 160, 60 });
		font = Font(21, Typeface::Light);
		selectPos = { 0, 0 };
		board.SetPiece({ 3, 3 }, Piece::white);
		board.SetPiece({ 4, 4 }, Piece::white);
		board.SetPiece({ 3, 4 }, Piece::black);
		board.SetPiece({ 4, 3 }, Piece::black);
		//pass = !board.IsAllSetAble(!black ? Piece::white : Piece::black);

		Image Cache1(m_data->archive.load(L"Melamine-wood-001.png"));
		Image Cache2(m_data->archive.load(L"Melamine-wood-002.png"));
		Table = Texture(Cache1);
		Board = Texture(Cache2);

		ai.Init(m_data->archive);
	}
示例#29
0
void computerTurn()
{
	int x, y;
	string choice = tom.getMove(board.grid);

	if (!(choice == ""))
	{
		string Sx = choice.substr(0, choice.find(","));
		string Sy = choice.substr(choice.find(",") + 1, choice.length());

		if ((Sx == "0" || Sx == "1" || Sx == "2") && (Sy == "0" || Sy == "1" || Sy == "2"))
		{
			sscanf_s(Sx.c_str(), "%d", &x);
			sscanf_s(Sy.c_str(), "%d", &y);

			board.setVal(x, y, 1);
		}
	}


}
示例#30
0
static bool	parse_args(int ac, char **av, AI& ai)
{
  if (ac == 2)
    {
      ai.setHost("localhost", 12345);
      ai.setTeamName(av[1]);
      return (true);
    }
  else if (ac == 3)
    {
      ai.setHost("localhost", atoi(av[2]));
      ai.setTeamName(av[1]);
      return (true);
    }
  else if (ac == 4)
    {
      ai.setHost(av[2], atoi(av[3]));
      ai.setTeamName(av[1]);
      return (true);
    }
  std::cout << "usage: ./AI [[Team Name] [[Host] [Port]]]"
	    << std::endl;
  return (false);
}