rule: rule 不再使用指针形式
This commit is contained in:
parent
3ece8b3cc8
commit
22adca36d5
|
@ -124,21 +124,21 @@ Value Evaluation<T>::value()
|
|||
case PHASE_GAMEOVER:
|
||||
if (pos.pieces_count_on_board(BLACK) + pos.pieces_count_on_board(WHITE) >=
|
||||
RANK_NB * FILE_NB) {
|
||||
if (rule->isBlackLoseButNotDrawWhenBoardFull) {
|
||||
if (rule.isBlackLoseButNotDrawWhenBoardFull) {
|
||||
value -= VALUE_MATE;
|
||||
} else {
|
||||
value = VALUE_DRAW;
|
||||
}
|
||||
} else if (pos.get_action() == ACTION_SELECT &&
|
||||
pos.is_all_surrounded() &&
|
||||
rule->isLoseButNotChangeSideWhenNoWay) {
|
||||
rule.isLoseButNotChangeSideWhenNoWay) {
|
||||
Value delta = pos.side_to_move() == BLACK ? -VALUE_MATE : VALUE_MATE;
|
||||
value += delta;
|
||||
}
|
||||
|
||||
else if (pos.pieces_count_on_board(BLACK) < rule->nPiecesAtLeast) {
|
||||
else if (pos.pieces_count_on_board(BLACK) < rule.nPiecesAtLeast) {
|
||||
value -= VALUE_MATE;
|
||||
} else if (pos.pieces_count_on_board(WHITE) < rule->nPiecesAtLeast) {
|
||||
} else if (pos.pieces_count_on_board(WHITE) < rule.nPiecesAtLeast) {
|
||||
value += VALUE_MATE;
|
||||
}
|
||||
|
||||
|
|
|
@ -73,8 +73,8 @@ ExtMove *generate<LEGAL>(/* const */ Position &pos, ExtMove *moveList)
|
|||
continue;
|
||||
}
|
||||
|
||||
if (pos.pieces_count_on_board(pos.side_to_move()) > rule->nPiecesAtLeast ||
|
||||
!rule->allowFlyWhenRemainThreePieces) {
|
||||
if (pos.pieces_count_on_board(pos.side_to_move()) > rule.nPiecesAtLeast ||
|
||||
!rule.allowFlyWhenRemainThreePieces) {
|
||||
for (int direction = MD_BEGIN; direction < MD_NB; direction++) {
|
||||
newSquare = static_cast<Square>(MoveList<LEGAL>::moveTable[oldSquare][direction]);
|
||||
if (newSquare && !pos.get_board()[newSquare]) {
|
||||
|
@ -110,7 +110,7 @@ ExtMove *generate<LEGAL>(/* const */ Position &pos, ExtMove *moveList)
|
|||
for (int i = MOVE_PRIORITY_TABLE_SIZE - 1; i >= 0; i--) {
|
||||
s = MoveList<LEGAL>::movePriorityTable[i];
|
||||
if (pos.get_board()[s] & make_piece(them)) {
|
||||
if (rule->allowRemovePieceInMill || !pos.in_how_many_mills(s, NOBODY)) {
|
||||
if (rule.allowRemovePieceInMill || !pos.in_how_many_mills(s, NOBODY)) {
|
||||
*cur++ = (Move)-s;
|
||||
}
|
||||
}
|
||||
|
@ -228,7 +228,7 @@ void MoveList<LEGAL>::create()
|
|||
/* 39 */ {0, 0, 0, 0},
|
||||
};
|
||||
|
||||
if (rule->hasObliqueLines) {
|
||||
if (rule.hasObliqueLines) {
|
||||
memcpy(moveTable, moveTable_obliqueLine, sizeof(moveTable));
|
||||
} else {
|
||||
memcpy(moveTable, moveTable_noObliqueLine, sizeof(moveTable));
|
||||
|
@ -259,7 +259,7 @@ void MoveList<LEGAL>::shuffle()
|
|||
std::array<Square, 4> movePriorityTable2 = { SQ_16, SQ_18, SQ_20, SQ_22 };
|
||||
std::array<Square, 8> movePriorityTable3 = { SQ_24, SQ_26, SQ_28, SQ_30, SQ_8, SQ_10, SQ_12, SQ_14 };
|
||||
|
||||
if (rule->nTotalPiecesEachSide == 9)
|
||||
if (rule.nTotalPiecesEachSide == 9)
|
||||
{
|
||||
movePriorityTable0 = { SQ_16, SQ_18, SQ_20, SQ_22 };
|
||||
movePriorityTable1 = { SQ_24, SQ_26, SQ_28, SQ_30, SQ_8, SQ_10, SQ_12, SQ_14 };
|
||||
|
|
|
@ -66,7 +66,7 @@ void MovePicker::score()
|
|||
int nTheirMills = 0;
|
||||
|
||||
#ifndef SORT_MOVE_WITHOUT_HUMAN_KNOWLEDGES
|
||||
// TODO: rule->allowRemoveMultiPiecesWhenCloseMultiMill adapt other rules
|
||||
// TODO: rule.allowRemoveMultiPiecesWhenCloseMultiMill adapt other rules
|
||||
if (type_of(m) != MOVETYPE_REMOVE) {
|
||||
// all phrase, check if place sq can close mill
|
||||
if (nOurMills > 0) {
|
||||
|
@ -91,7 +91,7 @@ void MovePicker::score()
|
|||
|
||||
if (sq % 2 == 0 && nTheirPieces == 3) {
|
||||
cur->value += RATING_BLOCK_ONE_MILL * nTheirMills;
|
||||
} else if (sq % 2 == 1 && nTheirPieces == 2 && rule->nTotalPiecesEachSide == 12) {
|
||||
} else if (sq % 2 == 1 && nTheirPieces == 2 && rule.nTotalPiecesEachSide == 12) {
|
||||
cur->value += RATING_BLOCK_ONE_MILL * nTheirMills;
|
||||
}
|
||||
}
|
||||
|
@ -101,7 +101,7 @@ void MovePicker::score()
|
|||
//cur->value += nBanned; // placing phrase, place nearby ban point
|
||||
|
||||
// for 12 men, white 's 2nd move place star point is as important as close mill (TODO)
|
||||
if (rule->nTotalPiecesEachSide == 12 &&
|
||||
if (rule.nTotalPiecesEachSide == 12 &&
|
||||
pos.count<ON_BOARD>(WHITE) < 2 && // patch: only when white's 2nd move
|
||||
Position::is_star_square(static_cast<Square>(m))) {
|
||||
cur->value += RATING_STAR_SQUARE;
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
#include "uci.h"
|
||||
|
||||
#include "option.h"
|
||||
#include "rule.h"
|
||||
|
||||
using std::string;
|
||||
|
||||
|
@ -167,10 +168,9 @@ void Position::init()
|
|||
Position::Position()
|
||||
{
|
||||
construct_key();
|
||||
|
||||
if (rule == nullptr) {
|
||||
set_position(&RULES[DEFAULT_RULE_NUMBER]);
|
||||
}
|
||||
|
||||
// TODO: Do not need to set again
|
||||
set_position(DEFAULT_RULE_NUMBER);
|
||||
|
||||
score[BLACK] = score[WHITE] = score_draw = nPlayed = 0;
|
||||
|
||||
|
@ -574,7 +574,7 @@ Key Position::key_after(Move m) const
|
|||
if (mt == MOVETYPE_REMOVE) {
|
||||
k ^= Zobrist::psq[~side_to_move()][s];
|
||||
|
||||
if (rule->hasBannedLocations && phase == PHASE_PLACING) {
|
||||
if (rule.hasBannedLocations && phase == PHASE_PLACING) {
|
||||
k ^= Zobrist::psq[BAN][s];
|
||||
}
|
||||
|
||||
|
@ -692,8 +692,8 @@ int Position::pieces_on_board_count()
|
|||
}
|
||||
}
|
||||
|
||||
if (pieceCountOnBoard[BLACK] > rule->nTotalPiecesEachSide ||
|
||||
pieceCountOnBoard[WHITE] > rule->nTotalPiecesEachSide) {
|
||||
if (pieceCountOnBoard[BLACK] > rule.nTotalPiecesEachSide ||
|
||||
pieceCountOnBoard[WHITE] > rule.nTotalPiecesEachSide) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -702,15 +702,16 @@ int Position::pieces_on_board_count()
|
|||
|
||||
int Position::pieces_in_hand_count()
|
||||
{
|
||||
pieceCountInHand[BLACK] = rule->nTotalPiecesEachSide - pieceCountOnBoard[BLACK];
|
||||
pieceCountInHand[WHITE] = rule->nTotalPiecesEachSide - pieceCountOnBoard[WHITE];
|
||||
pieceCountInHand[BLACK] = rule.nTotalPiecesEachSide - pieceCountOnBoard[BLACK];
|
||||
pieceCountInHand[WHITE] = rule.nTotalPiecesEachSide - pieceCountOnBoard[WHITE];
|
||||
|
||||
return pieceCountInHand[BLACK] + pieceCountInHand[WHITE];
|
||||
}
|
||||
|
||||
int Position::set_position(/* const */ struct Rule *newRule)
|
||||
int Position::set_position(int ruleNo)
|
||||
{
|
||||
rule = newRule;
|
||||
memset(&rule, 0, sizeof(Rule));
|
||||
memcpy(&rule, &RULES[ruleNo], sizeof(Rule));
|
||||
|
||||
gamePly = 0;
|
||||
st.rule50 = 0;
|
||||
|
@ -737,7 +738,7 @@ int Position::set_position(/* const */ struct Rule *newRule)
|
|||
|
||||
int r;
|
||||
for (r = 0; r < N_RULES; r++) {
|
||||
if (strcmp(rule->name, RULES[r].name) == 0)
|
||||
if (strcmp(rule.name, RULES[r].name) == 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
|
@ -768,12 +769,8 @@ bool Position::reset()
|
|||
st.key = 0;
|
||||
memset(byTypeBB, 0, sizeof(byTypeBB));
|
||||
|
||||
if (rule == nullptr) {
|
||||
|
||||
}
|
||||
|
||||
pieceCountOnBoard[BLACK] = pieceCountOnBoard[WHITE] = 0;
|
||||
pieceCountInHand[BLACK] = pieceCountInHand[WHITE] = rule->nTotalPiecesEachSide;
|
||||
pieceCountInHand[BLACK] = pieceCountInHand[WHITE] = rule.nTotalPiecesEachSide;
|
||||
pieceCountNeedRemove = 0;
|
||||
millListSize = 0;
|
||||
currentSquare = SQ_0;
|
||||
|
@ -787,12 +784,12 @@ bool Position::reset()
|
|||
int i;
|
||||
|
||||
for (i = 0; i < N_RULES; i++) {
|
||||
if (strcmp(rule->name, RULES[i].name) == 0)
|
||||
if (strcmp(rule.name, RULES[i].name) == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
if (sprintf(cmdline, "r%1u s%03u t%02u",
|
||||
i + 1, rule->maxStepsLedToDraw, 0) > 0) {
|
||||
i + 1, rule.maxStepsLedToDraw, 0) > 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -838,7 +835,7 @@ bool Position::put_piece(Square s, bool updateCmdlist)
|
|||
}
|
||||
|
||||
if (phase == PHASE_PLACING) {
|
||||
piece = (Piece)((0x01 | make_piece(sideToMove)) + rule->nTotalPiecesEachSide - pieceCountInHand[us]);
|
||||
piece = (Piece)((0x01 | make_piece(sideToMove)) + rule.nTotalPiecesEachSide - pieceCountInHand[us]);
|
||||
pieceCountInHand[us]--;
|
||||
pieceCountOnBoard[us]++;
|
||||
|
||||
|
@ -868,11 +865,11 @@ bool Position::put_piece(Square s, bool updateCmdlist)
|
|||
phase = PHASE_MOVING;
|
||||
action = ACTION_SELECT;
|
||||
|
||||
if (rule->hasBannedLocations) {
|
||||
if (rule.hasBannedLocations) {
|
||||
remove_ban_stones();
|
||||
}
|
||||
|
||||
if (!rule->isDefenderMoveFirst) {
|
||||
if (!rule.isDefenderMoveFirst) {
|
||||
change_side_to_move();
|
||||
}
|
||||
|
||||
|
@ -883,7 +880,7 @@ bool Position::put_piece(Square s, bool updateCmdlist)
|
|||
change_side_to_move();
|
||||
}
|
||||
} else {
|
||||
pieceCountNeedRemove = rule->allowRemoveMultiPiecesWhenCloseMultiMill ? n : 1;
|
||||
pieceCountNeedRemove = rule.allowRemoveMultiPiecesWhenCloseMultiMill ? n : 1;
|
||||
update_key_misc();
|
||||
action = ACTION_REMOVE;
|
||||
}
|
||||
|
@ -895,8 +892,8 @@ bool Position::put_piece(Square s, bool updateCmdlist)
|
|||
}
|
||||
|
||||
// if illegal
|
||||
if (pieceCountOnBoard[sideToMove] > rule->nPiecesAtLeast ||
|
||||
!rule->allowFlyWhenRemainThreePieces) {
|
||||
if (pieceCountOnBoard[sideToMove] > rule.nPiecesAtLeast ||
|
||||
!rule.allowFlyWhenRemainThreePieces) {
|
||||
int md;
|
||||
|
||||
for (md = 0; md < MD_NB; md++) {
|
||||
|
@ -940,7 +937,7 @@ bool Position::put_piece(Square s, bool updateCmdlist)
|
|||
return true;
|
||||
}
|
||||
} else {
|
||||
pieceCountNeedRemove = rule->allowRemoveMultiPiecesWhenCloseMultiMill ? n : 1;
|
||||
pieceCountNeedRemove = rule.allowRemoveMultiPiecesWhenCloseMultiMill ? n : 1;
|
||||
update_key_misc();
|
||||
action = ACTION_REMOVE;
|
||||
}
|
||||
|
@ -966,7 +963,7 @@ bool Position::remove_piece(Square s, bool updateCmdlist)
|
|||
if (!(make_piece(~side_to_move()) & board[s]))
|
||||
return false;
|
||||
|
||||
if (!rule->allowRemovePieceInMill &&
|
||||
if (!rule.allowRemovePieceInMill &&
|
||||
in_how_many_mills(s, NOBODY) &&
|
||||
!is_all_in_mills(~sideToMove)) {
|
||||
return false;
|
||||
|
@ -974,7 +971,7 @@ bool Position::remove_piece(Square s, bool updateCmdlist)
|
|||
|
||||
revert_key(s);
|
||||
|
||||
if (rule->hasBannedLocations && phase == PHASE_PLACING) {
|
||||
if (rule.hasBannedLocations && phase == PHASE_PLACING) {
|
||||
board[s]= BAN_STONE;
|
||||
update_key(s);
|
||||
byTypeBB[them] ^= s;
|
||||
|
@ -992,7 +989,7 @@ bool Position::remove_piece(Square s, bool updateCmdlist)
|
|||
|
||||
pieceCountOnBoard[them]--;
|
||||
|
||||
if (pieceCountOnBoard[them] + pieceCountInHand[them] < rule->nPiecesAtLeast) {
|
||||
if (pieceCountOnBoard[them] + pieceCountInHand[them] < rule.nPiecesAtLeast) {
|
||||
set_gameover(sideToMove, LOSE_REASON_LESS_THAN_THREE);
|
||||
return true;
|
||||
}
|
||||
|
@ -1011,11 +1008,11 @@ bool Position::remove_piece(Square s, bool updateCmdlist)
|
|||
phase = PHASE_MOVING;
|
||||
action = ACTION_SELECT;
|
||||
|
||||
if (rule->hasBannedLocations) {
|
||||
if (rule.hasBannedLocations) {
|
||||
remove_ban_stones();
|
||||
}
|
||||
|
||||
if (rule->isDefenderMoveFirst) {
|
||||
if (rule.isDefenderMoveFirst) {
|
||||
goto check;
|
||||
}
|
||||
} else {
|
||||
|
@ -1068,19 +1065,19 @@ bool Position::resign(Color loser)
|
|||
|
||||
bool Position::command(const char *cmd)
|
||||
{
|
||||
unsigned int ruleIndex;
|
||||
unsigned int ruleNo;
|
||||
unsigned t;
|
||||
int step;
|
||||
File file1, file2;
|
||||
Rank rank1, rank2;
|
||||
int args = 0;
|
||||
|
||||
if (sscanf(cmd, "r%1u s%3d t%2u", &ruleIndex, &step, &t) == 3) {
|
||||
if (ruleIndex <= 0 || ruleIndex > N_RULES) {
|
||||
if (sscanf(cmd, "r%1u s%3d t%2u", &ruleNo, &step, &t) == 3) {
|
||||
if (ruleNo <= 0 || ruleNo > N_RULES) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return set_position(&RULES[ruleIndex - 1]) >= 0 ? true : false;
|
||||
return set_position(ruleNo - 1) >= 0 ? true : false;
|
||||
}
|
||||
|
||||
args = sscanf(cmd, "(%1u,%1u)->(%1u,%1u)", (unsigned*)&file1, (unsigned*)&rank1, (unsigned*)&file2, (unsigned*)&rank2);
|
||||
|
@ -1153,8 +1150,8 @@ bool Position::check_gameover_condition()
|
|||
return true;
|
||||
}
|
||||
|
||||
if (rule->maxStepsLedToDraw > 0 &&
|
||||
st.rule50 > rule->maxStepsLedToDraw) {
|
||||
if (rule.maxStepsLedToDraw > 0 &&
|
||||
st.rule50 > rule.maxStepsLedToDraw) {
|
||||
winner = DRAW;
|
||||
phase = PHASE_GAMEOVER;
|
||||
gameoverReason = DRAW_REASON_RULE_50;
|
||||
|
@ -1162,7 +1159,7 @@ bool Position::check_gameover_condition()
|
|||
}
|
||||
|
||||
if (pieceCountOnBoard[BLACK] + pieceCountOnBoard[WHITE] >= RANK_NB * FILE_NB) {
|
||||
if (rule->isBlackLoseButNotDrawWhenBoardFull) {
|
||||
if (rule.isBlackLoseButNotDrawWhenBoardFull) {
|
||||
set_gameover(WHITE, LOSE_REASON_BOARD_IS_FULL);
|
||||
} else {
|
||||
set_gameover(DRAW, DRAW_REASON_BOARD_IS_FULL);
|
||||
|
@ -1172,7 +1169,7 @@ bool Position::check_gameover_condition()
|
|||
}
|
||||
|
||||
if (phase == PHASE_MOVING && action == ACTION_SELECT && is_all_surrounded()) {
|
||||
if (rule->isLoseButNotChangeSideWhenNoWay) {
|
||||
if (rule.isLoseButNotChangeSideWhenNoWay) {
|
||||
set_gameover(~sideToMove, LOSE_REASON_NO_WAY);
|
||||
return true;
|
||||
} else {
|
||||
|
@ -1209,7 +1206,7 @@ int Position::get_mobility_diff(bool includeFobidden)
|
|||
|
||||
void Position::remove_ban_stones()
|
||||
{
|
||||
assert(rule->hasBannedLocations);
|
||||
assert(rule.hasBannedLocations);
|
||||
|
||||
Square s = SQ_0;
|
||||
|
||||
|
@ -1415,7 +1412,8 @@ void Position::create_mill_table()
|
|||
/* 39 */ {{0, 0}, {0, 0}, {0, 0}}
|
||||
};
|
||||
|
||||
if (rule->hasObliqueLines) {
|
||||
// TODO: change to ptr?
|
||||
if (rule.hasObliqueLines) {
|
||||
memcpy(millTable, millTable_hasObliqueLines, sizeof(millTable));
|
||||
} else {
|
||||
memcpy(millTable, millTable_noObliqueLine, sizeof(millTable));
|
||||
|
@ -1540,12 +1538,12 @@ bool Position::is_all_in_mills(Color c)
|
|||
// Stat include ban
|
||||
int Position::surrounded_empty_squares_count(Square s, bool includeFobidden)
|
||||
{
|
||||
//assert(rule->hasBannedLocations == includeFobidden);
|
||||
//assert(rule.hasBannedLocations == includeFobidden);
|
||||
|
||||
int n = 0;
|
||||
|
||||
if (pieceCountOnBoard[sideToMove] > rule->nPiecesAtLeast ||
|
||||
!rule->allowFlyWhenRemainThreePieces) {
|
||||
if (pieceCountOnBoard[sideToMove] > rule.nPiecesAtLeast ||
|
||||
!rule.allowFlyWhenRemainThreePieces) {
|
||||
Square moveSquare;
|
||||
for (MoveDirection d = MD_BEGIN; d < MD_NB; d = (MoveDirection)(d + 1)) {
|
||||
moveSquare = static_cast<Square>(MoveList<LEGAL>::moveTable[s][d]);
|
||||
|
@ -1599,8 +1597,8 @@ bool Position::is_all_surrounded() const
|
|||
return true;
|
||||
|
||||
// Can fly
|
||||
if (pieceCountOnBoard[sideToMove] <= rule->nPiecesAtLeast &&
|
||||
rule->allowFlyWhenRemainThreePieces) {
|
||||
if (pieceCountOnBoard[sideToMove] <= rule.nPiecesAtLeast &&
|
||||
rule.allowFlyWhenRemainThreePieces) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1624,7 +1622,7 @@ bool Position::is_all_surrounded() const
|
|||
|
||||
bool Position::is_star_square(Square s)
|
||||
{
|
||||
if (rule->hasObliqueLines == true) {
|
||||
if (rule.hasObliqueLines == true) {
|
||||
return (s == 17 ||
|
||||
s == 19 ||
|
||||
s == 21 ||
|
||||
|
@ -1639,7 +1637,7 @@ bool Position::is_star_square(Square s)
|
|||
|
||||
void Position::print_board()
|
||||
{
|
||||
if (rule->nTotalPiecesEachSide == 12) {
|
||||
if (rule.nTotalPiecesEachSide == 12) {
|
||||
printf("\n"
|
||||
"31 ----- 24 ----- 25\n"
|
||||
"| \\ | / |\n"
|
||||
|
|
|
@ -104,7 +104,7 @@ public:
|
|||
|
||||
/// Mill Game
|
||||
|
||||
int set_position(/* const */ struct Rule *rule);
|
||||
int set_position(int ruleNo);
|
||||
|
||||
Piece *get_board();
|
||||
Square current_square() const;
|
||||
|
|
24
src/rule.cpp
24
src/rule.cpp
|
@ -20,10 +20,30 @@
|
|||
#include "rule.h"
|
||||
#include "types.h"
|
||||
|
||||
/* const */ struct Rule *rule;
|
||||
struct Rule rule = {
|
||||
"打三棋(12连棋)", // 打三棋
|
||||
// 规则说明
|
||||
"1. 双方各12颗子,棋盘有斜线;\n"
|
||||
"2. 摆棋阶段被提子的位置不能再摆子,直到走棋阶段;\n"
|
||||
"3. 摆棋阶段,摆满棋盘算先手负;\n"
|
||||
"4. 走棋阶段,后摆棋的一方先走;\n"
|
||||
"5. 同时出现两个“三连”只能提一子;\n"
|
||||
"6. 其它规则与成三棋基本相同。",
|
||||
12, // 双方各12子
|
||||
3, // 赛点子数为3
|
||||
true, // 有斜线
|
||||
true, // 有禁点,摆棋阶段被提子的点不能再摆子
|
||||
true, // 后摆棋者先行棋
|
||||
false, // 多个“三连”只能提一子
|
||||
true, // 可以提对手的“三连”子
|
||||
true, // 摆棋满子(闷棋,只有12子棋才出现)算先手负
|
||||
true, // 走棋阶段不能行动(被“闷”)算负
|
||||
false, // 剩三子时不可以飞棋
|
||||
0 // 50步
|
||||
};
|
||||
|
||||
// TODO
|
||||
/* const */ struct Rule RULES[N_RULES] = {
|
||||
const struct Rule RULES[N_RULES] = {
|
||||
{
|
||||
"成三棋", // 成三棋
|
||||
// 规则说明
|
||||
|
|
|
@ -24,8 +24,8 @@
|
|||
|
||||
struct Rule
|
||||
{
|
||||
const char *name;
|
||||
const char *description;
|
||||
const char name[32];
|
||||
const char description[512];
|
||||
int nTotalPiecesEachSide; // 9 or 12
|
||||
int nPiecesAtLeast; // Default is 3
|
||||
bool hasObliqueLines;
|
||||
|
@ -40,7 +40,7 @@ struct Rule
|
|||
};
|
||||
|
||||
#define N_RULES 4
|
||||
extern /* const */ struct Rule RULES[N_RULES]; // TODO
|
||||
extern /* const */ struct Rule *rule;
|
||||
extern const struct Rule RULES[N_RULES];
|
||||
extern struct Rule rule;
|
||||
|
||||
#endif /* RULE_H */
|
||||
|
|
|
@ -440,9 +440,9 @@ Depth Thread::adjustDepth()
|
|||
const Depth flyingDepth = 9;
|
||||
|
||||
if (rootPos->phase & PHASE_PLACING) {
|
||||
int index = rule->nTotalPiecesEachSide * 2 - rootPos->count<IN_HAND>(BLACK) - rootPos->count<IN_HAND>(WHITE);
|
||||
int index = rule.nTotalPiecesEachSide * 2 - rootPos->count<IN_HAND>(BLACK) - rootPos->count<IN_HAND>(WHITE);
|
||||
|
||||
if (rule->nTotalPiecesEachSide == 12) {
|
||||
if (rule.nTotalPiecesEachSide == 12) {
|
||||
assert(0 <= index && index <= 24);
|
||||
d = placingDepthTable_12[index];
|
||||
} else {
|
||||
|
@ -469,14 +469,14 @@ Depth Thread::adjustDepth()
|
|||
}
|
||||
|
||||
// Can fly
|
||||
if (rule->allowFlyWhenRemainThreePieces) {
|
||||
if (pb == rule->nPiecesAtLeast ||
|
||||
pw == rule->nPiecesAtLeast) {
|
||||
if (rule.allowFlyWhenRemainThreePieces) {
|
||||
if (pb == rule.nPiecesAtLeast ||
|
||||
pw == rule.nPiecesAtLeast) {
|
||||
d = flyingDepth;
|
||||
}
|
||||
|
||||
if (pb == rule->nPiecesAtLeast &&
|
||||
pw == rule->nPiecesAtLeast) {
|
||||
if (pb == rule.nPiecesAtLeast &&
|
||||
pw == rule.nPiecesAtLeast) {
|
||||
d = flyingDepth / 2;
|
||||
}
|
||||
}
|
||||
|
@ -503,7 +503,7 @@ Depth Thread::adjustDepth()
|
|||
|
||||
void Thread::clearTT()
|
||||
{
|
||||
if (strcmp(rule->name, rule->name) != 0) {
|
||||
if (strcmp(rule.name, rule.name) != 0) {
|
||||
#ifdef TRANSPOSITION_TABLE_ENABLE
|
||||
TranspositionTable::clear();
|
||||
#endif // TRANSPOSITION_TABLE_ENABLE
|
||||
|
|
|
@ -35,7 +35,7 @@ using std::string;
|
|||
|
||||
UCI::OptionsMap Options; // Global object
|
||||
|
||||
extern struct Rule *rule;
|
||||
extern struct Rule rule;
|
||||
|
||||
namespace UCI
|
||||
{
|
||||
|
@ -72,57 +72,57 @@ void on_random_move(const Option &o)
|
|||
|
||||
void on_nTotalPiecesEachSide(const Option &o)
|
||||
{
|
||||
rule->nTotalPiecesEachSide = (int)o;
|
||||
rule.nTotalPiecesEachSide = (int)o;
|
||||
}
|
||||
|
||||
void on_nPiecesAtLeast(const Option &o)
|
||||
{
|
||||
rule->nPiecesAtLeast = (int)o;
|
||||
rule.nPiecesAtLeast = (int)o;
|
||||
}
|
||||
|
||||
void on_hasObliqueLines(const Option &o)
|
||||
{
|
||||
rule->hasObliqueLines = (bool)o;
|
||||
rule.hasObliqueLines = (bool)o;
|
||||
}
|
||||
|
||||
void on_hasBannedLocations(const Option &o)
|
||||
{
|
||||
rule->hasBannedLocations = (bool)o;
|
||||
rule.hasBannedLocations = (bool)o;
|
||||
}
|
||||
|
||||
void on_isDefenderMoveFirst(const Option &o)
|
||||
{
|
||||
rule->isDefenderMoveFirst = (bool)o;
|
||||
rule.isDefenderMoveFirst = (bool)o;
|
||||
}
|
||||
|
||||
void on_allowRemoveMultiPiecesWhenCloseMultiMill(const Option &o)
|
||||
{
|
||||
rule->allowRemoveMultiPiecesWhenCloseMultiMill = (bool)o;
|
||||
rule.allowRemoveMultiPiecesWhenCloseMultiMill = (bool)o;
|
||||
}
|
||||
|
||||
void on_allowRemovePieceInMill(const Option &o)
|
||||
{
|
||||
rule->allowRemovePieceInMill = (bool)o;
|
||||
rule.allowRemovePieceInMill = (bool)o;
|
||||
}
|
||||
|
||||
void on_isBlackLoseButNotDrawWhenBoardFull(const Option &o)
|
||||
{
|
||||
rule->isBlackLoseButNotDrawWhenBoardFull = (bool)o;
|
||||
rule.isBlackLoseButNotDrawWhenBoardFull = (bool)o;
|
||||
}
|
||||
|
||||
void on_isLoseButNotChangeSideWhenNoWay(const Option &o)
|
||||
{
|
||||
rule->isLoseButNotChangeSideWhenNoWay = (bool)o;
|
||||
rule.isLoseButNotChangeSideWhenNoWay = (bool)o;
|
||||
}
|
||||
|
||||
void on_allowFlyWhenRemainThreePieces(const Option &o)
|
||||
{
|
||||
rule->allowFlyWhenRemainThreePieces = (bool)o;
|
||||
rule.allowFlyWhenRemainThreePieces = (bool)o;
|
||||
}
|
||||
|
||||
void on_maxStepsLedToDraw(const Option &o)
|
||||
{
|
||||
rule->maxStepsLedToDraw = (int)o;
|
||||
rule.maxStepsLedToDraw = (int)o;
|
||||
}
|
||||
|
||||
/// Our case insensitive less() function as required by UCI protocol
|
||||
|
@ -171,7 +171,7 @@ void init(OptionsMap &o)
|
|||
o["isBlackLoseButNotDrawWhenBoardFull"] << Option(true, on_isBlackLoseButNotDrawWhenBoardFull);
|
||||
o["isLoseButNotChangeSideWhenNoWay"] << Option(true, on_isLoseButNotChangeSideWhenNoWay);
|
||||
o["allowFlyWhenRemainThreePieces"] << Option(false, on_allowFlyWhenRemainThreePieces);
|
||||
o["maxStepsLedToDraw"] << Option(50, on_maxStepsLedToDraw);
|
||||
o["maxStepsLedToDraw"] << Option(50, 30, 50, on_maxStepsLedToDraw);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -225,7 +225,7 @@ void Game::gameReset()
|
|||
currentPiece = nullptr;
|
||||
|
||||
// 重新绘制棋盘
|
||||
scene.setDiagonal(rule->hasObliqueLines);
|
||||
scene.setDiagonal(rule.hasObliqueLines);
|
||||
|
||||
// 绘制所有棋子,放在起始位置
|
||||
// 0: 先手第1子; 1:后手第1子
|
||||
|
@ -234,7 +234,7 @@ void Game::gameReset()
|
|||
PieceItem::Models md;
|
||||
PieceItem *newP;
|
||||
|
||||
for (int i = 0; i < rule->nTotalPiecesEachSide; i++) {
|
||||
for (int i = 0; i < rule.nTotalPiecesEachSide; i++) {
|
||||
// 先手的棋子
|
||||
md = isInverted ? PieceItem::whitePiece : PieceItem::blackPiece;
|
||||
newP = new PieceItem;
|
||||
|
@ -259,7 +259,7 @@ void Game::gameReset()
|
|||
}
|
||||
|
||||
// 读取规则限时要求
|
||||
timeLimit = 0; // TODO: rule->maxTimeLedToLose;
|
||||
timeLimit = 0; // TODO: rule.maxTimeLedToLose;
|
||||
|
||||
// 如果规则不要求计时,则time1和time2表示已用时间
|
||||
if (timeLimit <= 0) {
|
||||
|
@ -353,11 +353,11 @@ void Game::setRule(int ruleNo, int stepLimited /*= -1*/, int timeLimited /*= -1*
|
|||
}
|
||||
|
||||
// 设置模型规则,重置游戏
|
||||
int r = position.set_position(&RULES[ruleNo]);
|
||||
int r = position.set_position(ruleNo);
|
||||
elapsedSeconds[BLACK] = elapsedSeconds[WHITE] = 0;
|
||||
|
||||
char cmdline[64] = { 0 };
|
||||
if (sprintf(cmdline, "r%1u s%03u t%02u", r + 1, rule->maxStepsLedToDraw, 0) <= 0) {
|
||||
if (sprintf(cmdline, "r%1u s%03u t%02u", r + 1, rule.maxStepsLedToDraw, 0) <= 0) {
|
||||
assert(0);
|
||||
}
|
||||
string cmd(cmdline);
|
||||
|
@ -1234,7 +1234,7 @@ bool Game::updateScence(Position &p)
|
|||
int key;
|
||||
|
||||
// 棋子总数
|
||||
int nTotalPieces = rule->nTotalPiecesEachSide * 2;
|
||||
int nTotalPieces = rule.nTotalPiecesEachSide * 2;
|
||||
|
||||
// 动画组
|
||||
auto *animationGroup = new QParallelAnimationGroup;
|
||||
|
@ -1311,7 +1311,7 @@ bool Game::updateScence(Position &p)
|
|||
}
|
||||
|
||||
// 添加摆棋阶段禁子点
|
||||
if (rule->hasBannedLocations && p.get_phase() == PHASE_PLACING) {
|
||||
if (rule.hasBannedLocations && p.get_phase() == PHASE_PLACING) {
|
||||
for (int j = SQ_BEGIN; j < SQ_END; j++) {
|
||||
if (board[j] == BAN_STONE) {
|
||||
pos = scene.polar2pos(File(j / RANK_NB), Rank(j % RANK_NB + 1));
|
||||
|
@ -1330,7 +1330,7 @@ bool Game::updateScence(Position &p)
|
|||
}
|
||||
|
||||
// 走棋阶段清除禁子点
|
||||
if (rule->hasBannedLocations && p.get_phase() != PHASE_PLACING) {
|
||||
if (rule.hasBannedLocations && p.get_phase() != PHASE_PLACING) {
|
||||
while (nTotalPieces < static_cast<int>(pieceList.size())) {
|
||||
delete pieceList.at(pieceList.size() - 1);
|
||||
pieceList.pop_back();
|
||||
|
|
Loading…
Reference in New Issue