-
Notifications
You must be signed in to change notification settings - Fork 1
/
Chess.h
167 lines (149 loc) · 6.37 KB
/
Chess.h
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
#pragma once
#ifndef CHESS_H
#define CHESS_H
#include "define.h"
#include <vector>
using namespace std;
class Chess //记录棋子在棋盘上的坐标;根据形势给出所有合法走子;检验所给走子方法的合法性
{
public:
bool exist;//棋子是否存在棋盘上
CHESSPOS pos;//棋子在棋盘上的位置
public:
Chess(CHESSPOS pos, bool exist = true):pos(pos),exist(exist) {}
void setPos(CHESSPOS & pos){this->pos = pos;}//设置棋子在棋盘上的位置
void setExist(){this->exist = true;}//可以直接访问成员或者调用
void disExist(){this->exist = false;}//可以直接访问成员或者调用
virtual ~Chess() {}
virtual bool moveValid(CHESSPOS &tar, char board[10][9]) = 0; //确定目标移动位置合法性:针对棋子特定的移动规则
virtual void generateMovement(vector<MOVEMENT> &moveList, char board[10][9]) = 0; //生成所有的合法的走子位置
virtual void genMovePos(CHESSPOS srcPos, vector<CHESSPOS> &tarPos, char board[10][9]) = 0; //根据起始点生成合法目标位置
};
extern Chess * chess[32];//定义在game.cpp中的全局变量
class R_King : public Chess //红帅
{
public:
R_King(CHESSPOS pos):Chess(pos) {}
~R_King() {}
bool moveValid(CHESSPOS &tar, char board[10][9]); //重定义父类函数
void generateMovement(vector<MOVEMENT> &moveList, char board[10][9]); //重定义父类函数
void genMovePos(CHESSPOS srcPos, vector<CHESSPOS> &tar_pos, char board[10][9]); //重定义父类函数
};
class B_King : public Chess //黑帅
{
public:
B_King(CHESSPOS pos):Chess(pos){}
~B_King() {}
bool moveValid(CHESSPOS &tar, char board[10][9]); //重定义父类函数
void generateMovement(vector<MOVEMENT> &moveList, char board[10][9]); //重定义父类函数
void genMovePos(CHESSPOS srcPos, vector<CHESSPOS> &tarPos, char board[10][9]); //重定义父类函数
};
class R_Guard : public Chess //红士
{
public:
R_Guard(CHESSPOS pos):Chess(pos) {}
~R_Guard() {}
bool moveValid(CHESSPOS &tar, char board[10][9]); //重定义父类函数
void generateMovement(vector<MOVEMENT> &moveList, char board[10][9]); //重定义父类函数
void genMovePos(CHESSPOS srcPos, vector<CHESSPOS> &tarPos, char board[10][9]); //重定义父类函数
};
class B_Guard : public Chess //黑士
{
public:
B_Guard(CHESSPOS pos):Chess(pos) {}
~B_Guard() {}
bool moveValid(CHESSPOS &tar, char board[10][9]); //重定义父类函数
void generateMovement(vector<MOVEMENT> &moveList, char board[10][9]); //重定义父类函数
void genMovePos(CHESSPOS srcPos, vector<CHESSPOS> &tarPos, char board[10][9]); //重定义父类函数
};
class R_Bishop : public Chess //红象
{
public:
R_Bishop(CHESSPOS pos):Chess(pos) {}
~R_Bishop() {}
bool moveValid(CHESSPOS &tar, char board[10][9]); //重定义父类函数
void generateMovement(vector<MOVEMENT> &moveList, char board[10][9]); //重定义父类函数
void genMovePos(CHESSPOS srcPos, vector<CHESSPOS> &tarPos, char board[10][9]); //重定义父类函数
};
class B_Bishop : public Chess //黑象
{
public:
B_Bishop(CHESSPOS pos):Chess(pos) {}
~B_Bishop() {}
bool moveValid(CHESSPOS &tar, char board[10][9]); //重定义父类函数
void generateMovement(vector<MOVEMENT> &moveList, char board[10][9]); //重定义父类函数
void genMovePos(CHESSPOS srcPos, vector<CHESSPOS> &tarPos, char board[10][9]); //重定义父类函数
};
class R_Pawn : public Chess //红卒
{
public:
R_Pawn(CHESSPOS pos):Chess(pos) {}
~R_Pawn() {}
bool moveValid(CHESSPOS &tar, char board[10][9]); //重定义父类函数
void generateMovement(vector<MOVEMENT> &moveList, char board[10][9]); //重定义父类函数
void genMovePos(CHESSPOS srcPos, vector<CHESSPOS> &tarPos, char board[10][9]); //重定义父类函数
};
class B_Pawn : public Chess //黑卒
{
public:
B_Pawn(CHESSPOS pos):Chess(pos) {}
~B_Pawn() {}
bool moveValid(CHESSPOS &tar, char board[10][9]); //重定义父类函数
void generateMovement(vector<MOVEMENT> &moveList, char board[10][9]); //重定义父类函数
void genMovePos(CHESSPOS srcPos, vector<CHESSPOS> &tarPos, char board[10][9]); //重定义父类函数
};
class R_Horse : public Chess //红马
{
public:
R_Horse(CHESSPOS pos):Chess(pos) {}
~R_Horse() {}
bool moveValid(CHESSPOS &tar, char board[10][9]); //重定义父类函数
void generateMovement(vector<MOVEMENT> &moveList, char board[10][9]); //重定义父类函数
void genMovePos(CHESSPOS srcPos, vector<CHESSPOS> &tarPos, char board[10][9]); //重定义父类函数
};
class B_Horse : public Chess //黑马
{
public:
B_Horse(CHESSPOS pos):Chess(pos) {}
~B_Horse() {}
bool moveValid(CHESSPOS &tar, char board[10][9]); //重定义父类函数
void generateMovement(vector<MOVEMENT> &moveList, char board[10][9]); //重定义父类函数
void genMovePos(CHESSPOS srcPos, vector<CHESSPOS> &tarPos, char board[10][9]); //重定义父类函数
};
class R_Cannon : public Chess //红炮
{
public:
R_Cannon(CHESSPOS pos):Chess(pos) {}
~R_Cannon() {}
bool moveValid(CHESSPOS &tar, char board[10][9]); //重定义父类函数
void generateMovement(vector<MOVEMENT> &moveList, char board[10][9]); //重定义父类函数
void genMovePos(CHESSPOS srcPos, vector<CHESSPOS> &tarPos, char board[10][9]); //重定义父类函数
};
class B_Cannon : public Chess //黑炮
{
public:
B_Cannon(CHESSPOS pos):Chess(pos) {}
~B_Cannon() {}
bool moveValid(CHESSPOS &tar, char board[10][9]); //重定义父类函数
void generateMovement(vector<MOVEMENT> &moveList, char board[10][9]); //重定义父类函数
void genMovePos(CHESSPOS srcPos, vector<CHESSPOS> &tarPos, char board[10][9]); //重定义父类函数
};
class R_Car : public Chess //红车
{
public:
R_Car(CHESSPOS pos):Chess(pos) {}
~R_Car() {}
bool moveValid(CHESSPOS &tar, char board[10][9]); //重定义父类函数
void generateMovement(vector<MOVEMENT> &moveList, char board[10][9]); //重定义父类函数
void genMovePos(CHESSPOS srcPos, vector<CHESSPOS> &tarPos, char board[10][9]); //重定义父类函数
};
class B_Car : public Chess //黑车
{
public:
B_Car(CHESSPOS pos):Chess(pos) {}
~B_Car() {}
bool moveValid(CHESSPOS &tar, char board[10][9]); //重定义父类函数
void generateMovement(vector<MOVEMENT> &moveList, char board[10][9]); //重定义父类函数
void genMovePos(CHESSPOS srcPos, vector<CHESSPOS> &tarPos, char board[10][9]); //重定义父类函数
};
#endif // !CHESS_H