-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAIPlayer.cpp
53 lines (44 loc) · 1.15 KB
/
AIPlayer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "AIPlayer.h"
#include "HFL/Source/HFL.h"
#include "OP2Helper/OP2Helper.h"
#include "Outpost2DLL/Outpost2DLL.h"
#include <vector>
#include <stdexcept>
#include <algorithm>
int HumanPlayerCount()
{
return TethysGame::NoPlayers() - 1;
}
// AI player is last player
PlayerNum GetAIIndex()
{
for (int i = 0; i < 7; ++i)
{
if (!Player[i].IsHuman()) {
return static_cast<PlayerNum>(i);
}
}
throw std::runtime_error("No AI player detected");
}
//Note: Scenario must have 5 or fewer human players to work.
PlayerColor GetAIColor(bool allowBlack)
{
int totalColors = 6;
if (allowBlack) {
totalColors++;
}
std::vector<int> availableColors;
for (int i = 0; i < totalColors; ++i) {
availableColors.push_back(i);
}
for (int i = 0; i < TethysGame::NoPlayers() - 1; ++i)
{
availableColors.erase(
std::remove(availableColors.begin(), availableColors.end(), ExtPlayer[i].GetColorNumber()), availableColors.end());
}
if (availableColors.size() == 0) {
return PlayerColor::PlayerBlue;
}
const int colorIndex = TethysGame::GetRand(availableColors.size());
return static_cast<PlayerColor>(availableColors[colorIndex]);
}