forked from SharifAIChallenge/AIC16-Client-Cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAI.cpp
More file actions
24 lines (22 loc) · 651 Bytes
/
AI.cpp
File metadata and controls
24 lines (22 loc) · 651 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include "AI.h"
#include <vector>
#include <cstdlib>
#include <iostream>
void AI::doTurn(World *world)
{
/** Fill this method. We've presented a stupid AI as an example! **/
srand(time(NULL));
std::vector<Node*>& myNodes = world->getMyNodes();
for(auto& source : myNodes)
{
/** Get neighbours **/
const std::vector<Node*>& neighbours = source->getNeighbours();
if (neighbours.size() > 0)
{
/** Select a random neighbour **/
Node *destination = neighbours[(int)(rand() % neighbours.size())];
/** Move half of the nodes army to the neighbour node **/
world->moveArmy(source, destination, source->getArmyCount() / 2);
}
}
}