rule: refactor: 修改规则相关变量名提高可读性
This commit is contained in:
parent
900aac636a
commit
48358b0e99
|
@ -138,15 +138,12 @@
|
|||
|
||||
//#define DONOT_PLAY_WIN_SOUND
|
||||
|
||||
// 摆棋阶段在叉下面显示被吃的子
|
||||
//#define GAME_PLACING_SHOW_REMOVED_PIECES
|
||||
|
||||
// 启动时窗口最大化
|
||||
//#define SHOW_MAXIMIZED_ON_LOAD
|
||||
|
||||
// 不使用哈希桶
|
||||
#define DISABLE_HASHBUCKET
|
||||
// 哈希表不加锁
|
||||
|
||||
#define HASHMAP_NOLOCK
|
||||
|
||||
#ifdef WIN32
|
||||
|
|
|
@ -93,7 +93,7 @@ Value Eval::evaluate(Position *pos)
|
|||
// 布局阶段闷棋判断
|
||||
if (pos->nPiecesOnBoard[BLACK] + pos->nPiecesOnBoard[WHITE] >=
|
||||
Board::N_RANKS * Board::N_FILES) {
|
||||
if (rule.isStartingPlayerLoseWhenBoardFull) {
|
||||
if (rule.isBlackLosebutNotDrawWhenBoardFull) {
|
||||
value -= VALUE_MATE;
|
||||
} else {
|
||||
value = VALUE_DRAW;
|
||||
|
@ -103,7 +103,7 @@ Value Eval::evaluate(Position *pos)
|
|||
// 走棋阶段被闷判断
|
||||
else if (pos->action == ACTION_SELECT &&
|
||||
pos->board.isAllSurrounded(pos->sideId, pos->nPiecesOnBoard, pos->sideToMove) &&
|
||||
rule.isLoseWhenNoWay) {
|
||||
rule.isLoseButNotChangeTurnWhenNoWay) {
|
||||
// 规则要求被“闷”判负,则对手获胜
|
||||
Value delta = pos->sideToMove == PLAYER_BLACK ? -VALUE_MATE : VALUE_MATE;
|
||||
value += delta;
|
||||
|
|
|
@ -395,7 +395,7 @@ ExtMove *generateMoves(/* TODO: const */ Position *position, ExtMove *moveList)
|
|||
for (int i = Board::MOVE_PRIORITY_TABLE_SIZE - 1; i >= 0; i--) {
|
||||
square = static_cast<Square>(MoveList::movePriorityTable[i]);
|
||||
if (position->board.locations[square] & opponent) {
|
||||
if (rule.allowRemoveMill || !position->board.inHowManyMills(square, PLAYER_NOBODY)) {
|
||||
if (rule.allowRemovePieceInMill || !position->board.inHowManyMills(square, PLAYER_NOBODY)) {
|
||||
*cur++ = ((Move)-square);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,7 +59,7 @@ void MovePicker::score()
|
|||
int nopponentMills = 0;
|
||||
|
||||
#ifdef SORT_MOVE_WITH_HUMAN_KNOWLEDGES
|
||||
// TODO: rule.allowRemoveMultiPieces 以及 适配打三棋之外的其他规则
|
||||
// TODO: rule.allowRemoveMultiPiecesWhenCloseMultiMill 以及 适配打三棋之外的其他规则
|
||||
if (type_of(m) != MOVETYPE_REMOVE) {
|
||||
// 在任何阶段, 都检测落子点是否能使得本方成三
|
||||
if (nMills > 0) {
|
||||
|
|
|
@ -284,7 +284,7 @@ int Board::addMills(Square square)
|
|||
+ static_cast<uint64_t>(idx[2]);
|
||||
|
||||
// 如果允许相同三连反复去子
|
||||
if (rule.allowRemovePiecesRepeatedly) {
|
||||
if (rule.allowRemovePiecesRepeatedlyWhenCloseSameMill) {
|
||||
n++;
|
||||
continue;
|
||||
}
|
||||
|
@ -468,7 +468,7 @@ void Board::mirror(vector<string> &cmdlist, char* cmdline, int32_t move_, Square
|
|||
square = static_cast<Square>(r * N_RANKS + s);
|
||||
}
|
||||
|
||||
if (rule.allowRemovePiecesRepeatedly) {
|
||||
if (rule.allowRemovePiecesRepeatedlyWhenCloseSameMill) {
|
||||
for (auto &mill : millList) {
|
||||
llp[0] = (mill & 0x000000ff00000000) >> 32;
|
||||
llp[1] = (mill & 0x0000000000ff0000) >> 16;
|
||||
|
@ -591,7 +591,7 @@ void Board::turn(vector <string> &cmdlist, char *cmdline, int32_t move_, Square
|
|||
square = static_cast<Square>(r * N_RANKS + s);
|
||||
}
|
||||
|
||||
if (rule.allowRemovePiecesRepeatedly) {
|
||||
if (rule.allowRemovePiecesRepeatedlyWhenCloseSameMill) {
|
||||
for (auto &mill : millList) {
|
||||
llp[0] = (mill & 0x000000ff00000000) >> 32;
|
||||
llp[1] = (mill & 0x0000000000ff0000) >> 16;
|
||||
|
@ -780,7 +780,7 @@ void Board::rotate(int degrees, vector<string> &cmdlist, char *cmdline, int32_t
|
|||
square = static_cast<Square>(r * N_RANKS + s);
|
||||
}
|
||||
|
||||
if (rule.allowRemovePiecesRepeatedly) {
|
||||
if (rule.allowRemovePiecesRepeatedlyWhenCloseSameMill) {
|
||||
for (auto &mill : millList) {
|
||||
llp[0] = (mill & 0x000000ff00000000) >> 32;
|
||||
llp[1] = (mill & 0x0000000000ff0000) >> 16;
|
||||
|
|
|
@ -463,7 +463,7 @@ bool Position::placePiece(Square square, bool updateCmdlist)
|
|||
// 如果成三
|
||||
else {
|
||||
// 设置去子数目
|
||||
nPiecesNeedRemove = rule.allowRemoveMultiPieces ? n : 1;
|
||||
nPiecesNeedRemove = rule.allowRemoveMultiPiecesWhenCloseMultiMill ? n : 1;
|
||||
|
||||
// 进入去子状态
|
||||
action = ACTION_REMOVE;
|
||||
|
@ -535,7 +535,7 @@ bool Position::placePiece(Square square, bool updateCmdlist)
|
|||
// 中局阶段成三
|
||||
else {
|
||||
// 设置去子数目
|
||||
nPiecesNeedRemove = rule.allowRemoveMultiPieces ? n : 1;
|
||||
nPiecesNeedRemove = rule.allowRemoveMultiPiecesWhenCloseMultiMill ? n : 1;
|
||||
|
||||
// 进入去子状态
|
||||
action = ACTION_REMOVE;
|
||||
|
@ -594,7 +594,7 @@ bool Position::removePiece(Square square, bool updateCmdlist)
|
|||
return false;
|
||||
|
||||
// 如果当前子是否处于“三连”之中,且对方还未全部处于“三连”之中
|
||||
if (!rule.allowRemoveMill &&
|
||||
if (!rule.allowRemovePieceInMill &&
|
||||
board.inHowManyMills(square, PLAYER_NOBODY) &&
|
||||
!board.isAllInMills(Player::getOpponent(sideToMove))) {
|
||||
return false;
|
||||
|
@ -984,7 +984,7 @@ bool Position::checkGameOverCondition(int8_t updateCmdlist)
|
|||
if (nPiecesOnBoard[BLACK] + nPiecesOnBoard[WHITE] >= Board::N_RANKS * Board::N_FILES) {
|
||||
phase = PHASE_GAMEOVER;
|
||||
|
||||
if (rule.isStartingPlayerLoseWhenBoardFull) {
|
||||
if (rule.isBlackLosebutNotDrawWhenBoardFull) {
|
||||
winner = PLAYER_WHITE;
|
||||
if (updateCmdlist) {
|
||||
sprintf(cmdline, "Player2 win!");
|
||||
|
@ -1008,7 +1008,7 @@ bool Position::checkGameOverCondition(int8_t updateCmdlist)
|
|||
// 规则要求被“闷”判负,则对手获胜 // TODO: 应该转移到下面的分支中
|
||||
phase = PHASE_GAMEOVER;
|
||||
|
||||
if (rule.isLoseWhenNoWay) {
|
||||
if (rule.isLoseButNotChangeTurnWhenNoWay) {
|
||||
if (updateCmdlist) {
|
||||
tips = "玩家" + Player::chToStr(chSide) + "无子可走被闷";
|
||||
winner = Player::getOpponent(sideToMove);
|
||||
|
|
|
@ -20,11 +20,8 @@
|
|||
#include "rule.h"
|
||||
#include "types.h"
|
||||
|
||||
// 当前使用的规则
|
||||
struct Rule rule;
|
||||
|
||||
// 对静态常量数组的定义要放在类外,不要放在头文件
|
||||
// 预定义的几套规则
|
||||
const struct Rule RULES[N_RULES] = {
|
||||
{
|
||||
"成三棋", // 成三棋
|
||||
|
|
|
@ -24,59 +24,25 @@
|
|||
|
||||
struct Rule
|
||||
{
|
||||
// 规则名称
|
||||
const char *name;
|
||||
|
||||
// 规则介绍
|
||||
const char *description;
|
||||
|
||||
// 任一方子数,各9子或各12子
|
||||
int nTotalPiecesEachSide;
|
||||
|
||||
// 赛点子数,少于则判负
|
||||
int nPiecesAtLeast;
|
||||
|
||||
// 是否有斜线
|
||||
int nTotalPiecesEachSide; // 9 or 12
|
||||
int nPiecesAtLeast; // Default is 3
|
||||
bool hasObliqueLines;
|
||||
|
||||
// 是否有禁点(摆棋阶段被提子的点不能再摆子)
|
||||
bool hasBannedLocations;
|
||||
|
||||
// 是否后摆棋者先行棋
|
||||
bool isDefenderMoveFirst;
|
||||
|
||||
// 相同顺序和位置的重复“三连”是否可反复提子
|
||||
bool allowRemovePiecesRepeatedly;
|
||||
|
||||
// 多个“三连”能否多提子
|
||||
bool allowRemoveMultiPieces;
|
||||
|
||||
// 能否提“三连”的子
|
||||
bool allowRemoveMill;
|
||||
|
||||
// 摆棋满子(闷棋,只有12子棋才出现),是否算先手负,false为和棋
|
||||
bool isStartingPlayerLoseWhenBoardFull;
|
||||
|
||||
// 走棋阶段不能行动(被“闷”)是否算负,false则轮空(由对手走棋)
|
||||
bool isLoseWhenNoWay;
|
||||
|
||||
// 剩三子时是否可以飞棋
|
||||
bool allowRemovePiecesRepeatedlyWhenCloseSameMill;
|
||||
bool allowRemoveMultiPiecesWhenCloseMultiMill;
|
||||
bool allowRemovePieceInMill;
|
||||
bool isBlackLosebutNotDrawWhenBoardFull;
|
||||
bool isLoseButNotChangeTurnWhenNoWay;
|
||||
bool allowFlyWhenRemainThreePieces;
|
||||
|
||||
// 最大步数,超出判和
|
||||
Step maxStepsLedToDraw;
|
||||
|
||||
// 包干最长时间(秒),超出判负,为0则不计时
|
||||
int maxTimeLedToLose;
|
||||
};
|
||||
|
||||
// 预定义的规则数目
|
||||
#define N_RULES 5
|
||||
|
||||
// 预定义的规则
|
||||
extern const struct Rule RULES[N_RULES];
|
||||
|
||||
// 当前规则
|
||||
extern struct Rule rule;
|
||||
|
||||
#endif /* RULE_H */
|
||||
|
|
|
@ -147,20 +147,14 @@ enum Rating : int8_t
|
|||
|
||||
enum PieceType : uint16_t
|
||||
{
|
||||
NO_PIECE_TYPE = 0, // 没有棋子
|
||||
BLACK_STONE = 1, // 先手的子
|
||||
WHITE_STONE = 2, // 后手的子
|
||||
BAN = 3, // 禁点
|
||||
ALL_PIECES = 0, // 禁点
|
||||
NO_PIECE_TYPE = 0,
|
||||
BLACK_STONE = 1,
|
||||
WHITE_STONE = 2,
|
||||
BAN = 3,
|
||||
ALL_PIECES = 0,
|
||||
PIECE_TYPE_NB = 4
|
||||
};
|
||||
|
||||
/*
|
||||
0x00 代表无棋子
|
||||
0x0F 代表禁点
|
||||
0x11~0x1C 代表先手第 1~12 子
|
||||
0x21~0x2C 代表后手第 1~12 子
|
||||
*/
|
||||
enum Piece
|
||||
{
|
||||
NO_PIECE = 0x00,
|
||||
|
@ -240,13 +234,11 @@ enum LineDirection
|
|||
LD_NB = 3
|
||||
};
|
||||
|
||||
// 圈
|
||||
enum File : int
|
||||
{
|
||||
FILE_A = 1, FILE_B, FILE_C, FILE_NB = 3
|
||||
};
|
||||
|
||||
// 位
|
||||
enum Rank : int
|
||||
{
|
||||
RANK_1, RANK_2, RANK_3, RANK_4, RANK_5, RANK_6, RANK_7, RANK_8, RANK_NB = 8
|
||||
|
|
|
@ -211,7 +211,7 @@ void GameController::gameReset()
|
|||
newP->setNum(i + 1);
|
||||
|
||||
// 如果重复三连不可用,则显示棋子序号,九连棋专用玩法
|
||||
if (!(rule.allowRemovePiecesRepeatedly))
|
||||
if (!(rule.allowRemovePiecesRepeatedlyWhenCloseSameMill))
|
||||
newP->setShowNum(true);
|
||||
|
||||
pieceList.push_back(newP);
|
||||
|
@ -225,7 +225,7 @@ void GameController::gameReset()
|
|||
newP->setNum(i + 1);
|
||||
|
||||
// 如果重复三连不可用,则显示棋子序号,九连棋专用玩法
|
||||
if (!(rule.allowRemovePiecesRepeatedly))
|
||||
if (!(rule.allowRemovePiecesRepeatedlyWhenCloseSameMill))
|
||||
newP->setShowNum(true);
|
||||
|
||||
pieceList.push_back(newP);
|
||||
|
|
Loading…
Reference in New Issue