Newer
Older
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
#include "morpion.hpp"
#include <sstream>
using namespace std;
namespace game
{
static vector<vector<uint64_t>> create_hash_values()
{
default_random_engine generator;
uniform_int_distribution<uint64_t> distribution;
vector<vector<uint64_t>> res(7, vector<uint64_t>(6, 0));
for (int i = 0; i < 7; ++i)
{
for (int j = 0; j < 6; ++j)
{
res[i][j] = distribution(generator);
}
}
return res;
}
vector<vector<uint64_t>> morpion::cross_hash_values = create_hash_values();
vector<vector<uint64_t>> morpion::circle_hash_values = create_hash_values();
morpion::morpion()
{
}
shared_ptr<game<morpion_state>> morpion::do_copy() const
{
return shared_ptr<morpion>(new morpion(*this));
}
morpion_state morpion::get_state()
{
return state;
}
void morpion::set_state(const morpion_state& s)
{
state = s;
}
bool morpion::end_of_game() const
{
return state.first_player_win || state.second_player_win || state.total_moves == 9;
}
bool morpion::won(std::uint8_t player) const
{
//TODO: Implement
return false;
}
bool morpion::lost(std::uint8_t player) const
{
//TODO: Implement
return false;
}
bool morpion::draw(std::uint8_t player) const
{
//TODO: Implement
return false;
}
uint8_t morpion::current_player() const
{
return state.total_moves & 1 ? CIRCLE : CROSS; // CROSS even, CIRCLE odd
}
int morpion::value(uint8_t player) const
{
//TODO: Implement
return 0;
}
uint16_t morpion::number_of_moves() const
{
}
bool morpion::get(uint64_t bitboard, uint8_t col, uint8_t row) const
{
//TODO: Implement
return false;
}
//#define set(bitboard, col, row) (bitboard |= (1LL << (((col) << 3) + (row))))
void morpion::update_win()
{
if(has_won(state.cross_bitboard))
state.first_player_win = true;
else if(has_won(state.circle_bitboard))
state.second_player_win = true;
if(bitboard == ROW1_MASK || bitboard == ROW2_MASK || bitboard == ROW3_MASK) // Check vertical |
return true;
if(bitboard == COL1_MASK || bitboard == COL2_MASK || bitboard == COL3_MASK) // Check horizontal _
return true;
if(bitboard == DIA1_MASK || bitboard == DIA2_MASK) // Chack diagonal \ /
return true;
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
return false;
}
void morpion::update_moves(uint16_t move)
{
//TODO: Implement
}
void morpion::play(uint16_t m)
{
//TODO: Implement
}
string morpion::player_to_string(uint8_t player) const
{
//TODO: Implement
return "TODO";
}
string morpion::move_to_string(uint16_t m) const
{
//TODO: Implement
return "TODO";
}
set<int> morpion::to_input_vector() const
{
return set<int>();
}
void morpion::from_input_vector(const std::set<int>& input)
{
}
string morpion::to_string() const
{
//TODO: Implement
return "TODO";
}
void morpion::playout(mt19937& engine, int max_depth)
{
while (!end_of_game())
{
uniform_int_distribution<uint16_t> distribution(0, number_of_moves() - 1);
uint16_t move = distribution(engine);
play(move);
}
}
std::uint64_t morpion::hash() const
{
//TODO: Implement
return 0;
}
std::uint64_t morpion::hash(std::uint16_t m) const
{
//TODO: Implement
return 0;
}
ostream& operator<<(ostream& os, const morpion& mor)
{
os << mor.to_string() << endl;
return os;
}
}