-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gomoku.cpp
88 lines (74 loc) · 1.93 KB
/
Gomoku.cpp
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
#include "Gomoku.hpp"
#include "Graphic.hpp"
Gomoku::Gomoku() {
for (int cptX = 0; cptX != 19; cptX++) {
for (int cptY = 0; cptY != 19; cptY++) {
_map[cptX][cptY] = 0;
}
}
}
void Gomoku::createMap() {
this->setWinner(0);
for (int cptX = 0; cptX != 19; cptX++) {
for (int cptY = 0; cptY != 19; cptY++) {
_map[cptX][cptY] = 1;
}
}
}
Gomoku::~Gomoku() {
}
void Gomoku::updateMapRule(const int& coord) {
_playedX = coord % 19;
_playedY = coord / 19;
for (int cptY = 0; cptY != 19; cptY++) {
for (int cptX = 0; cptX != 19; cptX++) {
_mapRule[cptY][cptX] = _map[cptY][cptX];
}
}
}
int Gomoku::createPlayer(const int& choice) {
if (choice == -1)
return -1;
if (choice == 1) {
_playerOne = new Player(HUMAN, TEAM_1, -1);
_playerTwo = new Player(HUMAN, TEAM_2, -1);
}
else if (choice == 2) {
_playerOne = new Player(HUMAN, TEAM_1, -1);
_playerTwo = new Player(IA, TEAM_2, 0);
}
else {
_playerOne = new Player(HUMAN, TEAM_1, -1);
_playerTwo = new Player(IA, TEAM_2, 1);
}
return choice;
}
int Gomoku::getNbPion() const {
int nbPion = 0;
for (int i = 0; i != 19; i++) {
for (int j = 0; j != 19; j++) {
if (_map[i][j] != FREE)
nbPion++;
}
}
return nbPion;
}
void Gomoku::copyMapRule() {
for (int cptY = 0; cptY != 19; cptY++) {
for (int cptX = 0; cptX != 19; cptX++) {
_map[cptY][cptX] = _mapRule[cptY][cptX];
}
}
}
int Gomoku::launchJudge(const t_flag& team) {
int ret;
this->_playedXRules = _playedX;
this->_playedYRules = _playedY;
if (team == TEAM_1)
ret = this->checkRules(team, *_playerOne);
else
ret = this->checkRules(team, *_playerTwo);
if (ret == -1)
copyMapRule();
return ret;
}