void AI::objectCheck() { cout<<"--Base AI variables--"<<endl; cout<<"turnNumber\t"<<turnNumber()<<endl; ///Player Number; either 0 or 1 cout<<"playerID\t"<<playerID()<<endl; ///What number game this is for the server cout<<"gameNumber\t"<<gameNumber()<<endl; ///Player 0's time remaining cout<<"player0Time\t"<<player0Time()<<endl; ///Player 1's time remaining cout<<"player1Time\t"<<player1Time()<<endl; ///Player 0's name cout<<"player0Name\t"<<player0Name()<<endl; ///Player 1's name cout<<"player1Name\t"<<player1Name()<<endl; ///The cost of a pirate cout<<"pirateCost\t"<<pirateCost()<<endl; ///The cost of a ship cout<<"shipCost\t"<<shipCost()<<endl; cout<<"portCost\t"<<portCost()<<endl; cout<<"boardX\t"<<boardX()<<endl; cout<<"baordY\t"<<boardY()<<endl; cout<<"--Object counts--"<<endl; cout<<"Pirates : "<<pirates.size()<<endl; displayPirates(); cout<<"Ports : "<<ports.size()<<endl; displayPorts(); cout<<"Ships : "<<ships.size()<<endl; displayShips(); cout<<"Tiles : "<<tiles.size()<<endl; displayTiles(); cout<<"Treasure: "<<treasures.size()<<endl; // displayTreasure(); }
bool AI::run() { realLight=(playerID())?player1Light():player0Light(); cout<<"Turn: "<<turnNumber()<<" Player: "<<playerID()<<" Light: "<<realLight<<endl; cout<<"Plants: "<<plants.size()<<endl; if(plants.size()<2) { return true; } //if the queue is empty if(que.empty()) { // cout<<"First time on this turn"<<endl; resetDataStructures(); buildQueue(); } //cout<<"Queue Size: "<<que.size()<<endl; //runs once return doActions(); /* while(!que.empty()) { que.pop(); } return true; */ //otherwise //return doActions(); /* while(!doActions()){}; return true; */ }
//This function is called each time it is your turn. //Return true to end your turn, return false to ask the server for updated information. bool AI::run() { cout << turnNumber() << ": START TURN" << endl; update(); detType(); for(int i = 0; i < myCreatures.size(); i++) { //HERBIVORE if( myCreatures[i].type.compare("herbivore") == 0 ) herbact(i); //CARNIVORE else if( myCreatures[i].type.compare("carnivore") == 0 ) carnact(i); //OMNIVORE else omniact(i); } cout << turnNumber() << ": END TURN" << endl; return true; }
GameContextData GameCycle::gameContextData() const { GameContextData res; res.currentPlayerId = currentPlayer()->id(); res.requestedPlayerId = requestedPlayer()->id(); res.turnNumber = turnNumber(); res.gamePlayState = gamePlayState(); if (gamePlayState() == GAMEPLAYSTATE_RESPONSE) { res.reactionType = reactionHandler()->reactionType(); Player* causedBy = reactionHandler()->causedBy(); res.causedBy = causedBy ? causedBy->id() : 0; } else { res.reactionType = REACTION_NONE; res.causedBy = 0; } return res; }
//This function is called each time it is your turn. //Return true to end your turn, return false to ask the server for updated information. bool AI::run() { cout<<"Turn: "<<turnNumber()<<endl; vector<int> builders, uncombined, actors; for(unsigned int b=0;b<bots.size();b++) { // if it is my bot if(bots[b].owner()==playerID() && bots[b].partOf()==0) { bots[b].talk( "Hi there, I'm you're robot" ); if(bots[b].buildRate()>0 && builders.size()<4 && bots[b].size()==1) { builders.push_back(b); } else if(bots[b].size()==1) { uncombined.push_back(b); } else { actors.push_back(b); } } } // starting builders if(builders.size()<4) { for(unsigned int b=0;b<builders.size();b++) { int x=bots[builders[b]].x()+xMod[playerID()*2 +1]; int y=bots[builders[b]].y()+yMod[playerID()*2 +1]; bots[builders[b]].build(types[1], x, y, 1); } } // if there are 4 builders if(builders.size()==4) { // check if the builders are in their correct locations for(unsigned int b=0;b<builders.size();b++) { int dir=1; if(bots[builders[b]].y()==9) { bots[builders[b]].move("up"); } else if(bots[builders[b]].y()==10) { bots[builders[b]].move("down"); } if(bots[builders[b]].y()==8) { dir = 2; } else if(bots[builders[b]].y()==11) { dir = 0; } int x=bots[builders[b]].x()+xMod[dir]; int y=bots[builders[b]].y()+yMod[dir]; if(bots[builders[b]].actions()>0) { // builds 4 different guys bots[builders[b]].build(types[(built/4+b)%types.size()], x, y, 1); built++; } } } if(uncombined.size()==4) { /* for(unsigned int b=0;b<uncombined.size();b++) { if(bots[uncombined[b]].y()==9) { bots[uncombined[b]].move("down"); } else if(bots[builders[b]].y()==10) { bots[builders[b]].move("down"); } } */ bots[uncombined[0]].combine(bots[uncombined[1]],bots[uncombined[2]],bots[uncombined[3]]); } // Handles all of the non builders for(unsigned int b=0;b<actors.size();b++) { Unit* target = findNearestTarget(bots[actors[b]]); moveTowardsTarget(bots[actors[b]], *target); if(inRange(bots[actors[b]], *target)) { cout<<"In RANGE!"<<endl; unload(bots[actors[b]],*target); } } return true; }
//This function is called each time it is your turn. //Return true to end your turn, return false to ask the server for updated information. bool AI::run() { cout<<"Starting turn: "<<turnNumber()<<endl; objectCheck(); return true; }
//This function is called each time it is your turn. //Return true to end your turn, return false to ask the server for updated information. bool AI::run() { cout << "Turn " << turnNumber() << endl; // Future: tell the map to update itself (saving history) _map = Map(this); // Update convenience data structures. myBases.erase(myBases.begin(),myBases.end()); for (vector<Base>::iterator base = bases.begin(); base != bases.end(); base++) { if ((*base).owner() == playerID()) myBases.push_back(*base); } myViruses.erase(myViruses.begin(),myViruses.end()); for (vector<Virus>::iterator virus = viruses.begin(); virus != viruses.end(); virus++) { if ((*virus).owner() == playerID()) myViruses.push_back(*virus); } if (_config[string("preset")].compare(string("Coverage"))) { players[playerID()].talk((char*)"The General: 0.52 (Coverage)"); } else { players[playerID()].talk((char*)"The General: 0.52 (2xLem,1Rand)"); } // Let the General command the army. Commander_Washington.Command(); // The Old Way // // virus coverage strategy // build_shells(this,map); // // fewest spawns // distribute_base_spawning(this,map); // // loop through all of the bases // for(int i=0;i<bases.size();i++) // { // // check if you own that base // if(bases[i].owner() == playerID()) // { // // check to see if you have enough cycles to spawn a level 0 virus // if(baseCost() <= players[playerID()].cycles()) // { // // spawn a level 0 virus at that base // bases[i].spawn(0); // } // } // } // // loop through all of the viruses // for(int i=0;i<viruses.size();i++) // { // // if you own that virus // if(viruses[i].owner() == playerID()) // { // // if the tile you want to move to is NOT a wall // if(getTileAtLocation(viruses[i].x()+1, viruses[i].y()).owner() != 3) // { // // move the virus // viruses[i].move(viruses[i].x()+1, viruses[i].y()); // } // } // } // End your turn return true; }
//TODO Test if you can build something and act on it in one turn void AI::buildQueue() { for(unsigned int i=0;i<plants.size();i++) { //cout<<"Working on plant: "<<i<<endl; //cout<<"HP: "<<plants[i].health()<<endl; //if its my plant and it can do something if(plants[i].ownerID() == playerID() && plants[i].canAct()) { //Spam talk string message="This is plant[" + plants[i].objectID(); message+="] owned by Player: "+plants[i].ownerID(); message+=" on turn "+turnNumber(); //char * temp = message.c_str(); plants[i].talk((char*)(message.c_str())); if(i==0) { plants[i].talk((char*)("Did calling talk twice append or replace the usual string?")); } //if you don't have a leaf if(!plants[i].leaf()) { if(canDo(i,LEAF)) { //a place to try growing a leaf space sp(plants[i].x(), plants[i].y(),i,LEAF); sp.rating=evalTree(leafTree,sp); que.push(sp); } /* else { space sp(plants[i].x(), plants[i].y(),i,LEAF); cout<<"CANT DO: "; sp.display(); } */ } //if you want to generate light else { //cout<<"Pushing NOOP"<<endl; space sp(plants[i].x(), plants[i].y(),i,NOOP); sp.rating=evalTree(noopTree,sp); //que.push(sp); } //if it doesn't have a root if(!plants[i].root()) { //I can do a root if(canDo(i,ROOT)) { //a place to try growing a root space sp(plants[i].x(), plants[i].y(),i,ROOT); sp.rating=evalTree(rootTree,sp); que.push(sp); } /* else { space sp(plants[i].x(), plants[i].y(),i,ROOT); cout<<"CANT DO: "; sp.display(); } */ } //for expansion else { if(canDo(i,SPREAD)) { for(unsigned int r=0;r<4;r++) { space sp(plants[i].x()+xoff[r], plants[i].y()+yoff[r],i,SPREAD); if(canSpawnHere[sp.x+1][sp.y+1]) { sp.rating=evalTree(rootTree,sp); que.push(sp); } } } } //if it doesn't have a flower and can make one if(!plants[i].flower()) { if(canDo(i,FLOWER)) { //a place to try growing a flower space sp(plants[i].x(), plants[i].y(),i,FLOWER); sp.rating=evalTree(flowerTree,sp); que.push(sp); } } //if you have a flower and can spawn else { if(canDo(i,SPAWN)) { for(unsigned int r=0;r<4;r++) { space sp(plants[i].x()+xoff[r], plants[i].y()+yoff[r],i,SPAWN); if(canSpawnHere[sp.x+1][sp.y+1]) { sp.rating=evalTree(spawnTree,sp); que.push(sp); } } } } } } // //cout<<"Bot of Build QUE"<<endl; }