-
Notifications
You must be signed in to change notification settings - Fork 1
/
move.h
114 lines (102 loc) · 3.41 KB
/
move.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
doko is a C++ doppelkopf program with an integrated UCT player.
Copyright (c) 2011-2016 Silvan Sievers
For questions, please write to: [email protected]
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MOVE_H
#define MOVE_H
#include "cards.h"
#include <cassert>
#include <iostream>
#include <fstream>
#include <vector>
enum question_t {
IMMEDIATE_SOLO,
HAS_RESERVATION,
IS_SOLO
};
class GameType;
class Move {
private:
enum move_t {
QUESTION,
GAME_TYPE,
ANNOUNCEMENT,
CARD
};
move_t type;
question_t question_type;
bool answer_re; // being used to store the answer for a question or if announcing player belongs to re team or not
const GameType *game_type;
announcement_t announcement;
Card card;
void print_type(std::ostream &out) const;
public:
Move() {} // introduced for UctPlayer
Move(question_t question_type, bool answer);
explicit Move(const GameType *game_type);
Move(announcement_t announcement, bool re_team);
explicit Move(Card card);
bool is_question_move() const {
return type == QUESTION;
}
question_t get_question_type() const {
assert(is_question_move());
return question_type;
}
bool get_answer() const {
return answer_re;
}
bool is_game_type_move() const {
return type == GAME_TYPE;
}
const GameType *get_game_type() const {
assert(is_game_type_move());
return game_type;
}
bool is_announcement_move() const {
return type == ANNOUNCEMENT;
}
announcement_t get_announcement() const {
assert(is_announcement_move());
return announcement;
}
bool get_re_team() const {
return answer_re;
}
bool is_card_move() const {
return type == CARD;
}
Card get_card() const {
assert(is_card_move());
return card;
}
bool operator==(const Move &rhs) const { // TODO: this is only for debugging (assertion in uct_player.cpp)
if (type != rhs.type)
return false;
if (type == QUESTION)
return (question_type == rhs.question_type && answer_re == rhs.answer_re);
else if (type == GAME_TYPE)
return game_type == rhs.game_type; // NOTE: comparing the pointers actually is enough because they all point to the same global const objects defined in game_type.h
else if (type == ANNOUNCEMENT)
return announcement == rhs.announcement;
else if (type == CARD)
return card == rhs.card;
else
return false;
}
void print_option(std::ostream &out = std::cout) const; // public for human_player
friend std::ostream &operator<<(std::ostream &out, const Move &move);
friend std::ostream &operator<<(std::ostream &out, const std::vector<Move> &moves);
};
#endif