-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOmok.cpp
More file actions
130 lines (117 loc) · 3.08 KB
/
Omok.cpp
File metadata and controls
130 lines (117 loc) · 3.08 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
128
129
130
#include "Omok.h"
#include "consts.h"
#include <iomanip>
Omok::Omok() {
for (int i = 0; i < DIM; ++i) {
this->board.push_back({});
for (int k = 0; k < DIM; ++k) {
this->board[i].push_back(UNDEF);
}
}
}
Omok::Omok(std::vector<std::vector<int>> existing_board) {
for (int i = 0; i < DIM; ++i) {
this->board.push_back({});
for (int k = 0; k < DIM; ++k) {
this->board[i].push_back(existing_board[i][k]);
}
}
}
void Omok::place(int player, int row, int col) {
this->board[row][col] = player;
}
void Omok::place(OmokMove move) {
this->place(move.player, move.row, move.col);
}
void Omok::print_board() {
for (auto row : this->board) {
for (auto cell : row) {
if (cell == UNDEF) {
std::cout << ". ";
} else if (cell == MAX) {
std::cout << "X ";
} else if (cell == MIN) {
std::cout << "O ";
} else {
std::cout << "# ";
}
}
std::cout << std::endl;
}
std::cout << std::endl;
}
std::vector<std::vector<int>> Omok::get_board() {
return board;
}
Omok::Omok(int flag) {
for (int i = 0; i < DIM; ++i) {
board_black.push_back({});
board_white.push_back({});
for (int k = 0; k < DIM; ++k) {
board_black[i].push_back(false);
board_white[i].push_back(false);
}
}
}
Omok::Omok(std::vector<std::vector<bool>> black, std::vector<std::vector<bool>> white) {
for (int i = 0; i < DIM; ++i) {
board_black.push_back({});
board_white.push_back({});
for (int k = 0; k < DIM; ++k) {
board_black[i].push_back(black[i][k]);
board_white[i].push_back(white[i][k]);
}
}
}
void Omok::increment(bool player) {
if (player) {
++white_stones;
} else {
++black_stones;
}
}
int Omok::stones_of(bool player) {
if (player) {
return white_stones;
} else {
return black_stones;
}
}
void Omok::place_bitboard(bool player, int row, int col) {
if (board_black[row][col] || board_white[row][col]) {
std::cerr << "There is already a stone at " << row << ", " << col << "!" << std::endl;
return;
}
if (player) {
board_white[row][col] = true;
} else {
board_black[row][col] = true;
}
}
std::vector<std::vector<bool>> Omok::get_bitboard(bool player) {
if (player) {
return board_white;
} else {
return board_black;
}
}
void Omok::print_bitboard(bool player) {
for (int i = 0; i < DIM; ++i) {
for (int k = 0; k < DIM; ++k) {
if (player) {
if (board_white[i][k]) {
std::cout << "O ";
} else {
std::cout << ". ";
}
} else {
if (board_black[i][k]) {
std::cout << "X ";
} else {
std::cout << ". ";
}
}
}
std::cout << std::endl;
}
}