void Player::botGameStart(Bot &b) { cout << " The bot game is setting " << endl; b.botSettingGame(); b.botDisplayGame(); }
Simulator::Simulator(QGraphicsScene *scene, QObject *parent): QObject(parent), timerId(0), scene(scene){ // Define the gravity vector. b2Vec2 gravity(0.0f,-10.0f); world = new b2World(gravity, true); b2BodyDef bodyDef; b2PolygonShape shapeDef; b2FixtureDef fixtureDef; bodyDef.position.Set(200.0f,-250); shapeDef.SetAsBox(100.0f, 10.0f); fixtureDef.shape = &shapeDef; groundBody = world->CreateBody(&bodyDef); groundBody->CreateFixture(&fixtureDef); // Create lots of little colored triangles, random pos, rotation, color. for (int i = 0; i < BODYCOUNT; ++i) { //poly << QPointF(0, -10) << QPointF(-5, 0) << QPointF(5, 0); Bot* polygon = bodyItems[i] = new Bot(world); polygon->setPos(200+-20 + qrand() % 40,200+ -75 - qrand() % 150); polygon->setRotation(qrand() % 360); polygon->setBrush(QColor(128 + qrand() % 128, 128 + qrand() % 128, 128 + qrand() % 128)); polygon->_init(); scene->addItem(polygon); } }
void GameMechanic::UpdateShoot(float dt) { vector<Bullet*>::iterator it; for(it = mBullets.begin(); it != mBullets.end(); ++it) { Bullet* bullet = *it; bullet->Update(dt); vector<Bot*>::iterator botIt; for (botIt = mBots.begin(); botIt != mBots.end(); ++botIt ) { Bot* bot = *botIt; if(xEntityDistance(bot->GetHandle(), bullet->GetHandle()) < 50.f) { bot->DealDamage(mPlayer->GetDamage()); if(bot->GetHealth() == 0) RemoveBot(botIt); RemoveBullet(it); return; } } //todo: investigate how to remove group of objects from collection float distance = xEntityDistance(bullet->GetHandle(), bullet->GetStartPositionPivot()); if( distance > 1000.f) { RemoveBullet(it); return; } } }
int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); std::cout << "start test\n"; Irc* irc = new Irc("irc.quakenet.org", 6667); Bot* bot = new Bot(irc); PingListener* ping_listener = new PingListener; bot->AddListener("irc.ping", ping_listener); AutoJoin* aj = new AutoJoin; bot->AddListener("irc.connect", aj); // Disconnect automatically from irc in 3 seconds Disconnecter* disconnecter = new Disconnecter; bot->AddListener("irc.connect", disconnecter); int bret = bot->Run(); std::cout << bret << std::endl; sleep(8); //wait 8 s bret = irc->Disconnect(); std::cout << "Disconnected: " << bret << std::endl; delete bot; // delete bot; return a.exec(); }
void GameEngine::drawHPGraph() { glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); int w = glutGet(GLUT_WINDOW_WIDTH); int h = glutGet(GLUT_WINDOW_HEIGHT); gluOrtho2D(0, w, h, 0); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glColor3f(1, 1, 1); glTranslatef(5, 18, 0); glScalef((GLfloat)bot.GetHP() / bot.GetMaxHP(), 1, 1); glBegin(GL_QUADS); glColor3f(1.0f, 0.0f, 0.0f); glVertex2i(0, 0); glColor3f(1.0f, 1.0f, 0.0f); glVertex2i(170, 0); glColor3f(1.0f, 1.0f, 0.0f); glVertex2i(170, 5); glColor3f(1.0f, 0.0f, 0.0f); glVertex2i(0, 5); glEnd(); glPopMatrix(); glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); }
int main (void) { ifstream fich; fich.open(FILE_NAME); Bot BOT (&fich); fich.close(); while (1) { BOT.exe(); BOT.modifyEnvironment(); } }
int EntityManager::createEntitiesFromFolder(std::list<Bot*> bots, int iterator) { (void)iterator; Bot *newEntity = bots.back(); _id++; newEntity->setId(_id); _entities.push_back(newEntity); return (_id); }
int main(int argc, char** argv) { gnutls_global_init(); curl_global_init(CURL_GLOBAL_ALL); Logger::instance = new StderrLogger(); ConnectionDispatcher d; std::vector<Bot*> bots; Data::add_type("string", new StringType()); Data::add_type("int", new IntType()); Data::add_type("pair", new PairType()); Data::add_type("list", new ListType()); Data::add_type("map", new MapType()); if (util::fs::exists("./bot.conf")) // move old bot.conf to networks/default.conf { if (!util::fs::is_directory("./networks")) { util::fs::mkdir("./networks"); } util::fs::rename("./bot.conf", "./networks/default.conf"); } Config *c = NULL; auto networks = util::fs::listdir("./networks"); for (auto name : networks) { c = Config::load("./networks/" + name); Config *l = Config::load("./lang/" + c->get("locale.language")->as_string() + ".conf"); Bot *b = new IRCBot(c, l); bots.push_back(b); b->connect(&d); } while(true) { if(d.count() == 0) { break; } d.handle(); } Data::cleanup_types(); curl_global_cleanup(); gnutls_global_deinit(); return 0; }
void BotRecycler::addMoreBots(wstring botType, unsigned int numToAdd) { // NOW MAKE THE BOTS Bot* sampleBot = registeredBotTypes[botType]; for (unsigned int i = 0; i < numToAdd; i++) { Bot *botClone = sampleBot->clone(); recyclableBots[botType]->push_back(botClone); } }
int main(int argc, char *argv[]) { Bot bot; if(bot.connectToServer()==sf::Socket::Done) { bot.registerConnection(); bot.join(); bot.loop(); } }
int main(int argc, char *argv[]) { std::cout.sync_with_stdio(0); Bot* bot = new Bot(); bot->playGame(); delete bot; LOG("Bot gracefully shutting down..."); return 0; }
int main() { Bot bot; std::string str = ""; while(!([&str]() -> std::istream& { std::cout << ">> "; return std::getline(std::cin, str); }().eof() || std::cin.fail() || std::cin.bad())) { if(bot.IssueCommand(str) == false) { break; } } return 0; }
void AI::unload(Bot& actor, Unit& target) { if(actor.actions()==0) { cout<<"Big guy cant attack?"<<endl; } while(actor.actions()>0) { if(actor.damage()==0){cout<<"NOT ";}; cout<<"ATTACKING!"<<endl; actor.attack(target); } }
extern "C" void AI_addevent(int _eventType, int _causeObjectId, int _targetObjectId, int _unitType, float _longitude, float _latitude) { m_bot.AddEvent(_eventType, _causeObjectId, _targetObjectId, _unitType, _longitude, _latitude); }
/* update - This method should be called once per frame. It goes through all of the sprites, including the player, and calls their update method such that they may update themselves. */ void SpriteManager::update(Game *game) { // UPDATE THE PLAYER SPRITE player.updateSprite(); // NOW UPDATE THE REST OF THE SPRITES list<Bot*>::iterator botIterator; botIterator = bots.begin(); while (botIterator != bots.end()) { Bot *bot = (*botIterator); bot->think(game); bot->updateSprite(); botIterator++; } }
int main(void) { Bot a = Bot(); float c_rgb[3]; GLFWwindow* window; glfwSetErrorCallback(error_callback); if (!glfwInit()) exit(EXIT_FAILURE); window = glfwCreateWindow(640, 480, "Simple example", NULL, NULL); if (!window) { glfwTerminate(); exit(EXIT_FAILURE); } glfwMakeContextCurrent(window); glfwSwapInterval(1); glfwSetKeyCallback(window, key_callback); while (!glfwWindowShouldClose(window)) { float ratio; int width, height; glfwGetFramebufferSize(window, &width, &height); ratio = width / (float)height; glViewport(0, 0, width, height); glClear(GL_COLOR_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-ratio, ratio, -1.f, 1.f, 1.f, -1.f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glRotatef((float)glfwGetTime() * 50.f, 0.f, 0.f, 1.f); glBegin(GL_TRIANGLES); a.getColor(c_rgb); glColor3f(c_rgb[0], c_rgb[1], c_rgb[2]); glVertex3f(-0.6f, -0.4f, 0.f); //glColor3f(0.f, 1.f, 0.f); glVertex3f(0.6f, -0.4f, 0.f); //glColor3f(0.f, 0.f, 1.f); glVertex3f(0.f, 0.6f, 0.f); glEnd(); glfwSwapBuffers(window); glfwPollEvents(); } glfwDestroyWindow(window); glfwTerminate(); exit(EXIT_SUCCESS); }
// AI_run() is called by DEFCON during every game update cycle (every 100ms) extern "C" bool AI_run() { m_bot.Update(); return true; }
void found_beacon(string top, string bottom, pair<double, double> position) { double d = position.first; double theta = position.second; pair<double, double> bot_pos = bot.get_position(); double beacon_yaw = bot.get_yaw() + theta; double b_x = bot_pos.first + d*cos(beacon_yaw); double b_y = bot_pos.second + d*sin(beacon_yaw); ROS_INFO_STREAM("BOT POS: " << top << " " << bottom << " " << b_x << "," << b_y << "beacon_yaw: " << beacon_yaw << " d: " << d << "robot_yaw " << bot.get_yaw() << "theta: " << theta); for (auto it = beacons.begin(); it != beacons.end(); ++it) { if (it->top == top && it->bottom == bottom) { it->known_location = true; it->x = b_x; it->y = b_y; } } }
void AI::moveTowardsTarget(Bot& actor, Unit& target) { int dist = INT_MAX,startDist = 0; while(actor.steps()>0 && dist > actor.range() && dist != startDist) { //startDist = distance(actor.x(),actor.y(),actor.size(), target.x(),target.y(),target.size()); startDist = distance(actor.x(),actor.y(),actor.size(), target.x(),target.y(),1)+1; cout<<"Distance to target: "<<startDist<<endl; dist = startDist; int dir = 0; // find the best, non blocked direction for(unsigned int d=0;d<DIR_SIZE;d++) { int x=actor.x()+xMod[d]; int y=actor.y()+yMod[d]; if(x>=0 && x<boardX() && y>=0 && y<boardY()) { //int tempDist = distance(x,y,actor.size(), target.x(),target.y(),target.size()); int tempDist = distance(x,y,actor.size(), target.x(),target.y(),1); if(tempDist < dist) { bool blocked = false; // check if blocked TODO add other blocking calls for(unsigned int b=0;b<bots.size() && !blocked;b++) { //if(bots[b].x()==x && bots[b].y()==y && bots[b].partOf()==0) if(bots[b].partOf()==0 && distance(bots[b].x(),bots[b].y(),bots[b].size(),x,y,actor.size())==0 && bots[b].id() != actor.id()) { blocked=true; } } if(!blocked) { dir=d; dist = tempDist; } } } } if(dist != startDist) { cout<<"Big guy moving: "<<direction[dir]<<endl; actor.move(direction[dir]); } else { cout<<"Nothing worth going to!"<<endl; } } }
void Team::randomTeam(unsigned int size) { unsigned int numrules; unsigned int mass; wins(0); losses(0); ties(0); goals(0); name("Team Stochastic"); for (unsigned int i=0; i<size; i++) { numrules = Random::randint(100,200); // pick a random number of rules for each bot mass = Random::randint(1,10); // pick a random number for the bot mass Bot *NewBot = new Bot(this); NewBot->randomBot(numrules, mass); insertBot(NewBot); } }
void GameEngine::Update(float dt) { if (gameover) return; handleInput(); // simulate physics m_world->Step(dt, 8, 3); // update entity bot.Update(); // update game scenario elapsedTime = glutGet(GLUT_ELAPSED_TIME) - initializedTime; long additionalBullets = elapsedTime / 2000; if (m_bulletCount < MAX_BULLET_COUNT + additionalBullets) { createBullet(); } typedef std::list<b2Body*> BodyList; BodyList::iterator end = m_bullets.end(); for (BodyList::iterator it = m_bullets.begin(); it != end; ++it) { b2Body* bullet = *it; const b2Vec2& pos = bullet->GetPosition(); if (pos.x < 0 || pos.x > m_stage.upperBound.x || pos.y < 0 || pos.y > m_stage.upperBound.y) { --m_bulletCount; m_bullets.erase(it); continue; } } if (bot.GetState() == BOT_STATE_DEAD) { // stop the world gameover = true; #ifdef _WIN32 PlaySound(TEXT("scifi011.wav"), NULL, SND_ASYNC); #endif } }
extern "C" int register_command(lua_State *state) { void *b_ = luaL_checkudata(state, 1, "bot"); Bot *b = (Bot*)b_; const char *s = luaL_checkstring(state, 2); if(lua_isfunction(state, 3)) { lua_pushvalue(state, 3); int cmd_ref = luaL_ref(state, LUA_REGISTRYINDEX); b->register_command(s, new LuaCommand(state, s, cmd_ref)); } else { // error } return 0; }
/* update - This method should be called once per frame. It goes through all of the sprites, including the player, and calls their update method such that they may update themselves. */ void SpriteManager::update() { // UPDATE THE PLAYER SPRITE ANIMATION FRAME/STATE/ROTATION if (player != nullptr) player->updateSprite(); // NOW UPDATE THE REST OF THE SPRITES ANIMATION FRAMES/STATES/ROTATIONS list<Bot*>::iterator botIterator = bots.begin(); list<Bot*> markedBots; while (botIterator != bots.end()) { Bot *bot = (*botIterator); bot->think(); bot->updateSprite(); if (bot->isMarkedForRemoval()) markedBots.push_back(bot); botIterator++; } // NOW REMOVE ALL THE MARKED BOTS FROM THE SPRITE MANAGER list<Bot*>::iterator markedBotsIterator = markedBots.begin(); while (markedBotsIterator != markedBots.end()) { Bot *bot = (*markedBotsIterator); bots.remove(bot); markedBotsIterator++; } // AND UPDATE THE SPAWNING POOLS vector<BotSpawningPool*>::iterator spawningPoolIterator = spawningPools.begin(); while (spawningPoolIterator != spawningPools.end()) { BotSpawningPool *pool = (*spawningPoolIterator); pool->update(); // AND ONTO THE NEXT SPAWNING POOL spawningPoolIterator++; } }
Bot *BotControl::GetHighestFragsBot (int team) { Bot *highFragBot = null; int bestIndex = 0; float bestScore = -1; // search bots in this team for (int i = 0; i < engine->GetMaxClients (); i++) { highFragBot = g_botManager->GetBot (i); if (highFragBot != null && IsAlive (highFragBot->GetEntity ()) && GetTeam (highFragBot->GetEntity ()) == team) { if (highFragBot->pev->frags > bestScore) { bestIndex = i; bestScore = highFragBot->pev->frags; } } } return GetBot (bestIndex); }
void BotSpawningPool::update() { countdownCounter--; if (countdownCounter <= 0) { // SPAWN A BOT Game *game = Game::getSingleton(); GameStateManager *gsm = game->getGSM(); SpriteManager *spriteManager = gsm->getSpriteManager(); BotRecycler *botRecycler = spriteManager->getBotRecycler(); Bot *spawnedBot = botRecycler->retrieveBot(botType); spriteManager->addBot(spawnedBot); initCountdownCounter(); // DO IT'S SPAWNING BEHAVIOR BotBehavior *spawningBehavior = spawnedBot->getBehavior(BotState::SPAWNING); spawningBehavior->behave(spawnedBot); // AND START IT LOCATED AT THE SPAWNING POOL PhysicalProperties *pp = spawnedBot->getPhysicalProperties(); pp->setX(x); pp->setY(y); } }
/* update - This method should be called once per frame. It goes through all of the sprites, including the player, and calls their update method such that they may update themselves. */ void SpriteManager::update(Game *game) { // FIRST LET'S DO THE NECESSARY PATHFINDING list<Bot*>::iterator botIterator; botIterator = bots.begin(); while (botIterator != bots.end()) { Bot *bot = (*botIterator); botIterator++; } // THEN UPDATE THE PLAYER SPRITE ANIMATION FRAME/STATE/ROTATION player.updateSprite(); // NOW UPDATE THE REST OF THE SPRITES ANIMATION FRAMES/STATES/ROTATIONS botIterator = bots.begin(); while (botIterator != bots.end()) { Bot *bot = (*botIterator); bot->think(game); bot->updateSprite(); botIterator++; } }
void GameEngine::Draw() { m_world->DrawDebugData(); // draw entity bot.Draw(); m_debugDraw.DrawString(5, 15, "Number of bullets: %d", m_bulletCount); //m_debugDraw.DrawString(5, 30, "HP: %d %d", bot.GetHP(), bot.GetState()); drawHPGraph(); // draw gameover if (gameover) { drawGameover(); } }
void Player::ballMatch(Human& h, Bot& b) { int i, j; for (i = 0; i < 3; i++) { for (j = 0; j < 3; j++) { if (b.getBotSetting(i) == h.getHumanSetting(j)) { if (i == j) { (strike)++; } else { (ball)++; } } } } cout << " strike : " << strike << " ball : " << ball << endl; }
void GameEngine::createActor() { // create actor b2BodyDef bodyDef; bodyDef.type = b2_dynamicBody; bodyDef.position.Set(m_stage.upperBound.x / 2.0f, m_stage.upperBound.y / 2.0); m_actor = m_world->CreateBody(&bodyDef); b2PolygonShape dynamicBox; dynamicBox.SetAsBox(10.0f, 10.0f); b2FixtureDef fixtureDef; fixtureDef.shape = &dynamicBox; fixtureDef.density = 1.0f; fixtureDef.friction = 0.3f; m_actor->CreateFixture(&fixtureDef); bot.Create(m_actor); }
/* addSpriteItemsToRenderList - This method goes through all of the sprites, including the player sprite, and adds the visible ones to the render list. This method should be called each frame. */ void SpriteManager::addSpriteItemsToRenderList( Game *game) { GameStateManager *gsm = game->getGSM(); GameGUI *gui = game->getGUI(); if (gsm->isWorldRenderable()) { GameGraphics *graphics = game->getGraphics(); RenderList *renderList = graphics->getWorldRenderList(); Viewport *viewport = gui->getViewport(); // ADD THE PLAYER SPRITE addSpriteToRenderList(&player, renderList, viewport); /* X = player.getPhysicalProperties() -> getX(); Y = player.getPhysicalProperties() -> getY();*/ //addSpriteToRenderList(&healthBar, renderList, viewport); // NOW ADD THE REST OF THE SPRITES list<Bot*>::iterator botIterator; botIterator = bots.begin(); while (botIterator != bots.end()) { Bot *bot = (*botIterator); if (bot->getCurrentState() == L"DYING" && bot->getRemoval() > 0) bot->setRemoval(bot->getRemoval()-1); if (bot->getRemoval() != 0) { addSpriteToRenderList(bot, renderList, viewport); } if (bot->getRemoval() == 0){ //bot->setCurrentlyCollidable(false); } botIterator++; } } }