-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOmokBitBoard.cpp
More file actions
81 lines (74 loc) · 2.02 KB
/
OmokBitBoard.cpp
File metadata and controls
81 lines (74 loc) · 2.02 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
#include <iostream>
#include "OmokBitBoard.h"
OmokBitBoard::OmokBitBoard() {
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);
}
}
}
OmokBitBoard::OmokBitBoard(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 OmokBitBoard::increment(bool player) {
if (player) {
++white_stones;
} else {
++black_stones;
}
}
int OmokBitBoard::stones_of(bool player) {
if (player) {
return white_stones;
} else {
return black_stones;
}
}
void OmokBitBoard::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>> OmokBitBoard::get_bitboard(bool player) {
if (player) {
return board_white;
} else {
return board_black;
}
}
void OmokBitBoard::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;
}
}