refactor: position: 类成员函数改为下划线风格并调整变量和函数顺序
This commit is contained in:
parent
2116aae3a4
commit
f6a9f40e78
|
@ -120,7 +120,7 @@ void sq2str(char *str)
|
|||
sig = 0;
|
||||
}
|
||||
|
||||
Position::squareToPolar((Square)sq, file, rank);
|
||||
Position::square_to_polar((Square)sq, file, rank);
|
||||
|
||||
if (sig == 1) {
|
||||
sprintf_s(str, 16, "(%d,%d)", file, rank);
|
||||
|
|
|
@ -60,7 +60,7 @@ Value Eval::evaluate(Position *pos)
|
|||
pos->nPiecesOnBoard[WHITE] * VALUE_EACH_PIECE_ONBOARD;
|
||||
|
||||
#ifdef EVALUATE_MOBILITY
|
||||
value += pos->getMobilityDiff(position->turn, position->nPiecesInHand[BLACK], position->nPiecesInHand[WHITE], false) * 10;
|
||||
value += pos->get_mobility_diff(position->turn, position->nPiecesInHand[BLACK], position->nPiecesInHand[WHITE], false) * 10;
|
||||
#endif /* EVALUATE_MOBILITY */
|
||||
|
||||
switch (pos->action) {
|
||||
|
@ -88,7 +88,7 @@ Value Eval::evaluate(Position *pos)
|
|||
value = VALUE_DRAW;
|
||||
}
|
||||
} else if (pos->action == ACTION_SELECT &&
|
||||
pos->isAllSurrounded() &&
|
||||
pos->is_all_surrounded() &&
|
||||
rule.isLoseButNotChangeTurnWhenNoWay) {
|
||||
Value delta = pos->sideToMove == BLACK ? -VALUE_MATE : VALUE_MATE;
|
||||
value += delta;
|
||||
|
|
|
@ -309,7 +309,7 @@ ExtMove *generateMoves(/* TODO: const */ Position *position, ExtMove *moveList)
|
|||
for (Move i : MoveList::movePriorityTable) {
|
||||
square = static_cast<Square>(i);
|
||||
|
||||
if (position->locations[square]) {
|
||||
if (position->board[square]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -320,7 +320,7 @@ ExtMove *generateMoves(/* TODO: const */ Position *position, ExtMove *moveList)
|
|||
*cur++ = ((Move)square);
|
||||
} else {
|
||||
#ifdef FIRST_MOVE_STAR_PREFERRED
|
||||
if (Position::isStar(square)) {
|
||||
if (Position::is_star_square(square)) {
|
||||
moves.push_back((Move)square);
|
||||
}
|
||||
#else
|
||||
|
@ -347,7 +347,7 @@ ExtMove *generateMoves(/* TODO: const */ Position *position, ExtMove *moveList)
|
|||
!rule.allowFlyWhenRemainThreePieces) {
|
||||
for (int direction = MD_BEGIN; direction < MD_NB; direction++) {
|
||||
newSquare = static_cast<Square>(MoveList::moveTable[oldSquare][direction]);
|
||||
if (newSquare && !position->locations[newSquare]) {
|
||||
if (newSquare && !position->board[newSquare]) {
|
||||
Move m = make_move(oldSquare, newSquare);
|
||||
*cur++ = ((Move)m);
|
||||
}
|
||||
|
@ -355,7 +355,7 @@ ExtMove *generateMoves(/* TODO: const */ Position *position, ExtMove *moveList)
|
|||
} else {
|
||||
// piece count < 3,and allow fly, if is empty point, that's ok, do not need in move list
|
||||
for (newSquare = SQ_BEGIN; newSquare < SQ_END; newSquare = static_cast<Square>(newSquare + 1)) {
|
||||
if (!position->locations[newSquare]) {
|
||||
if (!position->board[newSquare]) {
|
||||
Move m = make_move(oldSquare, newSquare);
|
||||
*cur++ = ((Move)m);
|
||||
}
|
||||
|
@ -366,10 +366,10 @@ ExtMove *generateMoves(/* TODO: const */ Position *position, ExtMove *moveList)
|
|||
break;
|
||||
|
||||
case ACTION_REMOVE:
|
||||
if (position->isAllInMills(them)) {
|
||||
if (position->is_all_in_mills(them)) {
|
||||
for (int i = MOVE_PRIORITY_TABLE_SIZE - 1; i >= 0; i--) {
|
||||
square = static_cast<Square>(MoveList::movePriorityTable[i]);
|
||||
if (position->locations[square] & (them << PLAYER_SHIFT)) {
|
||||
if (position->board[square] & (them << PLAYER_SHIFT)) {
|
||||
*cur++ = ((Move)-square);
|
||||
}
|
||||
}
|
||||
|
@ -379,8 +379,8 @@ ExtMove *generateMoves(/* TODO: const */ Position *position, ExtMove *moveList)
|
|||
// not is all in mills
|
||||
for (int i = MOVE_PRIORITY_TABLE_SIZE - 1; i >= 0; i--) {
|
||||
square = static_cast<Square>(MoveList::movePriorityTable[i]);
|
||||
if (position->locations[square] & (them << PLAYER_SHIFT)) {
|
||||
if (rule.allowRemovePieceInMill || !position->inHowManyMills(square, NOBODY)) {
|
||||
if (position->board[square] & (them << PLAYER_SHIFT)) {
|
||||
if (rule.allowRemovePieceInMill || !position->in_how_many_mills(square, NOBODY)) {
|
||||
*cur++ = ((Move)-square);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ void MovePicker::score()
|
|||
Square sqsrc = from_sq(m);
|
||||
|
||||
// if stat before moving, moving phrase maybe from @-0-@ to 0-@-@, but no mill, so need sqsrc to judge
|
||||
int nOurMills = position->inHowManyMills(sq, position->sideToMove, sqsrc);
|
||||
int nOurMills = position->in_how_many_mills(sq, position->sideToMove, sqsrc);
|
||||
int nTheirMills = 0;
|
||||
|
||||
#ifdef SORT_MOVE_WITH_HUMAN_KNOWLEDGES
|
||||
|
@ -66,17 +66,17 @@ void MovePicker::score()
|
|||
#ifdef ALPHABETA_AI
|
||||
cur->rating += static_cast<Rating>(RATING_ONE_MILL * nOurMills);
|
||||
#endif
|
||||
} else if (position->getPhase() == PHASE_PLACING) {
|
||||
} else if (position->get_phase() == PHASE_PLACING) {
|
||||
// placing phrase, check if place sq can block their close mill
|
||||
nTheirMills = position->inHowManyMills(sq, position->them);
|
||||
nTheirMills = position->in_how_many_mills(sq, position->them);
|
||||
#ifdef ALPHABETA_AI
|
||||
cur->rating += static_cast<Rating>(RATING_BLOCK_ONE_MILL * nTheirMills);
|
||||
#endif
|
||||
}
|
||||
#if 1
|
||||
else if (position->getPhase() == PHASE_MOVING) {
|
||||
else if (position->get_phase() == PHASE_MOVING) {
|
||||
// moving phrase, check if place sq can block their close mill
|
||||
nTheirMills = position->inHowManyMills(sq, position->them);
|
||||
nTheirMills = position->in_how_many_mills(sq, position->them);
|
||||
|
||||
if (nTheirMills) {
|
||||
int nOurPieces = 0;
|
||||
|
@ -84,7 +84,7 @@ void MovePicker::score()
|
|||
int nBanned = 0;
|
||||
int nEmpty = 0;
|
||||
|
||||
position->getSurroundedPieceCount(sq, nOurPieces, nTheirPieces, nBanned, nEmpty);
|
||||
position->surrounded_pieces_count(sq, nOurPieces, nTheirPieces, nBanned, nEmpty);
|
||||
|
||||
#ifdef ALPHABETA_AI
|
||||
if (sq % 2 == 0 && nTheirPieces == 3) {
|
||||
|
@ -103,7 +103,7 @@ void MovePicker::score()
|
|||
#ifdef ALPHABETA_AI
|
||||
if (rule.nTotalPiecesEachSide == 12 &&
|
||||
position->getPiecesOnBoardCount(WHITE) < 2 && // patch: only when white's 2nd move
|
||||
Position::isStar(static_cast<Square>(m))) {
|
||||
Position::is_star_square(static_cast<Square>(m))) {
|
||||
cur->rating += RATING_STAR_SQUARE;
|
||||
}
|
||||
#endif
|
||||
|
@ -113,7 +113,7 @@ void MovePicker::score()
|
|||
int nBanned = 0;
|
||||
int nEmpty = 0;
|
||||
|
||||
position->getSurroundedPieceCount(sq, nOurPieces, nTheirPieces, nBanned, nEmpty);
|
||||
position->surrounded_pieces_count(sq, nOurPieces, nTheirPieces, nBanned, nEmpty);
|
||||
|
||||
#ifdef ALPHABETA_AI
|
||||
if (nOurMills > 0) {
|
||||
|
@ -131,7 +131,7 @@ void MovePicker::score()
|
|||
}
|
||||
|
||||
// remove point is in their mill
|
||||
nTheirMills = position->inHowManyMills(sq, position->them);
|
||||
nTheirMills = position->in_how_many_mills(sq, position->them);
|
||||
if (nTheirMills) {
|
||||
if (nTheirPieces >= 2) {
|
||||
// if nearby their piece, prefer do not remove
|
||||
|
|
301
src/position.cpp
301
src/position.cpp
|
@ -31,9 +31,9 @@ string tips;
|
|||
|
||||
Position::Position()
|
||||
{
|
||||
constructKey();
|
||||
construct_key();
|
||||
|
||||
setPosition(&RULES[DEFAULT_RULE_NUMBER]);
|
||||
set_position(&RULES[DEFAULT_RULE_NUMBER]);
|
||||
|
||||
score[BLACK] = score[WHITE] = score_draw = nPlayed = 0;
|
||||
|
||||
|
@ -50,20 +50,20 @@ Position::~Position()
|
|||
cmdlist.clear();
|
||||
}
|
||||
|
||||
int Position::countPiecesOnBoard()
|
||||
int Position::pieces_on_board_count()
|
||||
{
|
||||
nPiecesOnBoard[BLACK] = nPiecesOnBoard[WHITE] = 0;
|
||||
|
||||
for (int r = 1; r < FILE_NB + 2; r++) {
|
||||
for (int s = 0; s < RANK_NB; s++) {
|
||||
Square square = static_cast<Square>(r * RANK_NB + s);
|
||||
if (locations[square] & B_STONE) {
|
||||
if (board[square] & B_STONE) {
|
||||
nPiecesOnBoard[BLACK]++;
|
||||
} else if (locations[square] & W_STONE) {
|
||||
} else if (board[square] & W_STONE) {
|
||||
nPiecesOnBoard[WHITE]++;
|
||||
}
|
||||
#if 0
|
||||
else if (locations[square] & BAN_STONE) {
|
||||
else if (board[square] & BAN_STONE) {
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ int Position::countPiecesOnBoard()
|
|||
return nPiecesOnBoard[BLACK] + nPiecesOnBoard[WHITE];
|
||||
}
|
||||
|
||||
int Position::countPiecesInHand()
|
||||
int Position::pieces_in_hand_count()
|
||||
{
|
||||
nPiecesInHand[BLACK] = rule.nTotalPiecesEachSide - nPiecesOnBoard[BLACK];
|
||||
nPiecesInHand[WHITE] = rule.nTotalPiecesEachSide - nPiecesOnBoard[WHITE];
|
||||
|
@ -85,7 +85,7 @@ int Position::countPiecesInHand()
|
|||
return nPiecesInHand[BLACK] + nPiecesInHand[WHITE];
|
||||
}
|
||||
|
||||
bool Position::setPosition(const struct Rule *newRule)
|
||||
bool Position::set_position(const struct Rule *newRule)
|
||||
{
|
||||
rule = *newRule;
|
||||
|
||||
|
@ -93,26 +93,26 @@ bool Position::setPosition(const struct Rule *newRule)
|
|||
this->moveStep = 0;
|
||||
|
||||
phase = PHASE_READY;
|
||||
setSideToMove(BLACK);
|
||||
set_side_to_move(BLACK);
|
||||
action = ACTION_PLACE;
|
||||
|
||||
memset(locations, 0, sizeof(locations));
|
||||
memset(board, 0, sizeof(board));
|
||||
st.key = 0;
|
||||
memset(byTypeBB, 0, sizeof(byTypeBB));
|
||||
|
||||
if (countPiecesOnBoard() == -1) {
|
||||
if (pieces_on_board_count() == -1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
countPiecesInHand();
|
||||
pieces_in_hand_count();
|
||||
nPiecesNeedRemove = 0;
|
||||
millListSize = 0;
|
||||
winner = NOBODY;
|
||||
MoveList::create();
|
||||
createMillTable();
|
||||
create_mill_table();
|
||||
currentSquare = SQ_0;
|
||||
elapsedSeconds[BLACK] = elapsedSeconds[WHITE] = 0;
|
||||
setTips();
|
||||
set_tips();
|
||||
cmdlist.clear();
|
||||
|
||||
int r;
|
||||
|
@ -141,12 +141,12 @@ bool Position::reset()
|
|||
moveStep = 0;
|
||||
|
||||
phase = PHASE_READY;
|
||||
setSideToMove(BLACK);
|
||||
set_side_to_move(BLACK);
|
||||
action = ACTION_PLACE;
|
||||
|
||||
winner = NOBODY;
|
||||
|
||||
memset(locations, 0, sizeof(locations));
|
||||
memset(board, 0, sizeof(board));
|
||||
st.key = 0;
|
||||
memset(byTypeBB, 0, sizeof(byTypeBB));
|
||||
|
||||
|
@ -156,7 +156,7 @@ bool Position::reset()
|
|||
millListSize = 0;
|
||||
currentSquare = SQ_0;
|
||||
elapsedSeconds[BLACK] = elapsedSeconds[WHITE] = 0;
|
||||
setTips();
|
||||
set_tips();
|
||||
cmdlist.clear();
|
||||
|
||||
#ifdef ENDGAME_LEARNING
|
||||
|
@ -224,19 +224,19 @@ bool Position::place_piece(Square square, bool updateCmdlist)
|
|||
if (action != ACTION_PLACE)
|
||||
return false;
|
||||
|
||||
if (!onBoard[square] || locations[square])
|
||||
if (!onBoard[square] || board[square])
|
||||
return false;
|
||||
|
||||
Position::squareToPolar(square, file, rank);
|
||||
Position::square_to_polar(square, file, rank);
|
||||
|
||||
if (phase == PHASE_PLACING) {
|
||||
piece = (Piece)((0x01 | (sideToMove << PLAYER_SHIFT)) + rule.nTotalPiecesEachSide - nPiecesInHand[us]);
|
||||
nPiecesInHand[us]--;
|
||||
nPiecesOnBoard[us]++;
|
||||
|
||||
locations[square] = piece;
|
||||
board[square] = piece;
|
||||
|
||||
updateKey(square);
|
||||
update_key(square);
|
||||
|
||||
byTypeBB[ALL_PIECES] |= square;
|
||||
byTypeBB[us] |= square;
|
||||
|
@ -253,31 +253,31 @@ bool Position::place_piece(Square square, bool updateCmdlist)
|
|||
|
||||
currentSquare = square;
|
||||
|
||||
n = addMills(currentSquare);
|
||||
n = add_mills(currentSquare);
|
||||
|
||||
if (n == 0) {
|
||||
assert(nPiecesInHand[BLACK] >= 0 && nPiecesInHand[WHITE] >= 0);
|
||||
|
||||
if (nPiecesInHand[BLACK] == 0 && nPiecesInHand[WHITE] == 0) {
|
||||
if (checkGameOverCondition(updateCmdlist)) {
|
||||
if (check_gameover_condition(updateCmdlist)) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
phase = PHASE_MOVING;
|
||||
action = ACTION_SELECT;
|
||||
cleanBannedLocations();
|
||||
clean_banned();
|
||||
|
||||
if (rule.isDefenderMoveFirst) {
|
||||
setSideToMove(WHITE);
|
||||
set_side_to_move(WHITE);
|
||||
} else {
|
||||
setSideToMove(BLACK);
|
||||
set_side_to_move(BLACK);
|
||||
}
|
||||
|
||||
if (checkGameOverCondition(updateCmdlist)) {
|
||||
if (check_gameover_condition(updateCmdlist)) {
|
||||
goto out;
|
||||
}
|
||||
} else {
|
||||
changeSideToMove();
|
||||
change_side_to_move();
|
||||
}
|
||||
} else {
|
||||
nPiecesNeedRemove = rule.allowRemoveMultiPiecesWhenCloseMultiMill ? n : 1;
|
||||
|
@ -287,7 +287,7 @@ bool Position::place_piece(Square square, bool updateCmdlist)
|
|||
goto out;
|
||||
}
|
||||
|
||||
if (checkGameOverCondition(updateCmdlist)) {
|
||||
if (check_gameover_condition(updateCmdlist)) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
|
@ -322,22 +322,22 @@ bool Position::place_piece(Square square, bool updateCmdlist)
|
|||
byTypeBB[ALL_PIECES] ^= fromTo;
|
||||
byTypeBB[us] ^= fromTo;
|
||||
|
||||
locations[square] = locations[currentSquare];
|
||||
board[square] = board[currentSquare];
|
||||
|
||||
updateKey(square);
|
||||
revertKey(currentSquare);
|
||||
update_key(square);
|
||||
revert_key(currentSquare);
|
||||
|
||||
locations[currentSquare] = NO_PIECE;
|
||||
board[currentSquare] = NO_PIECE;
|
||||
|
||||
currentSquare = square;
|
||||
n = addMills(currentSquare);
|
||||
n = add_mills(currentSquare);
|
||||
|
||||
// midgame
|
||||
if (n == 0) {
|
||||
action = ACTION_SELECT;
|
||||
changeSideToMove();
|
||||
change_side_to_move();
|
||||
|
||||
if (checkGameOverCondition(updateCmdlist)) {
|
||||
if (check_gameover_condition(updateCmdlist)) {
|
||||
goto out;
|
||||
}
|
||||
} else {
|
||||
|
@ -347,7 +347,7 @@ bool Position::place_piece(Square square, bool updateCmdlist)
|
|||
|
||||
out:
|
||||
if (updateCmdlist) {
|
||||
setTips();
|
||||
set_tips();
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -355,14 +355,14 @@ out:
|
|||
|
||||
bool Position::_placePiece(File file, Rank rank)
|
||||
{
|
||||
Square square = Position::polarToSquare(file, rank);
|
||||
Square square = Position::polar_to_square(file, rank);
|
||||
|
||||
return place_piece(square, true);
|
||||
}
|
||||
|
||||
bool Position::_removePiece(File file, Rank rank)
|
||||
{
|
||||
Square square = Position::polarToSquare(file, rank);
|
||||
Square square = Position::polar_to_square(file, rank);
|
||||
|
||||
return remove_piece(square, 1);
|
||||
}
|
||||
|
@ -380,32 +380,32 @@ bool Position::remove_piece(Square square, bool updateCmdlist)
|
|||
|
||||
File file;
|
||||
Rank rank;
|
||||
Position::squareToPolar(square, file, rank);
|
||||
Position::square_to_polar(square, file, rank);
|
||||
|
||||
int seconds = -1;
|
||||
|
||||
int oppId = them;
|
||||
|
||||
// if piece is not their
|
||||
if (!((them << PLAYER_SHIFT) & locations[square]))
|
||||
if (!((them << PLAYER_SHIFT) & board[square]))
|
||||
return false;
|
||||
|
||||
if (!rule.allowRemovePieceInMill &&
|
||||
inHowManyMills(square, NOBODY) &&
|
||||
!isAllInMills(~sideToMove)) {
|
||||
in_how_many_mills(square, NOBODY) &&
|
||||
!is_all_in_mills(~sideToMove)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (rule.hasBannedLocations && phase == PHASE_PLACING) {
|
||||
revertKey(square);
|
||||
locations[square] = BAN_STONE;
|
||||
updateKey(square);
|
||||
revert_key(square);
|
||||
board[square] = BAN_STONE;
|
||||
update_key(square);
|
||||
|
||||
byTypeBB[oppId] ^= square;
|
||||
byTypeBB[BAN] |= square;
|
||||
} else { // Remove
|
||||
revertKey(square);
|
||||
locations[square] = NO_PIECE;
|
||||
revert_key(square);
|
||||
board[square] = NO_PIECE;
|
||||
|
||||
byTypeBB[ALL_PIECES] ^= square;
|
||||
byTypeBB[them] ^= square;
|
||||
|
@ -428,7 +428,7 @@ bool Position::remove_piece(Square square, bool updateCmdlist)
|
|||
|
||||
// Remove piece completed
|
||||
|
||||
if (checkGameOverCondition(updateCmdlist)) {
|
||||
if (check_gameover_condition(updateCmdlist)) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
|
@ -441,37 +441,37 @@ bool Position::remove_piece(Square square, bool updateCmdlist)
|
|||
|
||||
phase = PHASE_MOVING;
|
||||
action = ACTION_SELECT;
|
||||
cleanBannedLocations();
|
||||
clean_banned();
|
||||
|
||||
if (rule.isDefenderMoveFirst) {
|
||||
setSideToMove(WHITE);
|
||||
set_side_to_move(WHITE);
|
||||
} else {
|
||||
setSideToMove(BLACK);
|
||||
set_side_to_move(BLACK);
|
||||
}
|
||||
|
||||
if (checkGameOverCondition(updateCmdlist)) {
|
||||
if (check_gameover_condition(updateCmdlist)) {
|
||||
goto out;
|
||||
}
|
||||
} else {
|
||||
action = ACTION_PLACE;
|
||||
changeSideToMove();
|
||||
change_side_to_move();
|
||||
|
||||
if (checkGameOverCondition(updateCmdlist)) {
|
||||
if (check_gameover_condition(updateCmdlist)) {
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
action = ACTION_SELECT;
|
||||
changeSideToMove();
|
||||
change_side_to_move();
|
||||
|
||||
if (checkGameOverCondition(updateCmdlist)) {
|
||||
if (check_gameover_condition(updateCmdlist)) {
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
out:
|
||||
if (updateCmdlist) {
|
||||
setTips();
|
||||
set_tips();
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -485,7 +485,7 @@ bool Position::select_piece(Square square)
|
|||
if (action != ACTION_SELECT && action != ACTION_PLACE)
|
||||
return false;
|
||||
|
||||
if (locations[square] & (sideToMove << PLAYER_SHIFT)) {
|
||||
if (board[square] & (sideToMove << PLAYER_SHIFT)) {
|
||||
currentSquare = square;
|
||||
action = ACTION_PLACE;
|
||||
|
||||
|
@ -497,7 +497,7 @@ bool Position::select_piece(Square square)
|
|||
|
||||
bool Position::_selectPiece(File file, Rank rank)
|
||||
{
|
||||
return select_piece(Position::polarToSquare(file, rank));
|
||||
return select_piece(Position::polar_to_square(file, rank));
|
||||
}
|
||||
|
||||
bool Position::giveup(Color loser)
|
||||
|
@ -510,8 +510,8 @@ bool Position::giveup(Color loser)
|
|||
phase = PHASE_GAMEOVER;
|
||||
|
||||
Color loserColor = loser;
|
||||
char loserCh = colorToCh(loserColor);
|
||||
string loserStr = chToStr(loserCh);
|
||||
char loserCh = color_to_char(loserColor);
|
||||
string loserStr = char_to_string(loserCh);
|
||||
|
||||
winner = ~loser;
|
||||
tips = "玩家" + loserStr + "投子认负";
|
||||
|
@ -538,7 +538,7 @@ bool Position::command(const char *cmd)
|
|||
return false;
|
||||
}
|
||||
|
||||
return setPosition(&RULES[ruleIndex - 1]);
|
||||
return set_position(&RULES[ruleIndex - 1]);
|
||||
}
|
||||
|
||||
args = sscanf(cmd, "(%1u,%1u)->(%1u,%1u) %2u:%2u", &file1, &rank1, &file2, &rank2, &mm, &ss);
|
||||
|
@ -620,7 +620,7 @@ bool Position::do_move(Move m)
|
|||
return false;
|
||||
}
|
||||
|
||||
Color Position::getWinner() const
|
||||
Color Position::get_winner() const
|
||||
{
|
||||
return winner;
|
||||
}
|
||||
|
@ -646,13 +646,13 @@ int Position::update()
|
|||
}
|
||||
|
||||
if (rule.maxTimeLedToLose > 0) {
|
||||
checkGameOverCondition();
|
||||
check_gameover_condition();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool Position::checkGameOverCondition(int8_t updateCmdlist)
|
||||
bool Position::check_gameover_condition(int8_t updateCmdlist)
|
||||
{
|
||||
if (phase & PHASE_NOTPLAYING) {
|
||||
return true;
|
||||
|
@ -666,7 +666,7 @@ bool Position::checkGameOverCondition(int8_t updateCmdlist)
|
|||
if (elapsedSeconds[i] > rule.maxTimeLedToLose * 60) {
|
||||
elapsedSeconds[i] = rule.maxTimeLedToLose * 60;
|
||||
winner = ~Color(i);
|
||||
tips = "玩家" + chToStr(colorToCh(Color(i))) + "超时判负。";
|
||||
tips = "玩家" + char_to_string(color_to_char(Color(i))) + "超时判负。";
|
||||
sprintf(cmdline, "Time over. Player%d win!", ~Color(i));
|
||||
}
|
||||
}
|
||||
|
@ -749,13 +749,13 @@ bool Position::checkGameOverCondition(int8_t updateCmdlist)
|
|||
return true;
|
||||
}
|
||||
|
||||
if (phase == PHASE_MOVING && action == ACTION_SELECT && isAllSurrounded()) {
|
||||
if (phase == PHASE_MOVING && action == ACTION_SELECT && is_all_surrounded()) {
|
||||
// TODO: move to next branch
|
||||
phase = PHASE_GAMEOVER;
|
||||
|
||||
if (rule.isLoseButNotChangeTurnWhenNoWay) {
|
||||
if (updateCmdlist) {
|
||||
tips = "玩家" + chToStr(colorToCh(sideToMove)) + "无子可走被闷";
|
||||
tips = "玩家" + char_to_string(color_to_char(sideToMove)) + "无子可走被闷";
|
||||
winner = ~sideToMove;
|
||||
sprintf(cmdline, "Player%d no way to go. Player%d win!", sideToMove, winner);
|
||||
cmdlist.emplace_back(string(cmdline)); // TODO: memleak
|
||||
|
@ -764,7 +764,7 @@ bool Position::checkGameOverCondition(int8_t updateCmdlist)
|
|||
return true;
|
||||
}
|
||||
|
||||
changeSideToMove();
|
||||
change_side_to_move();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -772,7 +772,7 @@ bool Position::checkGameOverCondition(int8_t updateCmdlist)
|
|||
return false;
|
||||
}
|
||||
|
||||
int Position::getMobilityDiff(bool includeFobidden)
|
||||
int Position::get_mobility_diff(bool includeFobidden)
|
||||
{
|
||||
// TODO: Deal with rule is no ban location
|
||||
int mobilityBlack = 0;
|
||||
|
@ -781,11 +781,11 @@ int Position::getMobilityDiff(bool includeFobidden)
|
|||
int n = 0;
|
||||
|
||||
for (Square i = SQ_BEGIN; i < SQ_END; i = static_cast<Square>(i + 1)) {
|
||||
n = getSurroundedEmptyLocationCount(i, includeFobidden);
|
||||
n = surrounded_empty_squres_count(i, includeFobidden);
|
||||
|
||||
if (locations[i] & B_STONE) {
|
||||
if (board[i] & B_STONE) {
|
||||
mobilityBlack += n;
|
||||
} else if (locations[i] & W_STONE) {
|
||||
} else if (board[i] & W_STONE) {
|
||||
mobilityWhite += n;
|
||||
}
|
||||
}
|
||||
|
@ -795,7 +795,7 @@ int Position::getMobilityDiff(bool includeFobidden)
|
|||
return diff;
|
||||
}
|
||||
|
||||
void Position::cleanBannedLocations()
|
||||
void Position::clean_banned()
|
||||
{
|
||||
if (!rule.hasBannedLocations) {
|
||||
return;
|
||||
|
@ -807,47 +807,42 @@ void Position::cleanBannedLocations()
|
|||
for (int s = 0; s < RANK_NB; s++) {
|
||||
square = static_cast<Square>(r * RANK_NB + s);
|
||||
|
||||
if (locations[square] == BAN_STONE) {
|
||||
revertKey(square);
|
||||
locations[square] = NO_PIECE;
|
||||
if (board[square] == BAN_STONE) {
|
||||
revert_key(square);
|
||||
board[square] = NO_PIECE;
|
||||
byTypeBB[ALL_PIECES] ^= square; // Need to remove?
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Position::setSideToMove(Color c)
|
||||
void Position::set_side_to_move(Color c)
|
||||
{
|
||||
sideToMove = c;
|
||||
them = ~sideToMove;
|
||||
}
|
||||
|
||||
Color Position::getSideToMove()
|
||||
void Position::change_side_to_move()
|
||||
{
|
||||
return sideToMove;
|
||||
}
|
||||
|
||||
void Position::changeSideToMove()
|
||||
{
|
||||
setSideToMove(~sideToMove);
|
||||
set_side_to_move(~sideToMove);
|
||||
}
|
||||
|
||||
bool Position::do_null_move()
|
||||
{
|
||||
changeSideToMove();
|
||||
change_side_to_move();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Position::undo_null_move()
|
||||
{
|
||||
changeSideToMove();
|
||||
change_side_to_move();
|
||||
return true;
|
||||
}
|
||||
|
||||
void Position::setTips()
|
||||
void Position::set_tips()
|
||||
{
|
||||
string winnerStr, t;
|
||||
string turnStr = chToStr(colorToCh(sideToMove));
|
||||
string turnStr = char_to_string(color_to_char(sideToMove));
|
||||
|
||||
switch (phase) {
|
||||
case PHASE_READY:
|
||||
|
@ -878,7 +873,7 @@ void Position::setTips()
|
|||
break;
|
||||
}
|
||||
|
||||
winnerStr = chToStr(colorToCh(winner));
|
||||
winnerStr = char_to_string(color_to_char(winner));
|
||||
|
||||
score[winner]++;
|
||||
|
||||
|
@ -897,12 +892,12 @@ void Position::setTips()
|
|||
}
|
||||
}
|
||||
|
||||
time_t Position::getElapsedTime(int us)
|
||||
time_t Position::get_elapsed_time(int us)
|
||||
{
|
||||
return elapsedSeconds[us];
|
||||
}
|
||||
|
||||
void Position::constructKey()
|
||||
void Position::construct_key()
|
||||
{
|
||||
st.key = 0;
|
||||
}
|
||||
|
@ -910,17 +905,17 @@ void Position::constructKey()
|
|||
Key Position::key()
|
||||
{
|
||||
// TODO: Move to suitable function
|
||||
return updateKeyMisc();
|
||||
return update_key_misc();
|
||||
}
|
||||
|
||||
Key Position::updateKey(Square square)
|
||||
Key Position::update_key(Square square)
|
||||
{
|
||||
// PieceType is locations[square]
|
||||
// PieceType is board[square]
|
||||
|
||||
// 0b00 - no piece,0b01 = 1 black,0b10 = 2 white,0b11 = 3 ban
|
||||
int pieceType = locationToColor(square);
|
||||
int pieceType = color_on(square);
|
||||
// TODO: this is std, but current code can work
|
||||
//Location loc = locations[square];
|
||||
//Location loc = board[square];
|
||||
//int pieceType = loc == 0x0f? 3 : loc >> PLAYER_SHIFT;
|
||||
|
||||
st.key ^= zobrist[square][pieceType];
|
||||
|
@ -928,12 +923,12 @@ Key Position::updateKey(Square square)
|
|||
return st.key;
|
||||
}
|
||||
|
||||
Key Position::revertKey(Square square)
|
||||
Key Position::revert_key(Square square)
|
||||
{
|
||||
return updateKey(square);
|
||||
return update_key(square);
|
||||
}
|
||||
|
||||
Key Position::updateKeyMisc()
|
||||
Key Position::update_key_misc()
|
||||
{
|
||||
const int KEY_MISC_BIT = 8;
|
||||
|
||||
|
@ -956,7 +951,7 @@ Key Position::updateKeyMisc()
|
|||
return st.key;
|
||||
}
|
||||
|
||||
Key Position::getNextPrimaryKey(Move m)
|
||||
Key Position::next_primary_key(Move m)
|
||||
{
|
||||
Key npKey = st.key /* << 8 >> 8 */;
|
||||
Square sq = static_cast<Square>(to_sq(m));;
|
||||
|
@ -1024,7 +1019,7 @@ Position &Position::operator= (const Position &other)
|
|||
if (this == &other)
|
||||
return *this;
|
||||
|
||||
memcpy(this->locations, other.locations, sizeof(this->locations));
|
||||
memcpy(this->board, other.board, sizeof(this->board));
|
||||
memcpy(this->byTypeBB, other.byTypeBB, sizeof(this->byTypeBB));
|
||||
|
||||
memcpy(&millList, &other.millList, sizeof(millList));
|
||||
|
@ -1034,7 +1029,7 @@ Position &Position::operator= (const Position &other)
|
|||
}
|
||||
#endif
|
||||
|
||||
void Position::createMillTable()
|
||||
void Position::create_mill_table()
|
||||
{
|
||||
const int millTable_noObliqueLine[SQUARE_NB][LD_NB][2] = {
|
||||
/* 0 */ {{0, 0}, {0, 0}, {0, 0}},
|
||||
|
@ -1161,7 +1156,7 @@ void Position::createMillTable()
|
|||
#endif /* DEBUG_MODE */
|
||||
}
|
||||
|
||||
void Position::squareToPolar(const Square square, File &file, Rank &rank)
|
||||
void Position::square_to_polar(const Square square, File &file, Rank &rank)
|
||||
{
|
||||
//r = square / RANK_NB;
|
||||
//s = square % RANK_NB + 1;
|
||||
|
@ -1169,53 +1164,53 @@ void Position::squareToPolar(const Square square, File &file, Rank &rank)
|
|||
rank = Rank((square & 0x07) + 1);
|
||||
}
|
||||
|
||||
Square Position::polarToSquare(File file, Rank rank)
|
||||
Square Position::polar_to_square(File file, Rank rank)
|
||||
{
|
||||
assert(!(file < 1 || file > FILE_NB || rank < 1 || rank > RANK_NB));
|
||||
|
||||
return static_cast<Square>(file * RANK_NB + rank - 1);
|
||||
}
|
||||
|
||||
Color Position::locationToColor(Square square)
|
||||
Color Position::color_on(Square s)
|
||||
{
|
||||
return Color((locations[square] & 0x30) >> PLAYER_SHIFT);
|
||||
return Color((board[s] & 0x30) >> PLAYER_SHIFT);
|
||||
}
|
||||
|
||||
int Position::inHowManyMills(Square square, Color c, Square squareSelected)
|
||||
int Position::in_how_many_mills(Square square, Color c, Square squareSelected)
|
||||
{
|
||||
int n = 0;
|
||||
Piece locbak = NO_PIECE;
|
||||
|
||||
if (c == NOBODY) {
|
||||
c = Color(locationToColor(square) >> PLAYER_SHIFT);
|
||||
c = Color(color_on(square) >> PLAYER_SHIFT);
|
||||
}
|
||||
|
||||
if (squareSelected != SQ_0) {
|
||||
locbak = locations[squareSelected];
|
||||
locations[squareSelected] = NO_PIECE;
|
||||
locbak = board[squareSelected];
|
||||
board[squareSelected] = NO_PIECE;
|
||||
}
|
||||
|
||||
for (int l = 0; l < LD_NB; l++) {
|
||||
if ((c << PLAYER_SHIFT) &
|
||||
locations[millTable[square][l][0]] &
|
||||
locations[millTable[square][l][1]]) {
|
||||
board[millTable[square][l][0]] &
|
||||
board[millTable[square][l][1]]) {
|
||||
n++;
|
||||
}
|
||||
}
|
||||
|
||||
if (squareSelected != SQ_0) {
|
||||
locations[squareSelected] = locbak;
|
||||
board[squareSelected] = locbak;
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
int Position::addMills(Square square)
|
||||
int Position::add_mills(Square square)
|
||||
{
|
||||
uint64_t mill = 0;
|
||||
int n = 0;
|
||||
int idx[3], min, temp;
|
||||
Color m = locationToColor(square);
|
||||
Color m = color_on(square);
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
idx[0] = square;
|
||||
|
@ -1223,7 +1218,7 @@ int Position::addMills(Square square)
|
|||
idx[2] = millTable[square][i][1];
|
||||
|
||||
// no mill
|
||||
if (!((m << PLAYER_SHIFT) & locations[idx[1]] & locations[idx[2]])) {
|
||||
if (!((m << PLAYER_SHIFT) & board[idx[1]] & board[idx[2]])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -1247,11 +1242,11 @@ int Position::addMills(Square square)
|
|||
idx[j] = temp;
|
||||
}
|
||||
|
||||
mill = (static_cast<uint64_t>(locations[idx[0]]) << 40)
|
||||
mill = (static_cast<uint64_t>(board[idx[0]]) << 40)
|
||||
+ (static_cast<uint64_t>(idx[0]) << 32)
|
||||
+ (static_cast<uint64_t>(locations[idx[1]]) << 24)
|
||||
+ (static_cast<uint64_t>(board[idx[1]]) << 24)
|
||||
+ (static_cast<uint64_t>(idx[1]) << 16)
|
||||
+ (static_cast<uint64_t>(locations[idx[2]]) << 8)
|
||||
+ (static_cast<uint64_t>(board[idx[2]]) << 8)
|
||||
+ static_cast<uint64_t>(idx[2]);
|
||||
|
||||
if (rule.allowRemovePiecesRepeatedlyWhenCloseSameMill) {
|
||||
|
@ -1276,11 +1271,11 @@ int Position::addMills(Square square)
|
|||
return n;
|
||||
}
|
||||
|
||||
bool Position::isAllInMills(Color c)
|
||||
bool Position::is_all_in_mills(Color c)
|
||||
{
|
||||
for (Square i = SQ_BEGIN; i < SQ_END; i = static_cast<Square>(i + 1)) {
|
||||
if (locations[i] & ((uint8_t)(c << PLAYER_SHIFT))) {
|
||||
if (!inHowManyMills(i, NOBODY)) {
|
||||
if (board[i] & ((uint8_t)(c << PLAYER_SHIFT))) {
|
||||
if (!in_how_many_mills(i, NOBODY)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -1290,7 +1285,7 @@ bool Position::isAllInMills(Color c)
|
|||
}
|
||||
|
||||
// Stat include ban
|
||||
int Position::getSurroundedEmptyLocationCount(Square square, bool includeFobidden)
|
||||
int Position::surrounded_empty_squres_count(Square square, bool includeFobidden)
|
||||
{
|
||||
//assert(rule.hasBannedLocations == includeFobidden);
|
||||
|
||||
|
@ -1302,8 +1297,8 @@ int Position::getSurroundedEmptyLocationCount(Square square, bool includeFobidde
|
|||
for (MoveDirection d = MD_BEGIN; d < MD_NB; d = (MoveDirection)(d + 1)) {
|
||||
moveSquare = static_cast<Square>(MoveList::moveTable[square][d]);
|
||||
if (moveSquare) {
|
||||
if (locations[moveSquare] == 0x00 ||
|
||||
(includeFobidden && locations[moveSquare] == BAN_STONE)) {
|
||||
if (board[moveSquare] == 0x00 ||
|
||||
(includeFobidden && board[moveSquare] == BAN_STONE)) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
@ -1313,7 +1308,7 @@ int Position::getSurroundedEmptyLocationCount(Square square, bool includeFobidde
|
|||
return count;
|
||||
}
|
||||
|
||||
void Position::getSurroundedPieceCount(Square square, int &nOurPieces, int &nTheirPieces, int &nBanned, int &nEmpty)
|
||||
void Position::surrounded_pieces_count(Square square, int &nOurPieces, int &nTheirPieces, int &nBanned, int &nEmpty)
|
||||
{
|
||||
Square moveSquare;
|
||||
|
||||
|
@ -1324,7 +1319,7 @@ void Position::getSurroundedPieceCount(Square square, int &nOurPieces, int &nThe
|
|||
continue;
|
||||
}
|
||||
|
||||
enum Piece pieceType = static_cast<Piece>(locations[moveSquare]);
|
||||
enum Piece pieceType = static_cast<Piece>(board[moveSquare]);
|
||||
|
||||
switch (pieceType) {
|
||||
case NO_PIECE:
|
||||
|
@ -1344,7 +1339,7 @@ void Position::getSurroundedPieceCount(Square square, int &nOurPieces, int &nThe
|
|||
}
|
||||
}
|
||||
|
||||
bool Position::isAllSurrounded()
|
||||
bool Position::is_all_surrounded()
|
||||
{
|
||||
// Full
|
||||
if (nPiecesOnBoard[BLACK] + nPiecesOnBoard[WHITE] >= RANK_NB * FILE_NB)
|
||||
|
@ -1359,13 +1354,13 @@ bool Position::isAllSurrounded()
|
|||
Square moveSquare;
|
||||
|
||||
for (Square sq = SQ_BEGIN; sq < SQ_END; sq = (Square)(sq + 1)) {
|
||||
if (!(sideToMove & locationToColor(sq))) {
|
||||
if (!(sideToMove & color_on(sq))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (MoveDirection d = MD_BEGIN; d < MD_NB; d = (MoveDirection)(d + 1)) {
|
||||
moveSquare = static_cast<Square>(MoveList::moveTable[sq][d]);
|
||||
if (moveSquare && !locations[moveSquare]) {
|
||||
if (moveSquare && !board[moveSquare]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -1374,7 +1369,7 @@ bool Position::isAllSurrounded()
|
|||
return true;
|
||||
}
|
||||
|
||||
bool Position::isStar(Square square)
|
||||
bool Position::is_star_square(Square square)
|
||||
{
|
||||
if (rule.nTotalPiecesEachSide == 12) {
|
||||
return (square == 17 ||
|
||||
|
@ -1397,9 +1392,9 @@ void Position::mirror(int32_t move_, Square square, bool cmdChange /*= true*/)
|
|||
|
||||
for (r = 1; r <= FILE_NB; r++) {
|
||||
for (s = 1; s < RANK_NB / 2; s++) {
|
||||
ch = locations[r * RANK_NB + s];
|
||||
locations[r * RANK_NB + s] = locations[(r + 1) * RANK_NB - s];
|
||||
locations[(r + 1) * RANK_NB - s] = ch;
|
||||
ch = board[r * RANK_NB + s];
|
||||
board[r * RANK_NB + s] = board[(r + 1) * RANK_NB - s];
|
||||
board[(r + 1) * RANK_NB - s] = ch;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1505,9 +1500,9 @@ void Position::turn(int32_t move_, Square square, bool cmdChange /*= true*/)
|
|||
int i;
|
||||
|
||||
for (s = 0; s < RANK_NB; s++) {
|
||||
ch = locations[RANK_NB + s];
|
||||
locations[RANK_NB + s] = locations[RANK_NB * FILE_NB + s];
|
||||
locations[RANK_NB * FILE_NB + s] = ch;
|
||||
ch = board[RANK_NB + s];
|
||||
board[RANK_NB + s] = board[RANK_NB * FILE_NB + s];
|
||||
board[RANK_NB * FILE_NB + s] = ch;
|
||||
}
|
||||
|
||||
uint64_t llp[3] = { 0 };
|
||||
|
@ -1679,34 +1674,34 @@ void Position::rotate(int degrees, int32_t move_, Square square, bool cmdChange
|
|||
|
||||
if (degrees == 2) {
|
||||
for (r = 1; r <= FILE_NB; r++) {
|
||||
ch1 = locations[r * RANK_NB];
|
||||
ch2 = locations[r * RANK_NB + 1];
|
||||
ch1 = board[r * RANK_NB];
|
||||
ch2 = board[r * RANK_NB + 1];
|
||||
|
||||
for (s = 0; s < RANK_NB - 2; s++) {
|
||||
locations[r * RANK_NB + s] = locations[r * RANK_NB + s + 2];
|
||||
board[r * RANK_NB + s] = board[r * RANK_NB + s + 2];
|
||||
}
|
||||
|
||||
locations[r * RANK_NB + 6] = ch1;
|
||||
locations[r * RANK_NB + 7] = ch2;
|
||||
board[r * RANK_NB + 6] = ch1;
|
||||
board[r * RANK_NB + 7] = ch2;
|
||||
}
|
||||
} else if (degrees == 6) {
|
||||
for (r = 1; r <= FILE_NB; r++) {
|
||||
ch1 = locations[r * RANK_NB + 7];
|
||||
ch2 = locations[r * RANK_NB + 6];
|
||||
ch1 = board[r * RANK_NB + 7];
|
||||
ch2 = board[r * RANK_NB + 6];
|
||||
|
||||
for (s = RANK_NB - 1; s >= 2; s--) {
|
||||
locations[r * RANK_NB + s] = locations[r * RANK_NB + s - 2];
|
||||
board[r * RANK_NB + s] = board[r * RANK_NB + s - 2];
|
||||
}
|
||||
|
||||
locations[r * RANK_NB + 1] = ch1;
|
||||
locations[r * RANK_NB] = ch2;
|
||||
board[r * RANK_NB + 1] = ch1;
|
||||
board[r * RANK_NB] = ch2;
|
||||
}
|
||||
} else if (degrees == 4) {
|
||||
for (r = 1; r <= FILE_NB; r++) {
|
||||
for (s = 0; s < RANK_NB / 2; s++) {
|
||||
ch1 = locations[r * RANK_NB + s];
|
||||
locations[r * RANK_NB + s] = locations[r * RANK_NB + s + 4];
|
||||
locations[r * RANK_NB + s + 4] = ch1;
|
||||
ch1 = board[r * RANK_NB + s];
|
||||
board[r * RANK_NB + s] = board[r * RANK_NB + s + 4];
|
||||
board[r * RANK_NB + s + 4] = ch1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -1812,7 +1807,7 @@ void Position::rotate(int degrees, int32_t move_, Square square, bool cmdChange
|
|||
}
|
||||
}
|
||||
|
||||
void Position::printBoard()
|
||||
void Position::print_board()
|
||||
{
|
||||
if (rule.nTotalPiecesEachSide == 12) {
|
||||
loggerDebug("\n"
|
||||
|
|
349
src/position.h
349
src/position.h
|
@ -71,144 +71,143 @@ public:
|
|||
Position(const Position &) = delete;
|
||||
Position &operator=(const Position &) = delete;
|
||||
|
||||
// Position representation
|
||||
Color color_on(Square s);
|
||||
int getPiecesInHandCount(Color c) const;
|
||||
int getPiecesOnBoardCount(Color c) const;
|
||||
|
||||
// Properties of moves
|
||||
bool select_piece(Square s);
|
||||
bool place_piece(Square s, bool updateCmdlist = false);
|
||||
bool remove_piece(Square s, bool updateCmdlist = false);
|
||||
|
||||
bool _selectPiece(File file, Rank rank);
|
||||
bool _placePiece(File file, Rank rank);
|
||||
bool _removePiece(File file, Rank rank);
|
||||
|
||||
// Doing and undoing moves
|
||||
bool do_move(Move m);
|
||||
bool do_null_move();
|
||||
bool undo_null_move();
|
||||
bool do_null_move();
|
||||
|
||||
// Accessing hash keys
|
||||
Key key();
|
||||
Key revertKey(Square square);
|
||||
Key updateKey(Square square);
|
||||
Key updateKeyMisc();
|
||||
Key getNextPrimaryKey(Move m);
|
||||
void construct_key();
|
||||
Key revert_key(Square square);
|
||||
Key update_key(Square square);
|
||||
Key update_key_misc();
|
||||
Key next_primary_key(Move m);
|
||||
|
||||
// Other properties of the position
|
||||
|
||||
enum Phase phase {PHASE_NONE};
|
||||
|
||||
Color sideToMove {NOCOLOR};
|
||||
Color them { NOCOLOR };
|
||||
|
||||
enum Action action { };
|
||||
|
||||
// Note: [0] is sum of Black and White
|
||||
int nPiecesInHand[COLOR_NB]{0};
|
||||
int nPiecesOnBoard[COLOR_NB] {0};
|
||||
int nPiecesNeedRemove {0};
|
||||
Color side_to_move() const;
|
||||
|
||||
//////////////////////////////////////
|
||||
|
||||
bool setPosition(const struct Rule *rule);
|
||||
bool set_position(const struct Rule *rule);
|
||||
|
||||
Piece *getBoardLocations() const
|
||||
{
|
||||
return (Piece *)locations;
|
||||
}
|
||||
time_t get_elapsed_time(int us);
|
||||
time_t start_timeb() const;
|
||||
void set_start_time(int stimeb);
|
||||
|
||||
Square getCurrentSquare() const
|
||||
{
|
||||
return currentSquare;
|
||||
}
|
||||
Piece *get_board() const;
|
||||
Square current_square() const;
|
||||
int get_step() const;
|
||||
enum Phase get_phase() const;
|
||||
enum Action get_action() const;
|
||||
const string get_tips() const;
|
||||
const char *cmd_line() const;
|
||||
const vector<string> *cmd_list() const;
|
||||
|
||||
int getStep() const
|
||||
{
|
||||
return currentStep;
|
||||
}
|
||||
|
||||
enum Phase getPhase() const
|
||||
{
|
||||
return phase;
|
||||
}
|
||||
|
||||
enum Action getAction() const
|
||||
{
|
||||
return action;
|
||||
}
|
||||
|
||||
time_t getElapsedTime(int us);
|
||||
|
||||
const string getTips() const
|
||||
{
|
||||
return tips;
|
||||
}
|
||||
|
||||
const char *getCmdLine() const
|
||||
{
|
||||
return cmdline;
|
||||
}
|
||||
|
||||
const vector<string> *getCmdList() const
|
||||
{
|
||||
return &cmdlist;
|
||||
}
|
||||
|
||||
time_t getStartTimeb() const
|
||||
{
|
||||
return startTime;
|
||||
}
|
||||
|
||||
void setStartTime(int stimeb)
|
||||
{
|
||||
startTime = stimeb;
|
||||
}
|
||||
|
||||
int getPiecesInHandCount(Color c) const
|
||||
{
|
||||
return nPiecesInHand[c];
|
||||
}
|
||||
|
||||
int getPiecesOnBoardCount(Color c) const
|
||||
{
|
||||
return nPiecesOnBoard[c];
|
||||
}
|
||||
|
||||
int getMobilityDiff(bool includeFobidden);
|
||||
int get_mobility_diff(bool includeFobidden);
|
||||
|
||||
bool reset();
|
||||
|
||||
bool start();
|
||||
|
||||
bool giveup(Color loser);
|
||||
|
||||
bool command(const char *cmd);
|
||||
|
||||
int update();
|
||||
bool check_gameover_condition(int8_t cp = 0);
|
||||
void clean_banned();
|
||||
void set_side_to_move(Color c);
|
||||
|
||||
void change_side_to_move();
|
||||
void set_tips();
|
||||
Color get_winner() const;
|
||||
|
||||
bool checkGameOverCondition(int8_t cp = 0);
|
||||
void mirror(int32_t move_, Square square, bool cmdChange = true);
|
||||
void turn(int32_t move_, Square square, bool cmdChange = true);
|
||||
void rotate(int degrees, int32_t move_, Square square, bool cmdChange = true);
|
||||
|
||||
void cleanBannedLocations();
|
||||
void create_mill_table();
|
||||
int add_mills(Square square);
|
||||
int in_how_many_mills(Square square, Color c, Square squareSelected = SQ_0);
|
||||
bool is_all_in_mills(Color c);
|
||||
|
||||
void setSideToMove(Color c);
|
||||
int surrounded_empty_squres_count(Square square, bool includeFobidden);
|
||||
void surrounded_pieces_count(Square square, int &nOurPieces, int &nTheirPieces, int &nBanned, int &nEmpty);
|
||||
bool is_all_surrounded();
|
||||
|
||||
Color getSideToMove();
|
||||
static void square_to_polar(Square square, File &file, Rank &rank);
|
||||
static Square polar_to_square(File file, Rank rank);
|
||||
|
||||
void changeSideToMove();
|
||||
static void print_board();
|
||||
|
||||
void setTips();
|
||||
int pieces_on_board_count();
|
||||
int pieces_in_hand_count();
|
||||
|
||||
Color getWinner() const;
|
||||
static char color_to_char(Color color);
|
||||
static std::string char_to_string(char ch);
|
||||
|
||||
int score[COLOR_NB] = { 0 };
|
||||
static bool is_star_square(Square square);
|
||||
|
||||
// private:
|
||||
|
||||
// Data members
|
||||
|
||||
Color sideToMove { NOCOLOR };
|
||||
Color them { NOCOLOR };
|
||||
Color winner;
|
||||
|
||||
enum Phase phase {PHASE_NONE};
|
||||
enum Action action;
|
||||
|
||||
int score[COLOR_NB] { 0 };
|
||||
int score_draw { 0 };
|
||||
int nPlayed { 0 };
|
||||
|
||||
int tm { -1 };
|
||||
Step currentStep;
|
||||
int moveStep;
|
||||
|
||||
static const int onBoard[SQUARE_NB];
|
||||
|
||||
// Relate to Rule
|
||||
static int millTable[SQUARE_NB][LD_NB][FILE_NB - 1];
|
||||
|
||||
Square currentSquare;
|
||||
int nPlayed{ 0 };
|
||||
|
||||
vector <string> cmdlist;
|
||||
|
||||
// 着法命令行用于棋谱的显示和解析, 当前着法的命令行指令,即一招棋谱
|
||||
char cmdline[64]{ '\0' };
|
||||
|
||||
// Note: [0] is sum of Black and White
|
||||
int nPiecesInHand[COLOR_NB] { 0 };
|
||||
int nPiecesOnBoard[COLOR_NB] { 0 };
|
||||
int nPiecesNeedRemove { 0 };
|
||||
|
||||
int tm { -1 };
|
||||
time_t startTime;
|
||||
time_t currentTime;
|
||||
time_t elapsedSeconds[COLOR_NB];
|
||||
|
||||
Piece board[SQUARE_NB];
|
||||
|
||||
Bitboard byTypeBB[PIECE_TYPE_NB];
|
||||
|
||||
/*
|
||||
0x 00 00 00 00 00 00 00 00
|
||||
unused unused piece1 square1 piece2 square2 piece3 square3
|
||||
*/
|
||||
|
||||
uint64_t millList[4];
|
||||
int millListSize { 0 };
|
||||
|
||||
/*
|
||||
0x 00 00
|
||||
square1 square2
|
||||
|
@ -230,86 +229,86 @@ public:
|
|||
*/
|
||||
Move move { MOVE_NONE };
|
||||
|
||||
Square currentSquare{};
|
||||
|
||||
void createMillTable();
|
||||
|
||||
void mirror(int32_t move_, Square square, bool cmdChange = true);
|
||||
void turn(int32_t move_, Square square, bool cmdChange = true);
|
||||
void rotate(int degrees, int32_t move_, Square square, bool cmdChange = true);
|
||||
|
||||
int inHowManyMills(Square square, Color c, Square squareSelected = SQ_0);
|
||||
bool isAllInMills(Color c);
|
||||
|
||||
int getSurroundedEmptyLocationCount(Square square, bool includeFobidden);
|
||||
void getSurroundedPieceCount(Square square, int &nOurPieces, int &nTheirPieces, int &nBanned, int &nEmpty);
|
||||
bool isAllSurrounded();
|
||||
|
||||
int addMills(Square square);
|
||||
|
||||
static void squareToPolar(Square square, File &file, Rank &rank);
|
||||
static Square polarToSquare(File file, Rank rank);
|
||||
|
||||
static void printBoard();
|
||||
|
||||
Color locationToColor(Square square);
|
||||
|
||||
Piece locations[SQUARE_NB]{};
|
||||
|
||||
Bitboard byTypeBB[PIECE_TYPE_NB];
|
||||
|
||||
/*
|
||||
0x 00 00 00 00 00 00 00 00
|
||||
unused unused piece1 square1 piece2 square2 piece3 square3
|
||||
*/
|
||||
|
||||
uint64_t millList[4];
|
||||
int millListSize{ 0 };
|
||||
|
||||
//Board &operator=(const Board &);
|
||||
|
||||
static const int onBoard[SQUARE_NB];
|
||||
|
||||
static bool isStar(Square square);
|
||||
|
||||
// Relate to Rule
|
||||
static int millTable[SQUARE_NB][LD_NB][FILE_NB - 1];
|
||||
|
||||
private:
|
||||
|
||||
void constructKey();
|
||||
|
||||
int countPiecesOnBoard();
|
||||
|
||||
int countPiecesInHand();
|
||||
|
||||
inline static char colorToCh(Color color)
|
||||
{
|
||||
return static_cast<char>('0' + color);
|
||||
}
|
||||
|
||||
inline static std::string chToStr(char ch)
|
||||
{
|
||||
if (ch == '1') {
|
||||
return "1";
|
||||
} else {
|
||||
return "2";
|
||||
}
|
||||
}
|
||||
|
||||
Color winner;
|
||||
|
||||
Step currentStep {};
|
||||
|
||||
int moveStep {};
|
||||
|
||||
time_t startTime {};
|
||||
|
||||
time_t currentTime {};
|
||||
|
||||
time_t elapsedSeconds[COLOR_NB];
|
||||
|
||||
StateInfo st;
|
||||
};
|
||||
|
||||
inline Color Position::side_to_move() const
|
||||
{
|
||||
return sideToMove;
|
||||
}
|
||||
|
||||
inline char Position::color_to_char(Color color)
|
||||
{
|
||||
return static_cast<char>('0' + color);
|
||||
}
|
||||
|
||||
inline std::string Position::char_to_string(char ch)
|
||||
{
|
||||
if (ch == '1') {
|
||||
return "1";
|
||||
} else {
|
||||
return "2";
|
||||
}
|
||||
}
|
||||
|
||||
inline int Position::getPiecesInHandCount(Color c) const
|
||||
{
|
||||
return nPiecesInHand[c];
|
||||
}
|
||||
|
||||
inline int Position::getPiecesOnBoardCount(Color c) const
|
||||
{
|
||||
return nPiecesOnBoard[c];
|
||||
}
|
||||
|
||||
inline Piece *Position::get_board() const
|
||||
{
|
||||
return (Piece *)board;
|
||||
}
|
||||
|
||||
inline Square Position::current_square() const
|
||||
{
|
||||
return currentSquare;
|
||||
}
|
||||
|
||||
inline int Position::get_step() const
|
||||
{
|
||||
return currentStep;
|
||||
}
|
||||
|
||||
inline enum Phase Position::get_phase() const
|
||||
{
|
||||
return phase;
|
||||
}
|
||||
|
||||
inline enum Action Position::get_action() const
|
||||
{
|
||||
return action;
|
||||
}
|
||||
|
||||
inline const string Position::get_tips() const
|
||||
{
|
||||
return tips;
|
||||
}
|
||||
|
||||
inline const char *Position::cmd_line() const
|
||||
{
|
||||
return cmdline;
|
||||
}
|
||||
|
||||
inline const vector<string> *Position::cmd_list() const
|
||||
{
|
||||
return &cmdlist;
|
||||
}
|
||||
|
||||
inline time_t Position::start_timeb() const
|
||||
{
|
||||
return startTime;
|
||||
}
|
||||
|
||||
inline void Position::set_start_time(int stimeb)
|
||||
{
|
||||
startTime = stimeb;
|
||||
}
|
||||
|
||||
#endif /* POSITION_H */
|
||||
|
|
|
@ -187,7 +187,7 @@ int AIAlgorithm::search(Depth depth)
|
|||
#ifdef THREEFOLD_REPETITION
|
||||
static int nRepetition = 0;
|
||||
|
||||
if (position->getPhase() == PHASE_MOVING) {
|
||||
if (position->get_phase() == PHASE_MOVING) {
|
||||
Key key = position->key();
|
||||
|
||||
if (std::find(moveHistory.begin(), moveHistory.end(), key) != moveHistory.end()) {
|
||||
|
@ -201,7 +201,7 @@ int AIAlgorithm::search(Depth depth)
|
|||
}
|
||||
}
|
||||
|
||||
if (position->getPhase() == PHASE_PLACING) {
|
||||
if (position->get_phase() == PHASE_PLACING) {
|
||||
moveHistory.clear();
|
||||
}
|
||||
#endif // THREEFOLD_REPETITION
|
||||
|
@ -455,7 +455,7 @@ Value AIAlgorithm::search(Depth depth, Value alpha, Value beta)
|
|||
#ifdef TRANSPOSITION_TABLE_ENABLE
|
||||
#ifdef PREFETCH_SUPPORT
|
||||
for (int i = 0; i < nchild; i++) {
|
||||
TranspositionTable::prefetch(pos->getNextPrimaryKey(extMoves[i].move));
|
||||
TranspositionTable::prefetch(pos->next_primary_key(extMoves[i].move));
|
||||
}
|
||||
|
||||
#ifdef PREFETCH_DEBUG
|
||||
|
@ -586,7 +586,7 @@ const char* AIAlgorithm::nextMove()
|
|||
#if 0
|
||||
char charSelect = '*';
|
||||
|
||||
Position::printBoard();
|
||||
Position::print_board();
|
||||
|
||||
int moveIndex = 0;
|
||||
bool foundBest = false;
|
||||
|
@ -663,14 +663,14 @@ const char *AIAlgorithm::moveToCommand(Move move)
|
|||
{
|
||||
File file2;
|
||||
Rank rank2;
|
||||
Position::squareToPolar(to_sq(move), file2, rank2);
|
||||
Position::square_to_polar(to_sq(move), file2, rank2);
|
||||
|
||||
if (move < 0) {
|
||||
sprintf(cmdline, "-(%1u,%1u)", file2, rank2);
|
||||
} else if (move & 0x7f00) {
|
||||
File file1;
|
||||
Rank rank1;
|
||||
Position::squareToPolar(from_sq(move), file1, rank1);
|
||||
Position::square_to_polar(from_sq(move), file1, rank1);
|
||||
sprintf(cmdline, "(%1u,%1u)->(%1u,%1u)", file1, rank1, file2, rank2);
|
||||
} else {
|
||||
sprintf(cmdline, "(%1u,%1u)", file2, rank2);
|
||||
|
|
|
@ -251,7 +251,7 @@ void GameController::gameReset()
|
|||
// 更新棋谱
|
||||
manualListModel.removeRows(0, manualListModel.rowCount());
|
||||
manualListModel.insertRow(0);
|
||||
manualListModel.setData(manualListModel.index(0), position->getCmdLine());
|
||||
manualListModel.setData(manualListModel.index(0), position->cmd_line());
|
||||
currentRow = 0;
|
||||
|
||||
// 发出信号通知主窗口更新LCD显示
|
||||
|
@ -260,7 +260,7 @@ void GameController::gameReset()
|
|||
emit time2Changed(qtime.toString("hh:mm:ss"));
|
||||
|
||||
// 发信号更新状态栏
|
||||
message = QString::fromStdString(position->getTips());
|
||||
message = QString::fromStdString(position->get_tips());
|
||||
emit statusBarChanged(message);
|
||||
|
||||
// 更新比分 LCD 显示
|
||||
|
@ -330,7 +330,7 @@ void GameController::setRule(int ruleNo, Step stepLimited /*= -1*/, int timeLimi
|
|||
}
|
||||
|
||||
// 设置模型规则,重置游戏
|
||||
position->setPosition(&RULES[ruleNo]);
|
||||
position->set_position(&RULES[ruleNo]);
|
||||
tmppos = position;
|
||||
|
||||
// 重置游戏
|
||||
|
@ -565,7 +565,7 @@ void GameController::flip()
|
|||
|
||||
// 更新棋谱
|
||||
int row = 0;
|
||||
for (const auto &str : *(position->getCmdList())) {
|
||||
for (const auto &str : *(position->cmd_list())) {
|
||||
manualListModel.setData(manualListModel.index(row++), str.c_str());
|
||||
}
|
||||
|
||||
|
@ -592,7 +592,7 @@ void GameController::mirror()
|
|||
// 更新棋谱
|
||||
int row = 0;
|
||||
|
||||
for (const auto &str : *(position->getCmdList())) {
|
||||
for (const auto &str : *(position->cmd_list())) {
|
||||
manualListModel.setData(manualListModel.index(row++), str.c_str());
|
||||
}
|
||||
|
||||
|
@ -621,7 +621,7 @@ void GameController::turnRight()
|
|||
// 更新棋谱
|
||||
int row = 0;
|
||||
|
||||
for (const auto &str : *(position->getCmdList())) {
|
||||
for (const auto &str : *(position->cmd_list())) {
|
||||
manualListModel.setData(manualListModel.index(row++), str.c_str());
|
||||
}
|
||||
|
||||
|
@ -647,7 +647,7 @@ void GameController::turnLeft()
|
|||
|
||||
// 更新棋谱
|
||||
int row = 0;
|
||||
for (const auto &str : *(position->getCmdList())) {
|
||||
for (const auto &str : *(position->cmd_list())) {
|
||||
manualListModel.setData(manualListModel.index(row++), str.c_str());
|
||||
}
|
||||
|
||||
|
@ -666,8 +666,8 @@ void GameController::timerEvent(QTimerEvent *event)
|
|||
|
||||
// 玩家的已用时间
|
||||
position->update();
|
||||
remainingTime[BLACK] = position->getElapsedTime(BLACK);
|
||||
remainingTime[WHITE] = position->getElapsedTime(WHITE);
|
||||
remainingTime[BLACK] = position->get_elapsed_time(BLACK);
|
||||
remainingTime[WHITE] = position->get_elapsed_time(WHITE);
|
||||
|
||||
// 如果规则要求计时,则time1和time2表示倒计时
|
||||
if (timeLimit > 0) {
|
||||
|
@ -683,7 +683,7 @@ void GameController::timerEvent(QTimerEvent *event)
|
|||
emit time2Changed(qt2.toString("hh:mm:ss"));
|
||||
|
||||
// 如果胜负已分
|
||||
Color winner = position->getWinner();
|
||||
Color winner = position->get_winner();
|
||||
if (winner != NOBODY) {
|
||||
// 停止计时
|
||||
killTimer(timeID);
|
||||
|
@ -693,7 +693,7 @@ void GameController::timerEvent(QTimerEvent *event)
|
|||
|
||||
#ifndef TRAINING_MODE
|
||||
// 发信号更新状态栏
|
||||
message = QString::fromStdString(position->getTips());
|
||||
message = QString::fromStdString(position->get_tips());
|
||||
emit statusBarChanged(message);
|
||||
|
||||
// 弹框
|
||||
|
@ -771,13 +771,13 @@ bool GameController::actionPiece(QPointF pos)
|
|||
manualListModel.removeRows(currentRow + 1, manualListModel.rowCount() - currentRow - 1);
|
||||
|
||||
// 如果再决出胜负后悔棋,则重新启动计时
|
||||
if (position->getWinner() == NOBODY) {
|
||||
if (position->get_winner() == NOBODY) {
|
||||
|
||||
// 重新启动计时
|
||||
timeID = startTimer(100);
|
||||
|
||||
// 发信号更新状态栏
|
||||
message = QString::fromStdString(position->getTips());
|
||||
message = QString::fromStdString(position->get_tips());
|
||||
emit statusBarChanged(message);
|
||||
#ifndef MOBILE_APP_UI
|
||||
}
|
||||
|
@ -788,7 +788,7 @@ bool GameController::actionPiece(QPointF pos)
|
|||
}
|
||||
|
||||
// 如果未开局则开局
|
||||
if (position->getPhase() == PHASE_READY)
|
||||
if (position->get_phase() == PHASE_READY)
|
||||
gameStart();
|
||||
|
||||
// 判断执行选子、落子或去子
|
||||
|
@ -796,15 +796,15 @@ bool GameController::actionPiece(QPointF pos)
|
|||
PieceItem *piece = nullptr;
|
||||
QGraphicsItem *item = scene.itemAt(pos, QTransform());
|
||||
|
||||
switch (position->getAction()) {
|
||||
switch (position->get_action()) {
|
||||
case ACTION_PLACE:
|
||||
if (position->_placePiece(file, rank)) {
|
||||
if (position->getAction() == ACTION_REMOVE) {
|
||||
if (position->get_action() == ACTION_REMOVE) {
|
||||
// 播放成三音效
|
||||
playSound(GAME_SOUND_MILL, position->getSideToMove());
|
||||
playSound(GAME_SOUND_MILL, position->side_to_move());
|
||||
} else {
|
||||
// 播放移动棋子音效
|
||||
playSound(GAME_SOUND_DROG, position->getSideToMove());
|
||||
playSound(GAME_SOUND_DROG, position->side_to_move());
|
||||
}
|
||||
result = true;
|
||||
break;
|
||||
|
@ -819,22 +819,22 @@ bool GameController::actionPiece(QPointF pos)
|
|||
break;
|
||||
if (position->_selectPiece(file, rank)) {
|
||||
// 播放选子音效
|
||||
playSound(GAME_SOUND_SELECT, position->getSideToMove());
|
||||
playSound(GAME_SOUND_SELECT, position->side_to_move());
|
||||
result = true;
|
||||
} else {
|
||||
// 播放禁止音效
|
||||
playSound(GAME_SOUND_BANNED, position->getSideToMove());
|
||||
playSound(GAME_SOUND_BANNED, position->side_to_move());
|
||||
}
|
||||
break;
|
||||
|
||||
case ACTION_REMOVE:
|
||||
if (position->_removePiece(file, rank)) {
|
||||
// 播放音效
|
||||
playSound(GAME_SOUND_REMOVE, position->getSideToMove());
|
||||
playSound(GAME_SOUND_REMOVE, position->side_to_move());
|
||||
result = true;
|
||||
} else {
|
||||
// 播放禁止音效
|
||||
playSound(GAME_SOUND_BANNED, position->getSideToMove());
|
||||
playSound(GAME_SOUND_BANNED, position->side_to_move());
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -845,7 +845,7 @@ bool GameController::actionPiece(QPointF pos)
|
|||
|
||||
if (result) {
|
||||
// 发信号更新状态栏
|
||||
message = QString::fromStdString(position->getTips());
|
||||
message = QString::fromStdString(position->get_tips());
|
||||
emit statusBarChanged(message);
|
||||
|
||||
// 将新增的棋谱行插入到ListModel
|
||||
|
@ -853,7 +853,7 @@ bool GameController::actionPiece(QPointF pos)
|
|||
int k = 0;
|
||||
|
||||
// 输出命令行
|
||||
for (const auto & i : *(position->getCmdList())) {
|
||||
for (const auto & i : *(position->cmd_list())) {
|
||||
// 跳过已添加的,因标准list容器没有下标
|
||||
if (k++ <= currentRow)
|
||||
continue;
|
||||
|
@ -863,7 +863,7 @@ bool GameController::actionPiece(QPointF pos)
|
|||
|
||||
// 播放胜利或失败音效
|
||||
#ifndef DONOT_PLAY_WIN_SOUND
|
||||
Color winner = position->getWinner();
|
||||
Color winner = position->get_winner();
|
||||
if (winner != NOBODY &&
|
||||
(manualListModel.data(manualListModel.index(currentRow - 1))).toString().contains("Time over."))
|
||||
playSound(GAME_SOUND_WIN, winner);
|
||||
|
@ -871,7 +871,7 @@ bool GameController::actionPiece(QPointF pos)
|
|||
|
||||
// AI设置
|
||||
// 如果还未决出胜负
|
||||
if (position->getWinner() == NOBODY) {
|
||||
if (position->get_winner() == NOBODY) {
|
||||
resumeAiThreads(position->sideToMove);
|
||||
}
|
||||
// 如果已经决出胜负
|
||||
|
@ -903,7 +903,7 @@ bool GameController::giveUp()
|
|||
int k = 0;
|
||||
|
||||
// 输出命令行
|
||||
for (const auto & i : *(position->getCmdList())) {
|
||||
for (const auto & i : *(position->cmd_list())) {
|
||||
// 跳过已添加的,因标准list容器没有下标
|
||||
if (k++ <= currentRow)
|
||||
continue;
|
||||
|
@ -911,8 +911,8 @@ bool GameController::giveUp()
|
|||
manualListModel.setData(manualListModel.index(currentRow), i.c_str());
|
||||
}
|
||||
|
||||
if (position->getWinner() != NOBODY)
|
||||
playSound(GAME_SOUND_GIVE_UP, position->getSideToMove());
|
||||
if (position->get_winner() != NOBODY)
|
||||
playSound(GAME_SOUND_GIVE_UP, position->side_to_move());
|
||||
|
||||
#endif // TRAINING_MODE
|
||||
|
||||
|
@ -937,7 +937,7 @@ bool GameController::command(const QString &cmd, bool update /* = true */)
|
|||
// 声音
|
||||
sound_t soundType = GAME_SOUND_NONE;
|
||||
|
||||
switch (position->getAction()) {
|
||||
switch (position->get_action()) {
|
||||
case ACTION_SELECT:
|
||||
case ACTION_PLACE:
|
||||
soundType = GAME_SOUND_DROG;
|
||||
|
@ -951,7 +951,7 @@ bool GameController::command(const QString &cmd, bool update /* = true */)
|
|||
#endif
|
||||
|
||||
// 如果未开局则开局
|
||||
if (position->getPhase() == PHASE_READY) {
|
||||
if (position->get_phase() == PHASE_READY) {
|
||||
gameStart();
|
||||
}
|
||||
|
||||
|
@ -959,37 +959,37 @@ bool GameController::command(const QString &cmd, bool update /* = true */)
|
|||
return false;
|
||||
|
||||
#ifndef TRAINING_MODE
|
||||
if (soundType == GAME_SOUND_DROG && position->getAction() == ACTION_REMOVE) {
|
||||
if (soundType == GAME_SOUND_DROG && position->get_action() == ACTION_REMOVE) {
|
||||
soundType = GAME_SOUND_MILL;
|
||||
}
|
||||
|
||||
if (update) {
|
||||
playSound(soundType, position->getSideToMove());
|
||||
playSound(soundType, position->side_to_move());
|
||||
updateScence(position);
|
||||
}
|
||||
|
||||
// 发信号更新状态栏
|
||||
message = QString::fromStdString(position->getTips());
|
||||
message = QString::fromStdString(position->get_tips());
|
||||
emit statusBarChanged(message);
|
||||
|
||||
// 对于新开局
|
||||
if (position->getCmdList()->size() <= 1) {
|
||||
if (position->cmd_list()->size() <= 1) {
|
||||
manualListModel.removeRows(0, manualListModel.rowCount());
|
||||
manualListModel.insertRow(0);
|
||||
manualListModel.setData(manualListModel.index(0), position->getCmdLine());
|
||||
manualListModel.setData(manualListModel.index(0), position->cmd_line());
|
||||
currentRow = 0;
|
||||
}
|
||||
// 对于当前局
|
||||
else {
|
||||
currentRow = manualListModel.rowCount() - 1;
|
||||
// 跳过已添加行,迭代器不支持+运算符,只能一个个++
|
||||
auto i = (position->getCmdList()->begin());
|
||||
for (int r = 0; i != (position->getCmdList())->end(); i++) {
|
||||
auto i = (position->cmd_list()->begin());
|
||||
for (int r = 0; i != (position->cmd_list())->end(); i++) {
|
||||
if (r++ > currentRow)
|
||||
break;
|
||||
}
|
||||
// 将新增的棋谱行插入到ListModel
|
||||
while (i != position->getCmdList()->end()) {
|
||||
while (i != position->cmd_list()->end()) {
|
||||
manualListModel.insertRow(++currentRow);
|
||||
manualListModel.setData(manualListModel.index(currentRow), (*i++).c_str());
|
||||
}
|
||||
|
@ -997,7 +997,7 @@ bool GameController::command(const QString &cmd, bool update /* = true */)
|
|||
|
||||
// 播放胜利或失败音效
|
||||
#ifndef DONOT_PLAY_WIN_SOUND
|
||||
Color winner = position->getWinner();
|
||||
Color winner = position->get_winner();
|
||||
if (winner != NOBODY &&
|
||||
(manualListModel.data(manualListModel.index(currentRow - 1))).toString().contains("Time over.")) {
|
||||
playSound(GAME_SOUND_WIN, winner);
|
||||
|
@ -1007,7 +1007,7 @@ bool GameController::command(const QString &cmd, bool update /* = true */)
|
|||
|
||||
// AI设置
|
||||
// 如果还未决出胜负
|
||||
if (position->getWinner() == NOBODY) {
|
||||
if (position->get_winner() == NOBODY) {
|
||||
resumeAiThreads(position->sideToMove);
|
||||
}
|
||||
// 如果已经决出胜负
|
||||
|
@ -1080,7 +1080,7 @@ bool GameController::command(const QString &cmd, bool update /* = true */)
|
|||
|
||||
#ifdef MESSAGEBOX_ENABLE
|
||||
// 弹框
|
||||
message = QString::fromStdString(position->getTips());
|
||||
message = QString::fromStdString(position->get_tips());
|
||||
QMessageBox::about(NULL, "游戏结果", message);
|
||||
#endif
|
||||
}
|
||||
|
@ -1120,7 +1120,7 @@ bool GameController::phaseChange(int row, bool forceUpdate)
|
|||
}
|
||||
|
||||
// 下面这步关键,会让悔棋者承担时间损失
|
||||
tmppos->setStartTime(static_cast<int>(position->getStartTimeb()));
|
||||
tmppos->set_start_time(static_cast<int>(position->start_timeb()));
|
||||
|
||||
// 刷新棋局场景
|
||||
updateScence(tmppos);
|
||||
|
@ -1141,7 +1141,7 @@ bool GameController::updateScence()
|
|||
bool GameController::updateScence(Position *p)
|
||||
{
|
||||
#ifndef TRAINING_MODE
|
||||
const Piece *board = p->getBoardLocations();
|
||||
const Piece *board = p->get_board();
|
||||
QPointF pos;
|
||||
|
||||
// game类中的棋子代码
|
||||
|
@ -1207,7 +1207,7 @@ bool GameController::updateScence(Position *p)
|
|||
deletedPiece = piece;
|
||||
|
||||
#ifdef GAME_PLACING_SHOW_REMOVED_PIECES
|
||||
if (position->getPhase() == PHASE_MOVING) {
|
||||
if (position->get_phase() == PHASE_MOVING) {
|
||||
#endif
|
||||
QPropertyAnimation *animation = new QPropertyAnimation(piece, "pos");
|
||||
animation->setDuration(durationTime);
|
||||
|
@ -1225,7 +1225,7 @@ bool GameController::updateScence(Position *p)
|
|||
}
|
||||
|
||||
// 添加摆棋阶段禁子点
|
||||
if (rule.hasBannedLocations && p->getPhase() == 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));
|
||||
|
@ -1244,7 +1244,7 @@ bool GameController::updateScence(Position *p)
|
|||
}
|
||||
|
||||
// 走棋阶段清除禁子点
|
||||
if (rule.hasBannedLocations && p->getPhase() != 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();
|
||||
|
@ -1252,9 +1252,9 @@ bool GameController::updateScence(Position *p)
|
|||
}
|
||||
|
||||
// 选中当前棋子
|
||||
int ipos = p->getCurrentSquare();
|
||||
int ipos = p->current_square();
|
||||
if (ipos) {
|
||||
key = board[p->getCurrentSquare()];
|
||||
key = board[p->current_square()];
|
||||
ipos = key & B_STONE ? (key - B_STONE_1) * 2 : (key - W_STONE_1) * 2 + 1;
|
||||
if (ipos >= 0 && ipos < nTotalPieces) {
|
||||
currentPiece = pieceList.at(static_cast<size_t>(ipos));
|
||||
|
@ -1306,7 +1306,7 @@ void GameController::showTestWindow()
|
|||
|
||||
void GameController::humanGiveUp()
|
||||
{
|
||||
if (position->getWinner() == NOBODY) {
|
||||
if (position->get_winner() == NOBODY) {
|
||||
giveUp();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -608,7 +608,7 @@ void MillGameWindow::on_actionNew_N_triggered()
|
|||
QString strDate = QDateTime::currentDateTime().toString("yyyy-MM-dd");
|
||||
QString whoWin;
|
||||
|
||||
switch (gameController->getPosition()->getWinner()) {
|
||||
switch (gameController->getPosition()->get_winner()) {
|
||||
case BLACK:
|
||||
whoWin = "Black-Win";
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue