Files
2023-03-07 15:55:44 +08:00

91 lines
2.6 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#include <iostream>
#define BLACK false
#define WHITE true
enum putChessPieceResult { failed, success, win, fullBoard };
class ChessPiece {
private:
bool color;
bool isEmptyStatus;
bool isWinStatus;
public:
ChessPiece();
~ChessPiece();
void setColor(bool newColor);
// 设置颜色,黑或白
void setWin();
// 将自身设置为“获胜棋子”
void reset();
// 重置为未下状态
bool isEmpty();
bool getColor();
std::string show();
// 按照自身颜色及是否是“获胜棋”给出不同的样式。
};
class ChessBoard {
private:
static char emptyBoardString[3][4][4];
ChessPiece ChessPieces[19][19];
int size;
int chessCount;
char toHex(int);
// 把序号数字0123...变成123...ABCD...
void makeTitle();
// 输出一个棋盘表头
void countWinningPiece(bool color, int row, int column,
std::function<int(int)> const &rowFunc,
std::function<int(int)> const &columnFunc,
int possiblePieces[][2], int *connectCount);
// 检查从row, column开始以rowFunc
// columnFunc为状态转移函数连续的同颜色棋子的数量
// possiblePieces是用来存储连接的棋子坐标的
// connectCount是其它函数可能已经再其它方向找到了连接的棋子
void setWinPiece(int connectCount, int winningPieces[][2]);
// 将获胜棋子全部设置为获胜状态
public:
ChessBoard();
ChessBoard(int boardSize);
~ChessBoard();
void show();
// 显示现在的棋盘
bool setChess(bool color, int row, int column);
// Returns true if success, returns false if not
void reset();
// 重置所有棋子位置为空的
bool isFull();
// 返回现在是否已经下满了
bool checkWinner(int row, int column, bool color);
// 检查现在是否有玩家赢了row,
// column是最新下的一个棋子的坐标color是下这个棋的颜色
int getSize();
// 显示棋盘的大小(行数)
};
class Player {
private:
ChessBoard *board;
std::string playerName;
bool chessType;
static int chessCount;
int toInt(char input);
// 把行号1, 2, ... ABC转换为数字0123...
static void addCount();
// 棋子计数器增加
public:
Player(std::string name, bool type, ChessBoard *chessBoard);
~Player();
std::string getName();
bool getColor();
putChessPieceResult setChess(char row, char column);
// 在row, column处下自己颜色的棋子
static void resetCounts();
// 重置棋子计数器
};