-
Notifications
You must be signed in to change notification settings - Fork 0
/
turnbased_ai.h
74 lines (54 loc) · 1.56 KB
/
turnbased_ai.h
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#ifndef TURNBASED_AI_H
#define TURNBASED_AI_H
#include <vector>
#include "realtime_ai.h"
namespace koala { namespace chillin { namespace client {
// definition
template <class T>
class TurnbasedAI : public RealtimeAI<T>
{
public:
TurnbasedAI(T world);
~TurnbasedAI();
virtual void update(const ks::messages::BaseSnapshot *snapshot);
virtual bool allowedToDecide() const;
protected:
virtual void sendCommandInternal(const ks::KSObject *command, ks::messages::BaseCommand *msg = 0);
protected:
std::vector<std::string> turnAllowedSides;
};
// implementation
template <class T>
TurnbasedAI<T>::TurnbasedAI(T world):
RealtimeAI<T>(world)
{
}
template <class T>
TurnbasedAI<T>::~TurnbasedAI()
{
}
template <class T>
void TurnbasedAI<T>::update(const ks::messages::BaseSnapshot *snapshot)
{
RealtimeAI<T>::update(snapshot);
ks::messages::TurnbasedSnapshot *x = (ks::messages::TurnbasedSnapshot*) snapshot;
turnAllowedSides = x->turn_allowed_sides();
}
template <class T>
bool TurnbasedAI<T>::allowedToDecide() const
{
return std::find(turnAllowedSides.begin(), turnAllowedSides.end(), this->mySide)
!= turnAllowedSides.end();
}
template <class T>
void TurnbasedAI<T>::sendCommandInternal(const ks::KSObject *command, ks::messages::BaseCommand *msg)
{
ks::messages::TurnbasedCommand *message;
if (msg == 0)
message = new ks::messages::TurnbasedCommand();
else
message = (ks::messages::TurnbasedCommand*) msg;
RealtimeAI<T>::sendCommandInternal(command, message);
}
}}}
#endif // TURNBASED_AI_H