-
Notifications
You must be signed in to change notification settings - Fork 1
/
Chess.cpp
179 lines (165 loc) · 6.02 KB
/
Chess.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
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
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
176
177
178
179
#include "Chess.h"
namespace ChessTable {
enum CHESS_TABLE {
BLACK_GENERAL = 1,
BLACK_ADVISOR,
BLACK_ELEPHANT,
BLACK_HORSE,
BLACK_CHARIOT,
BLACK_CANNON,
BLACK_SOLDIER,
RED_GENERAL,
RED_ADVISOR,
RED_ELEPHANT,
RED_HORSE,
RED_CHARIOT,
RED_CANNON,
RED_SOLDIER,
};
std::unordered_map<int, QString> Chess_Int2Qstr_simple {
{1, "b_gen_"},
{2, "b_adv_"},
{3, "b_ele_"},
{4, "b_hor_"},
{5, "b_cha_"},
{6, "b_can_"},
{7, "b_sol_"},
{8, "r_gen_"},
{9, "r_adv_"},
{10, "r_ele_"},
{11, "r_hor_"},
{12, "r_cha_"},
{13, "r_can_"},
{14, "r_sol_"},
};
}
Chess::Chess(int x, int y, QString name, bool camp, int number, bool isAlive):
SGeoPoint(x, y), _name(name), _redOrBlack(camp), _number(number), _isAlive(isAlive)
{
// StepList.clear(); // make it empty
// StepKillList.clear();
chessStepList.clear(); // make it empty
SchessStepList.clear();
_spaceValue = 0;
}
bool Chess::isAlive() {
return _isAlive;
}
void Chess::setAlive(bool isAliveNow) {
_isAlive = isAliveNow;
}
bool Chess::canKill() {
return _canKill;
}
bool Chess::canMove() {
return _canMove;
}
bool Chess::chessCamp() {
// false is black
// true is red
return _redOrBlack;
}
QString Chess::chessName() {
return _name;
}
int Chess::chessNumber() {
return _number;
}
void Chess::setSpaceValue(double value) {
_spaceValue = value;
}
double Chess::getSpaceValue() {
return _spaceValue;
}
void Chess::tranStarStepList() {
const int countStep = chessStepList.size();
SchessStepList.clear(); // init
if(countStep == 0) {
// qDebug() << "Chess.cpp tranStarStepList() line:89 error:chessStepList is EMPTY!!! " << chessName() << " " << chessNumber();
return;
}
// print every element of the list
for(int i = 0; i < countStep; i++) {
int Num = chessStepList.at(i)._chessNum;
int Number = chessStepList.at(i)._chessNumber;
int PosX = chessStepList.at(i)._deltaX;
int PosY = chessStepList.at(i)._deltaY;
bool kill = chessStepList.at(i)._isKill;
QString killString = kill ? "True" : "False";
int killNum = chessStepList.at(i)._chessKilledNum;
int killNumber = chessStepList.at(i)._chessKilledNumber;
if(kill == false && (killNum != -1 || killNumber != -1)) {
qDebug() << "Chess.cpp tranStarStepList() line:104 error:Kill is false but killNum or killNumber is not -1 !!!";
return;
}
if(chessStepList.at(i)._chessCamp != chessCamp()){
qDebug() << "Chess.cpp tranStarStepList() line:108 error:chessStepList.at(i)._chessCamp != chessCamp() !!!";
return;
}
chessStep* curStep = new chessStep(Num, Number, chessStepList.at(i)._chessCamp, PosX, PosY, kill, killNum, killNumber);
SchessStepList.append(curStep);
// delete curStep;
}
// chessStepList.clear();
}
void Chess::printStepList() {
const int countStep = chessStepList.size();
if(countStep == 0) {
qDebug() << "Chess.cpp printStepList() line:50 error:chessStepList is EMPTY!!!";
return;
}
// print every element of the list
for(int i = 0; i < countStep; i++) {
std::cout << "=================== <" << i << "> ===================" << std::endl;
int Num = chessStepList.at(i)._chessNum;
int Number = chessStepList.at(i)._chessNumber;
int PosX = chessStepList.at(i)._deltaX;
int PosY = chessStepList.at(i)._deltaY;
bool kill = chessStepList.at(i)._isKill;
QString killString = kill ? "True" : "False";
int killNum = chessStepList.at(i)._chessKilledNum;
int killNumber = chessStepList.at(i)._chessKilledNumber;
std::cout << "Num\t = " << Num << std::endl;
std::cout << "Number\t = " << Number << std::endl;
std::cout << "Name\t = " << ChessTable::Chess_Int2Qstr_simple[Num].toStdString() << std::endl;
std::cout << "PosX\t = " << PosX << std::endl;
std::cout << "PosY\t = " << PosY << std::endl;
std::cout << "kill\t = " << killString.toStdString() << std::endl;
if(kill) {
std::cout << "k_Num\t = " << killNum << std::endl;
std::cout << "k_Number\t = " << killNumber << std::endl;
std::cout << "k_Name\t = " << ChessTable::Chess_Int2Qstr_simple[killNum].toStdString() << std::endl;
}
}
}
void Chess::SprintStepList() {
// tranStarStepList();
const int countStep = SchessStepList.size();
if(countStep == 0) {
qDebug() << "Chess.cpp SprintStepList() line:120 error:SchessStepList is EMPTY!!!";
return;
}
// print every element of the list
for(int i = 0; i < countStep; i++) {
std::cout << "=================== <" << i << "> ===================" << std::endl;
int Num = SchessStepList.at(i)->_chessNum;
int Number = SchessStepList.at(i)->_chessNumber;
int PosX = SchessStepList.at(i)->_deltaX;
int PosY = SchessStepList.at(i)->_deltaY;
bool kill = SchessStepList.at(i)->_isKill;
QString killString = kill ? "True" : "False";
int killNum = SchessStepList.at(i)->_chessKilledNum;
int killNumber = SchessStepList.at(i)->_chessKilledNumber;
std::cout << "Num\t = " << Num << std::endl;
std::cout << "Number\t = " << Number << std::endl;
std::cout << "Name\t = " << ChessTable::Chess_Int2Qstr_simple[Num].toStdString() << std::endl;
std::cout << "PosX\t = " << PosX << std::endl;
std::cout << "PosY\t = " << PosY << std::endl;
std::cout << "kill\t = " << killString.toStdString() << std::endl;
if(kill) {
std::cout << "k_Num\t = " << killNum << std::endl;
std::cout << "k_Number\t = " << killNumber << std::endl;
std::cout << "k_Name\t = " << ChessTable::Chess_Int2Qstr_simple[killNum].toStdString() << std::endl;
}
}
}