refactor: Player 后面编号之前加 _ 以便后续重构时搜索处理

This commit is contained in:
Calcitem 2019-09-13 17:52:15 +08:00
parent f3d95dcc34
commit e1b5855f91
10 changed files with 145 additions and 148 deletions

View File

@ -63,7 +63,7 @@ value_t Evaluation::getValue(Position &dummyPosition, PositionContext *positionC
// 如果形成去子状态每有一个可去的子算100分
case ACTION_CAPTURE:
nPiecesNeedRemove = (positionContext->turn == PLAYER1) ?
nPiecesNeedRemove = (positionContext->turn == PLAYER_1) ?
positionContext->nPiecesNeedRemove : -(positionContext->nPiecesNeedRemove);
value += nPiecesNeedRemove * VALUE_EACH_PIECE_NEEDREMOVE;
#ifdef DEBUG_AB_TREE
@ -94,7 +94,7 @@ value_t Evaluation::getValue(Position &dummyPosition, PositionContext *positionC
// 如果形成去子状态每有一个可去的子算128分
case ACTION_CAPTURE:
nPiecesNeedRemove = (positionContext->turn == PLAYER1) ?
nPiecesNeedRemove = (positionContext->turn == PLAYER_1) ?
positionContext->nPiecesNeedRemove : -(positionContext->nPiecesNeedRemove);
value += nPiecesNeedRemove * VALUE_EACH_PIECE_NEEDREMOVE_2;
#ifdef DEBUG_AB_TREE
@ -113,7 +113,7 @@ value_t Evaluation::getValue(Position &dummyPosition, PositionContext *positionC
if (positionContext->nPiecesOnBoard_1 + positionContext->nPiecesOnBoard_2 >=
Board::N_SEATS * Board::N_RINGS) {
if (dummyPosition.getRule()->isStartingPlayerLoseWhenBoardFull) {
// winner = PLAYER2;
// winner = PLAYER_2;
value -= VALUE_WIN;
#ifdef DEBUG_AB_TREE
node->result = -3;
@ -128,7 +128,7 @@ value_t Evaluation::getValue(Position &dummyPosition, PositionContext *positionC
dummyPosition.context.board.isAllSurrounded(positionContext->turn, dummyPosition.currentRule, positionContext->nPiecesOnBoard_1, positionContext->nPiecesOnBoard_2, positionContext->turn) &&
dummyPosition.getRule()->isLoseWhenNoWay) {
// 规则要求被“闷”判负,则对手获胜
if (positionContext->turn == PLAYER1) {
if (positionContext->turn == PLAYER_1) {
value -= VALUE_WIN;
#ifdef DEBUG_AB_TREE
node->result = -2;

View File

@ -36,7 +36,7 @@ void MoveList::generateLegalMoves(MillGameAi_ab &ai_ab, Position &dummyPosition,
switch (dummyPosition.getPhase()) {
case PHASE_PLACING:
if (dummyPosition.getAction() == ACTION_CAPTURE) {
if (dummyPosition.whosTurn() == PLAYER1)
if (dummyPosition.whosTurn() == PLAYER_1)
newCapacity = static_cast<size_t>(dummyPosition.getPiecesOnBoardCount_2());
else
newCapacity = static_cast<size_t>(dummyPosition.getPiecesOnBoardCount_1());
@ -46,7 +46,7 @@ void MoveList::generateLegalMoves(MillGameAi_ab &ai_ab, Position &dummyPosition,
break;
case PHASE_MOVING:
if (dummyPosition.getAction() == ACTION_CAPTURE) {
if (dummyPosition.whosTurn() == PLAYER1)
if (dummyPosition.whosTurn() == PLAYER_1)
newCapacity = static_cast<size_t>(dummyPosition.getPiecesOnBoardCount_2());
else
newCapacity = static_cast<size_t>(dummyPosition.getPiecesOnBoardCount_1());
@ -110,9 +110,9 @@ void MoveList::generateLegalMoves(MillGameAi_ab &ai_ab, Position &dummyPosition,
continue;
}
if ((dummyPosition.context.turn == PLAYER1 &&
if ((dummyPosition.context.turn == PLAYER_1 &&
(dummyPosition.context.nPiecesOnBoard_1 > dummyPosition.currentRule.nPiecesAtLeast || !dummyPosition.currentRule.allowFlyWhenRemainThreePieces)) ||
(dummyPosition.context.turn == PLAYER2 &&
(dummyPosition.context.turn == PLAYER_2 &&
(dummyPosition.context.nPiecesOnBoard_2 > dummyPosition.currentRule.nPiecesAtLeast || !dummyPosition.currentRule.allowFlyWhenRemainThreePieces))) {
// 对于棋盘上还有3个子以上或不允许飞子的情况要求必须在着法表中
for (int direction = DIRECTION_CLOCKWISE; direction <= DIRECTION_OUTWARD; direction++) {

View File

@ -233,7 +233,7 @@ void MillGameAi_ab::sortLegalMoves(Node *node)
{
// 这个函数对效率的影响很大,排序好的话,剪枝较早,节省时间,但不能在此函数耗费太多时间
if (dummyPosition.whosTurn() == PLAYER1) {
if (dummyPosition.whosTurn() == PLAYER_1) {
std::stable_sort(node->children.begin(), node->children.end(), nodeGreater);
} else {
std::stable_sort(node->children.begin(), node->children.end(), nodeLess);
@ -432,7 +432,7 @@ value_t MillGameAi_ab::alphaBetaPruning(depth_t depth, value_t alpha, value_t be
#if 0
// TODO: 有必要针对深度微调 value?
if (positionContext->turn == PLAYER1)
if (positionContext->turn == PLAYER_1)
node->value += hashValue.depth - depth;
else
node->value -= hashValue.depth - depth;
@ -490,7 +490,7 @@ value_t MillGameAi_ab::alphaBetaPruning(depth_t depth, value_t alpha, value_t be
evaluatedNodeCount++;
// 为争取速胜value 值 +- 深度 (有必要?)
if (positionContext->turn == PLAYER1) {
if (positionContext->turn == PLAYER_1) {
node->value += depth;
} else {
node->value -= depth;
@ -505,7 +505,7 @@ value_t MillGameAi_ab::alphaBetaPruning(depth_t depth, value_t alpha, value_t be
#ifdef BOOK_LEARNING
// 检索开局库
if (positionContext->phase == GAME_PLACING && findBookHash(hash, hashValue)) {
if (positionContext->turn == PLAYER2) {
if (positionContext->turn == PLAYER_2) {
// 是否需对后手扣分 // TODO: 先后手都处理
node->value += 1;
}
@ -525,7 +525,7 @@ value_t MillGameAi_ab::alphaBetaPruning(depth_t depth, value_t alpha, value_t be
// 根据演算模型执行 MiniMax 检索,对先手,搜索 Max, 对后手,搜索 Min
minMax = dummyPosition.whosTurn() == PLAYER1 ? -VALUE_INFINITE : VALUE_INFINITE;
minMax = dummyPosition.whosTurn() == PLAYER_1 ? -VALUE_INFINITE : VALUE_INFINITE;
for (auto child : node->children) {
// 上下文入栈保存,以便后续撤销着法
@ -556,7 +556,7 @@ value_t MillGameAi_ab::alphaBetaPruning(depth_t depth, value_t alpha, value_t be
dummyPosition.context = contextStack.top();
contextStack.pop();
if (dummyPosition.whosTurn() == PLAYER1) {
if (dummyPosition.whosTurn() == PLAYER_1) {
// 为走棋一方的层, 局面对走棋的一方来说是以 α 为评价
// 取最大值
@ -693,8 +693,8 @@ const char* MillGameAi_ab::bestMove()
for (auto child : rootNode->children) {
// TODO: 使用常量代替
if ((whosTurn == PLAYER1 && child->value > -10000) ||
(whosTurn == PLAYER2 && child->value < 10000)) {
if ((whosTurn == PLAYER_1 && child->value > -10000) ||
(whosTurn == PLAYER_2 && child->value < 10000)) {
isMostLose = false;
break;
}
@ -702,9 +702,9 @@ const char* MillGameAi_ab::bestMove()
// 自动认输
if (isMostLose) {
if (whosTurn == PLAYER1) {
if (whosTurn == PLAYER_1) {
sprintf(cmdline, "Player1 give up!");
} else if (whosTurn == PLAYER2) {
} else if (whosTurn == PLAYER_2) {
sprintf(cmdline, "Player2 give up!");
}

View File

@ -319,9 +319,9 @@ bool Board::isAllInMills(enum player_t player)
{
char ch = 0x00;
if (player == PLAYER1)
if (player == PLAYER_1)
ch = 0x10;
else if (player == PLAYER2)
else if (player == PLAYER_2)
ch = 0x20;
else
return true;
@ -334,9 +334,9 @@ int Board::getSurroundedEmptyLocationCount(enum player_t turn, const Rule &curre
{
int count = 0;
if ((turn == PLAYER1 &&
if ((turn == PLAYER_1 &&
(nPiecesOnBoard_1 > currentRule.nPiecesAtLeast || !currentRule.allowFlyWhenRemainThreePieces)) ||
(turn == PLAYER2 &&
(turn == PLAYER_2 &&
(nPiecesOnBoard_2 > currentRule.nPiecesAtLeast || !currentRule.allowFlyWhenRemainThreePieces))) {
int moveLocation;
for (direction_t d = DIRECTION_BEGIN; d < DIRECTIONS_COUNT; d = (direction_t)(d + 1)) {
@ -357,9 +357,9 @@ int Board::getSurroundedEmptyLocationCount(enum player_t turn, const Rule &curre
bool Board::isSurrounded(enum player_t turn, const Rule &currentRule, int nPiecesOnBoard_1, int nPiecesOnBoard_2, int location)
{
// 判断location处的棋子是否被“闷”
if ((turn == PLAYER1 &&
if ((turn == PLAYER_1 &&
(nPiecesOnBoard_1 > currentRule.nPiecesAtLeast || !currentRule.allowFlyWhenRemainThreePieces)) ||
(turn == PLAYER2 &&
(turn == PLAYER_2 &&
(nPiecesOnBoard_2 > currentRule.nPiecesAtLeast || !currentRule.allowFlyWhenRemainThreePieces))) {
int i, moveLocation;
for (i = 0; i < 4; i++) {
@ -382,9 +382,9 @@ bool Board::isAllSurrounded(enum player_t turn, const Rule &currentRule, int nPi
return true;
// 判断是否可以飞子
if ((turn == PLAYER1 &&
if ((turn == PLAYER_1 &&
(nPiecesOnBoard_1 <= currentRule.nPiecesAtLeast && currentRule.allowFlyWhenRemainThreePieces)) ||
(turn == PLAYER2 &&
(turn == PLAYER_2 &&
(nPiecesOnBoard_2 <= currentRule.nPiecesAtLeast && currentRule.allowFlyWhenRemainThreePieces))) {
return false;
}
@ -411,9 +411,9 @@ bool Board::isAllSurrounded(enum player_t turn, const Rule &currentRule, int nPi
{
char t = '\x30';
if (ply == PLAYER1)
if (ply == PLAYER_1)
t &= '\x10';
else if (ply == PLAYER2)
else if (ply == PLAYER_2)
t &= '\x20';
return isAllSurrounded(turn, currentRule, nPiecesOnBoard_1, nPiecesOnBoard_2, t);
@ -424,10 +424,10 @@ enum player_t Board::getWhosPiece(int r, int s)
int location = polarToLocation(r, s);
if (locations[location] & '\x10')
return PLAYER1;
return PLAYER_1;
if (locations[location] & '\x20')
return PLAYER2;
return PLAYER_2;
return PLAYER_NOBODY;
}
@ -437,9 +437,9 @@ bool Board::getPieceRS(const player_t &player, const int &number, int &r, int &s
{
int piece;
if (player == PLAYER1) {
if (player == PLAYER_1) {
piece = 0x10;
} else if (player == PLAYER2) {
} else if (player == PLAYER_2) {
piece = 0x20;
} else {
return false;
@ -469,10 +469,10 @@ bool Board::getCurrentPiece(player_t &player, int &number, int location)
int p = locations[location];
if (p & 0x10) {
player = PLAYER1;
player = PLAYER_1;
number = p - 0x10;
} else if (p & 0x20) {
player = PLAYER2;
player = PLAYER_2;
number = p - 0x20;
} else {
return false;

View File

@ -79,9 +79,9 @@ Position &Position::operator= (const Position &position)
int Position::playerToId(enum player_t player)
{
if (player == PLAYER1)
if (player == PLAYER_1)
return 1;
else if (player == PLAYER2)
else if (player == PLAYER_2)
return 2;
return 0;
@ -91,10 +91,10 @@ player_t Position::getOpponent(player_t player)
{
switch (player)
{
case PLAYER1:
return PLAYER2;
case PLAYER2:
return PLAYER1;
case PLAYER_1:
return PLAYER_2;
case PLAYER_2:
return PLAYER_1;
default:
break;
}
@ -149,10 +149,10 @@ bool Position::setContext(const struct Rule *rule, step_t maxStepsLedToDraw, int
}
// 轮流状态标识
if (flags & PLAYER1) {
context.turn = PLAYER1;
} else if (flags & PLAYER2) {
context.turn = PLAYER2;
if (flags & PLAYER_1) {
context.turn = PLAYER_1;
} else if (flags & PLAYER_2) {
context.turn = PLAYER_2;
} else {
return false;
}
@ -293,7 +293,7 @@ bool Position::reset()
context.phase = PHASE_NOTSTARTED;
// 轮流状态标识
context.turn = PLAYER1;
context.turn = PLAYER_1;
// 动作状态标识
context.action = ACTION_PLACE;
@ -406,7 +406,7 @@ bool Position::place(int location, int time_p, int8_t rs)
if (context.phase == PHASE_PLACING) {
// 先手下
if (context.turn == PLAYER1) {
if (context.turn == PLAYER_1) {
piece = '\x11' + currentRule.nTotalPiecesEachSide - context.nPiecesInHand_1;
context.nPiecesInHand_1--;
context.nPiecesOnBoard_1++;
@ -451,9 +451,9 @@ bool Position::place(int location, int time_p, int8_t rs)
// 设置轮到谁走
if (currentRule.isDefenderMoveFirst) {
context.turn = PLAYER2;
context.turn = PLAYER_2;
} else {
context.turn = PLAYER1;
context.turn = PLAYER_1;
}
// 再决胜负
@ -487,9 +487,9 @@ bool Position::place(int location, int time_p, int8_t rs)
// 对于中局落子 (ontext.phase == GAME_MOVING)
// 如果落子不合法
if ((context.turn == PLAYER1 &&
if ((context.turn == PLAYER_1 &&
(context.nPiecesOnBoard_1 > currentRule.nPiecesAtLeast || !currentRule.allowFlyWhenRemainThreePieces)) ||
(context.turn == PLAYER2 &&
(context.turn == PLAYER_2 &&
(context.nPiecesOnBoard_2 > currentRule.nPiecesAtLeast || !currentRule.allowFlyWhenRemainThreePieces))) {
int i;
@ -595,7 +595,7 @@ bool Position::capture(int location, int time_p, int8_t cp)
int player_ms = -1;
// 对手
char opponent = context.turn == PLAYER1 ? 0x20 : 0x10;
char opponent = context.turn == PLAYER_1 ? 0x20 : 0x10;
// 判断去子是不是对手棋
if (!(opponent & boardLocations[location]))
@ -618,9 +618,9 @@ bool Position::capture(int location, int time_p, int8_t cp)
boardLocations[location] = '\x00';
}
if (context.turn == PLAYER1)
if (context.turn == PLAYER_1)
context.nPiecesOnBoard_2--;
else if (context.turn == PLAYER2)
else if (context.turn == PLAYER_2)
context.nPiecesOnBoard_1--;
move_ = -location;
@ -668,9 +668,9 @@ bool Position::capture(int location, int time_p, int8_t cp)
// 设置轮到谁走
if (currentRule.isDefenderMoveFirst) {
context.turn = PLAYER2;
context.turn = PLAYER_2;
} else {
context.turn = PLAYER1;
context.turn = PLAYER_1;
}
// 再决胜负
@ -724,7 +724,7 @@ bool Position::choose(int location)
if (context.action != ACTION_CHOOSE && context.action != ACTION_PLACE)
return false;
char t = context.turn == PLAYER1 ? 0x10 : 0x20;
char t = context.turn == PLAYER_1 ? 0x10 : 0x20;
// 判断选子是否可选
if (boardLocations[location] & t) {
@ -760,13 +760,13 @@ bool Position::giveup(player_t loser)
context.phase = PHASE_GAMEOVER;
if (loser == PLAYER1) {
winner = PLAYER2;
if (loser == PLAYER_1) {
winner = PLAYER_2;
tips = "玩家1投子认负。";
sprintf(cmdline, "Player1 give up!");
score_2++;
} else if (loser == PLAYER2) {
winner = PLAYER1;
} else if (loser == PLAYER_2) {
winner = PLAYER_1;
tips = "玩家2投子认负。";
sprintf(cmdline, "Player2 give up!");
score_1++;
@ -837,10 +837,10 @@ bool Position::command(const char *cmd)
if (args == 1) {
if (t == 1) {
return giveup(PLAYER1);
return giveup(PLAYER_1);
}
if (t == 2) {
return giveup(PLAYER2);
return giveup(PLAYER_2);
}
}
@ -883,8 +883,8 @@ bool Position::command(int move)
inline int Position::update(int time_p /*= -1*/)
{
int ret = -1;
time_t *player_ms = (context.turn == PLAYER1 ? &elapsedSeconds_1 : &elapsedSeconds_2);
time_t playerNext_ms = (context.turn == PLAYER1 ? elapsedSeconds_2 : elapsedSeconds_1);
time_t *player_ms = (context.turn == PLAYER_1 ? &elapsedSeconds_1 : &elapsedSeconds_2);
time_t playerNext_ms = (context.turn == PLAYER_1 ? elapsedSeconds_2 : elapsedSeconds_1);
// 根据局面调整计时器
@ -935,14 +935,14 @@ bool Position::win(bool forceDraw)
// 如果玩家1超时
if (elapsedSeconds_1 > currentRule.maxTimeLedToLose * 60) {
elapsedSeconds_1 = currentRule.maxTimeLedToLose * 60;
winner = PLAYER2;
winner = PLAYER_2;
tips = "玩家1超时判负。";
sprintf(cmdline, "Time over. Player2 win!");
}
// 如果玩家2超时
else if (elapsedSeconds_2 > currentRule.maxTimeLedToLose * 60) {
elapsedSeconds_2 = currentRule.maxTimeLedToLose * 60;
winner = PLAYER1;
winner = PLAYER_1;
tips = "玩家2超时判负。";
sprintf(cmdline, "Time over. Player1 win!");
}
@ -963,7 +963,7 @@ bool Position::win(bool forceDraw)
// 如果玩家1子数小于赛点则玩家2获胜
if (context.nPiecesOnBoard_1 + context.nPiecesInHand_1 < currentRule.nPiecesAtLeast) {
winner = PLAYER2;
winner = PLAYER_2;
context.phase = PHASE_GAMEOVER;
sprintf(cmdline, "Player2 win!");
cmdlist.emplace_back(string(cmdline));
@ -972,7 +972,7 @@ bool Position::win(bool forceDraw)
// 如果玩家2子数小于赛点则玩家1获胜
if (context.nPiecesOnBoard_2 + context.nPiecesInHand_2 < currentRule.nPiecesAtLeast) {
winner = PLAYER1;
winner = PLAYER_1;
context.phase = PHASE_GAMEOVER;
sprintf(cmdline, "Player1 win!");
cmdlist.emplace_back(string(cmdline));
@ -987,7 +987,7 @@ bool Position::win(bool forceDraw)
context.phase = PHASE_GAMEOVER;
if (currentRule.isStartingPlayerLoseWhenBoardFull) {
winner = PLAYER2;
winner = PLAYER_2;
sprintf(cmdline, "Player2 win!");
} else {
winner = PLAYER_DRAW;
@ -1004,14 +1004,14 @@ bool Position::win(bool forceDraw)
context.phase = PHASE_GAMEOVER;
if (currentRule.isLoseWhenNoWay) {
if (context.turn == PLAYER1) {
if (context.turn == PLAYER_1) {
tips = "玩家1无子可走被闷。";
winner = PLAYER2;
winner = PLAYER_2;
sprintf(cmdline, "Player1 no way to go. Player2 win!");
cmdlist.emplace_back(string(cmdline));
} else {
tips = "玩家2无子可走被闷。";
winner = PLAYER1;
winner = PLAYER_1;
sprintf(cmdline, "Player2 no way to go. Player1 win!");
cmdlist.emplace_back(string(cmdline));
#ifdef BOOK_LEARNING
@ -1085,7 +1085,7 @@ void Position::cleanForbiddenLocations()
enum player_t Position::changeTurn()
{
// 设置轮到谁走
context.turn = (context.turn == PLAYER1) ? PLAYER2 : PLAYER1;
context.turn = (context.turn == PLAYER_1) ? PLAYER_2 : PLAYER_1;
return context.turn;
}
@ -1100,15 +1100,15 @@ void Position::setTips()
case PHASE_PLACING:
if (context.action == ACTION_PLACE) {
if (context.turn == PLAYER1) {
if (context.turn == PLAYER_1) {
tips = "轮到玩家1落子剩余" + std::to_string(context.nPiecesInHand_1) + "";
} else if (context.turn == PLAYER2) {
} else if (context.turn == PLAYER_2) {
tips = "轮到玩家2落子剩余" + std::to_string(context.nPiecesInHand_2) + "";
}
} else if (context.action == ACTION_CAPTURE) {
if (context.turn == PLAYER1) {
if (context.turn == PLAYER_1) {
tips = "成三轮到玩家1去子需去" + std::to_string(context.nPiecesNeedRemove) + "";
} else if (context.turn == PLAYER2) {
} else if (context.turn == PLAYER_2) {
tips = "成三轮到玩家2去子需去" + std::to_string(context.nPiecesNeedRemove) + "";
}
}
@ -1116,15 +1116,15 @@ void Position::setTips()
case PHASE_MOVING:
if (context.action == ACTION_PLACE || context.action == ACTION_CHOOSE) {
if (context.turn == PLAYER1) {
if (context.turn == PLAYER_1) {
tips = "轮到玩家1选子移动";
} else if (context.turn == PLAYER2) {
} else if (context.turn == PLAYER_2) {
tips = "轮到玩家2选子移动";
}
} else if (context.action == ACTION_CAPTURE) {
if (context.turn == PLAYER1) {
if (context.turn == PLAYER_1) {
tips = "成三轮到玩家1去子需去" + std::to_string(context.nPiecesNeedRemove) + "";
} else if (context.turn == PLAYER2) {
} else if (context.turn == PLAYER_2) {
tips = "成三轮到玩家2去子需去" + std::to_string(context.nPiecesNeedRemove) + "";
}
}
@ -1135,13 +1135,13 @@ void Position::setTips()
score_draw++;
tips = "双方平局!比分 " + to_string(score_1) + ":" + to_string(score_2) + ", 和棋 " + to_string(score_draw);
}
else if (winner == PLAYER1) {
else if (winner == PLAYER_1) {
score_1++;
if (tips.find("无子可走") != string::npos)
tips += "玩家1获胜比分 " + to_string(score_1) + ":" + to_string(score_2) + ", 和棋 " + to_string(score_draw);
else
tips = "玩家1获胜比分 " + to_string(score_1) + ":" + to_string(score_2) + ", 和棋 " + to_string(score_draw);
} else if (winner == PLAYER2) {
} else if (winner == PLAYER_2) {
score_2++;
if (tips.find("无子可走") != string::npos)
tips += "玩家2获胜比分 " + to_string(score_1) + ":" + to_string(score_2) + ", 和棋 " + to_string(score_draw);
@ -1215,7 +1215,7 @@ hash_t Position::updateHashMisc()
// 置位
if (context.turn == PLAYER2) {
if (context.turn == PLAYER_2) {
context.hash |= 1U;
}

View File

@ -115,7 +115,7 @@ public:
step_t maxStepsLedToDraw = 0, // 限制步数
int maxTimeLedToLose = 0, // 限制时间
step_t initialStep = 0, // 默认起始步数为0
int flags = PHASE_NOTSTARTED | PLAYER1 | ACTION_PLACE, // 默认状态
int flags = PHASE_NOTSTARTED | PLAYER_1 | ACTION_PLACE, // 默认状态
const char *locations = nullptr, // 默认空棋盘
int nPiecesInHand_1 = 12, // 玩家1剩余未放置子数
int nPiecesInHand_2 = 12, // 玩家2剩余未放置子数

View File

@ -20,9 +20,9 @@
*****************************************************************************/
#ifndef RULE_H
#define RULE_H
#include "types.h"
#define RULE_H
#include "types.h"
struct Rule
{
@ -71,12 +71,12 @@ struct Rule
// 包干最长时间超出判负为0则不计时
int maxTimeLedToLose;
};
// 预定义的规则数目
static const int N_RULES = 4;
// 预定义的规则
extern const struct Rule RULES[N_RULES];
#endif /* RULE_H */
extern const struct Rule RULES[N_RULES];
#endif /* RULE_H */

View File

@ -84,8 +84,8 @@ enum piece_t : uint16_t
// 玩家标识, 轮流状态, 胜负标识
enum player_t : uint8_t
{
PLAYER1 = 0x10, // 玩家1
PLAYER2 = 0x20, // 玩家2
PLAYER_1 = 0x10, // 玩家1
PLAYER_2 = 0x20, // 玩家2
PLAYER_DRAW = 0x40, // 双方和棋
PLAYER_NOBODY = 0x80 // 胜负未分
};

View File

@ -44,8 +44,8 @@ GameController::GameController(GameScene & scene, QObject * parent) :
currentRow(-1),
isEditing(false),
isInverted(false),
isAiPlayer1(false),
isAiPlayer2(false),
isAiPlayer_1(false),
isAiPlayer_2(false),
hasAnimation(true),
durationTime(500),
hasSound(true),
@ -151,8 +151,8 @@ void GameController::gameReset()
if (!isAutoRestart) {
ai1.stop();
ai2.stop();
isAiPlayer1 = false;
isAiPlayer2 = false;
isAiPlayer_1 = false;
isAiPlayer_2 = false;
}
// 清除棋子
@ -286,7 +286,7 @@ void GameController::setEngine1(bool arg)
{
position_.configure(giveUpIfMostLose_, randomMove_);
isAiPlayer1 = arg;
isAiPlayer_1 = arg;
if (arg) {
ai1.setAi(position_);
if (ai1.isRunning())
@ -302,7 +302,7 @@ void GameController::setEngine2(bool arg)
{
position_.configure(giveUpIfMostLose_, randomMove_);
isAiPlayer2 = arg;
isAiPlayer_2 = arg;
if (arg) {
ai2.setAi(position_);
if (ai2.isRunning())
@ -316,11 +316,11 @@ void GameController::setEngine2(bool arg)
void GameController::setAiDepthTime(depth_t depth1, int time1, depth_t depth2, int time2)
{
if (isAiPlayer1) {
if (isAiPlayer_1) {
ai1.stop();
ai1.wait();
}
if (isAiPlayer2) {
if (isAiPlayer_2) {
ai2.stop();
ai2.wait();
}
@ -328,10 +328,10 @@ void GameController::setAiDepthTime(depth_t depth1, int time1, depth_t depth2, i
ai1.setAi(position_, depth1, time1);
ai2.setAi(position_, depth2, time2);
if (isAiPlayer1) {
if (isAiPlayer_1) {
ai1.start();
}
if (isAiPlayer2) {
if (isAiPlayer_2) {
ai2.start();
}
}
@ -389,11 +389,11 @@ void GameController::setRandomMove(bool arg)
// 上下翻转
void GameController::flip()
{
if (isAiPlayer1) {
if (isAiPlayer_1) {
ai1.stop();
ai1.wait();
}
if (isAiPlayer2) {
if (isAiPlayer_2) {
ai2.stop();
ai2.wait();
}
@ -417,11 +417,11 @@ void GameController::flip()
ai1.setAi(position_);
ai2.setAi(position_);
if (isAiPlayer1) {
if (isAiPlayer_1) {
ai1.start();
}
if (isAiPlayer2) {
if (isAiPlayer_2) {
ai2.start();
}
}
@ -429,11 +429,11 @@ void GameController::flip()
// 左右镜像
void GameController::mirror()
{
if (isAiPlayer1) {
if (isAiPlayer_1) {
ai1.stop();
ai1.wait();
}
if (isAiPlayer2) {
if (isAiPlayer_2) {
ai2.stop();
ai2.wait();
}
@ -459,11 +459,11 @@ void GameController::mirror()
ai1.setAi(position_);
ai2.setAi(position_);
if (isAiPlayer1) {
if (isAiPlayer_1) {
ai1.start();
}
if (isAiPlayer2) {
if (isAiPlayer_2) {
ai2.start();
}
}
@ -471,11 +471,11 @@ void GameController::mirror()
// 视图须时针旋转90°
void GameController::turnRight()
{
if (isAiPlayer1) {
if (isAiPlayer_1) {
ai1.stop();
ai1.wait();
}
if (isAiPlayer2) {
if (isAiPlayer_2) {
ai2.stop();
ai2.wait();
}
@ -499,11 +499,11 @@ void GameController::turnRight()
ai1.setAi(position_);
ai2.setAi(position_);
if (isAiPlayer1) {
if (isAiPlayer_1) {
ai1.start();
}
if (isAiPlayer2) {
if (isAiPlayer_2) {
ai2.start();
}
}
@ -511,11 +511,11 @@ void GameController::turnRight()
// 视图逆时针旋转90°
void GameController::turnLeft()
{
if (isAiPlayer1) {
if (isAiPlayer_1) {
ai1.stop();
ai1.wait();
}
if (isAiPlayer2) {
if (isAiPlayer_2) {
ai2.stop();
ai2.wait();
}
@ -534,10 +534,10 @@ void GameController::turnLeft()
ai1.setAi(position_);
ai2.setAi(position_);
if (isAiPlayer1) {
if (isAiPlayer_1) {
ai1.start();
}
if (isAiPlayer2) {
if (isAiPlayer_2) {
ai2.start();
}
}
@ -609,8 +609,8 @@ void GameController::timerEvent(QTimerEvent *event)
bool GameController::isAIsTurn()
{
return ((position_.whosTurn() == PLAYER1 && isAiPlayer1) ||
(position_.whosTurn() == PLAYER2 && isAiPlayer2));
return ((position_.whosTurn() == PLAYER_1 && isAiPlayer_1) ||
(position_.whosTurn() == PLAYER_2 && isAiPlayer_2));
}
// 关键槽函数根据QGraphicsScene的信号和状态来执行选子、落子或去子
@ -748,16 +748,16 @@ bool GameController::actionPiece(QPointF pos)
if (&position_ == &(this->position_)) {
// 如果还未决出胜负
if (position_.whoWin() == PLAYER_NOBODY) {
if (position_.whosTurn() == PLAYER1) {
if (isAiPlayer1) {
if (position_.whosTurn() == PLAYER_1) {
if (isAiPlayer_1) {
ai1.resume();
}
if (isAiPlayer2)
if (isAiPlayer_2)
ai2.pause();
} else {
if (isAiPlayer1)
if (isAiPlayer_1)
ai1.pause();
if (isAiPlayer2) {
if (isAiPlayer_2) {
ai2.resume();
}
}
@ -782,11 +782,11 @@ bool GameController::giveUp()
{
bool result = false;
if (position_.whosTurn() == PLAYER1) {
result = position_.giveup(PLAYER1);
if (position_.whosTurn() == PLAYER_1) {
result = position_.giveup(PLAYER_1);
}
else if (position_.whosTurn() == PLAYER2) {
result = position_.giveup(PLAYER2);
else if (position_.whosTurn() == PLAYER_2) {
result = position_.giveup(PLAYER_2);
}
if (result) {
@ -815,10 +815,10 @@ bool GameController::command(const QString &cmd, bool update /* = true */)
Q_UNUSED(hasSound)
// 防止接收滞后结束的线程发送的指令
if (sender() == &ai1 && !isAiPlayer1)
if (sender() == &ai1 && !isAiPlayer_1)
return false;
if (sender() == &ai2 && !isAiPlayer2)
if (sender() == &ai2 && !isAiPlayer_2)
return false;
// 声音
@ -892,16 +892,16 @@ bool GameController::command(const QString &cmd, bool update /* = true */)
if (&position_ == &(this->position_)) {
// 如果还未决出胜负
if (position_.whoWin() == PLAYER_NOBODY) {
if (position_.whosTurn() == PLAYER1) {
if (isAiPlayer1) {
if (position_.whosTurn() == PLAYER_1) {
if (isAiPlayer_1) {
ai1.resume();
}
if (isAiPlayer2)
if (isAiPlayer_2)
ai2.pause();
} else {
if (isAiPlayer1)
if (isAiPlayer_1)
ai1.pause();
if (isAiPlayer2) {
if (isAiPlayer_2) {
ai2.resume();
}
}
@ -915,10 +915,10 @@ bool GameController::command(const QString &cmd, bool update /* = true */)
gameReset();
gameStart();
if (isAiPlayer1) {
if (isAiPlayer_1) {
setEngine1(true);
}
if (isAiPlayer2) {
if (isAiPlayer_2) {
setEngine2(true);
}
}
@ -932,10 +932,10 @@ bool GameController::command(const QString &cmd, bool update /* = true */)
}
// 网络: 将着法放到服务器的发送列表中
if (isAiPlayer1)
if (isAiPlayer_1)
{
ai1.getServer()->setAction(cmd);
} else if (isAiPlayer2) {
} else if (isAiPlayer_2) {
ai1.getServer()->setAction(cmd); // 注意: 同样是AI1
}

View File

@ -224,9 +224,6 @@ private:
// 当前浏览的棋谱行
int currentRow;
// 玩家1手棋数、玩家2手棋数、待去棋数没有用到注释掉
//int player1_InHand, player2_InHand, num_NeedRemove;
// 是否处于“编辑棋局”状态
bool isEditing;
@ -234,10 +231,10 @@ private:
bool isInverted;
// 是否电脑执先手
bool isAiPlayer1;
bool isAiPlayer_1;
// 是否电脑执后手
bool isAiPlayer2;
bool isAiPlayer_2;
// 是否有落子动画
bool hasAnimation;