-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmove.cpp
More file actions
127 lines (112 loc) · 3.52 KB
/
move.cpp
File metadata and controls
127 lines (112 loc) · 3.52 KB
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
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
doko is a C++ doppelkopf program with an integrated UCT player.
Copyright (c) 2011-2016 Silvan Sievers
For questions, please write to: silvan.sievers@unibas.ch
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/>.
*/
#include "move.h"
#include "game_type.h"
#include <cassert>
#include <iostream>
using namespace std;
Move::Move(question_t question_type_, bool answer) : type(QUESTION), question_type(question_type_), answer_re(answer) {
}
Move::Move(const GameType *game_type_) : type(GAME_TYPE), game_type(game_type_) {
}
Move::Move(announcement_t announcement_, bool re_team) : type(ANNOUNCEMENT), answer_re(re_team), announcement(announcement_) {
}
Move::Move(Card card_) : type(CARD), card(card_) {
}
void Move::print_type(ostream &out) const {
out << "move type: ";
switch (type) {
case QUESTION:
switch (question_type) {
case IMMEDIATE_SOLO:
out << "immediate solo: ";
break;
case HAS_RESERVATION:
out << "has reservation: ";
break;
case IS_SOLO:
out << "is solo: ";
break;
}
break;
case GAME_TYPE:
out << "game type: ";
break;
case ANNOUNCEMENT:
out << "announcement: ";
break;
case CARD:
out << "card: ";
break;
}
}
void Move::print_option(ostream &out) const {
switch (type) {
case QUESTION:
out << (answer_re ? "yes" : "no");
break;
case GAME_TYPE:
out << *game_type;
break;
case ANNOUNCEMENT:
switch (announcement) {
case NONE:
out << "no announcement";
break;
case REKON:
out << "re/kontra";
break;
case N90:
out << "no 90";
break;
case N60:
out << "no 60";
break;
case N30:
out << "no 30";
break;
case SCHWARZ:
out << "black";
break;
}
break;
case CARD:
assert(false);
break;
}
}
ostream &operator<<(ostream &out, const Move &move) {
move.print_type(out);
if (move.is_card_move())
out << move.get_card();
else
move.print_option(out);
return out;
}
ostream &operator<<(ostream &out, const vector<Move> &moves) {
moves[0].print_type(out);
out << endl;
out << "move options: ";
for (size_t i = 0; i < moves.size(); ++i) {
if (moves[i].is_card_move())
out << moves[i].get_card();
else
moves[i].print_option(out);
if (i != moves.size() - 1)
out << ", ";
}
return out;
}