-
Notifications
You must be signed in to change notification settings - Fork 6
/
HolmesBot.h
93 lines (74 loc) · 3.3 KB
/
HolmesBot.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include "Hanabi.h"
class HolmesBot;
class CardKnowledge {
public:
CardKnowledge();
bool mustBe(Hanabi::Color color) const;
bool mustBe(Hanabi::Value value) const;
bool cannotBe(Hanabi::Card card) const;
bool cannotBe(Hanabi::Color color) const;
bool cannotBe(Hanabi::Value value) const;
int color() const;
int value() const;
void setMustBe(Hanabi::Color color);
void setMustBe(Hanabi::Value value);
void setCannotBe(Hanabi::Color color);
void setCannotBe(Hanabi::Value value);
void update(const Hanabi::Server &server, const HolmesBot &bot);
bool isPlayable;
bool isValuable;
bool isWorthless;
private:
bool cantBe_[Hanabi::NUMCOLORS][5+1];
int color_;
int value_;
};
struct Hint {
int information_content;
int to;
int color;
int value;
Hint();
void give(Hanabi::Server &);
};
class HolmesBot final : public Hanabi::Bot {
friend class CardKnowledge;
int me_;
int myHandSize_; /* purely for convenience */
/* What does each player know about his own hand? */
std::vector<std::vector<CardKnowledge> > handKnowledge_;
/* What cards have been played so far? */
int playedCount_[Hanabi::NUMCOLORS][5+1];
/* What cards in players' hands are definitely identified?
* This table is recomputed every turn. */
int locatedCount_[Hanabi::NUMCOLORS][5+1];
/* What is the lowest-value card currently playable?
* This value is recomputed every turn. */
int lowestPlayableValue_;
bool isValuable(const Hanabi::Server &server, Hanabi::Card card) const;
bool couldBeValuable(const Hanabi::Server &server, const CardKnowledge &knol, int value) const;
bool updateLocatedCount(const Hanabi::Server& server);
void invalidateKnol(int player_index, int card_index);
void seePublicCard(const Hanabi::Card &played_card);
void wipeOutPlayables(const Hanabi::Card &played_card);
/* Returns -1 if the named player is planning to play a card on his
* turn, or if all his cards are known to be valuable. Otherwise,
* returns the index of his oldest not-known-valuable card. */
int nextDiscardIndex(const Hanabi::Server& server, int player) const;
Hint bestHintForPlayer(const Hanabi::Server &server, int to) const;
bool maybePlayLowestPlayableCard(Hanabi::Server &server);
bool maybeGiveHelpfulHint(Hanabi::Server &server);
bool maybeGiveValuableWarning(Hanabi::Server &server);
bool maybePlayMysteryCard(Hanabi::Server &server);
bool maybeDiscardWorthlessCard(Hanabi::Server &server);
bool maybeDiscardOldCard(Hanabi::Server &server);
public:
HolmesBot(int index, int numPlayers, int handSize);
void pleaseObserveBeforeMove(const Hanabi::Server &) override;
void pleaseMakeMove(Hanabi::Server &) override;
void pleaseObserveBeforeDiscard(const Hanabi::Server &, int from, int card_index) override;
void pleaseObserveBeforePlay(const Hanabi::Server &, int from, int card_index) override;
void pleaseObserveColorHint(const Hanabi::Server &, int from, int to, Hanabi::Color color, Hanabi::CardIndices card_indices) override;
void pleaseObserveValueHint(const Hanabi::Server &, int from, int to, Hanabi::Value value, Hanabi::CardIndices card_indices) override;
void pleaseObserveAfterMove(const Hanabi::Server &) override;
};