position: 新增 count() 函数并应用

This commit is contained in:
Calcitem 2020-08-31 23:27:56 +08:00
parent 345764f058
commit ed5227041c
5 changed files with 20 additions and 17 deletions

View File

@ -114,7 +114,7 @@ void MovePicker::score()
// for 12 men, white 's 2nd move place star point is as important as close mill (TODO) // for 12 men, white 's 2nd move place star point is as important as close mill (TODO)
#ifdef ALPHABETA_AI #ifdef ALPHABETA_AI
if (rule.nTotalPiecesEachSide == 12 && if (rule.nTotalPiecesEachSide == 12 &&
pos->getPiecesOnBoardCount(WHITE) < 2 && // patch: only when white's 2nd move pos->count<ON_BOARD>(WHITE) < 2 && // patch: only when white's 2nd move
Position::is_star_square(static_cast<Square>(m))) { Position::is_star_square(static_cast<Square>(m))) {
cur->value += RATING_STAR_SQUARE; cur->value += RATING_STAR_SQUARE;
} }

View File

@ -77,10 +77,9 @@ public:
// Position representation // Position representation
Piece piece_on(Square s) const; Piece piece_on(Square s) const;
bool empty(Square s) const;
Color color_on(Square s); Color color_on(Square s);
int getPiecesInHandCount(Color c) const; bool empty(Square s) const;
int getPiecesOnBoardCount(Color c) const; template<PieceType Pt> int count(Color c) const;
// Properties of moves // Properties of moves
bool select_piece(Square s); bool select_piece(Square s);
@ -275,14 +274,15 @@ inline std::string Position::char_to_string(char ch)
} }
} }
inline int Position::getPiecesInHandCount(Color c) const template<PieceType Pt> inline int Position::count(Color c) const
{ {
return nPiecesInHand[c]; if (Pt == ON_BOARD) {
} return nPiecesOnBoard[c];
} else if (Pt == IN_HAND) {
return nPiecesInHand[c];
}
inline int Position::getPiecesOnBoardCount(Color c) const return 0;
{
return nPiecesOnBoard[c];
} }
inline Piece *Position::get_board() const inline Piece *Position::get_board() const

View File

@ -121,15 +121,15 @@ Depth AIAlgorithm::changeDepth()
if (pos->phase & PHASE_PLACING) { if (pos->phase & PHASE_PLACING) {
if (rule.nTotalPiecesEachSide == 12) { if (rule.nTotalPiecesEachSide == 12) {
d = placingDepthTable_12[rule.nTotalPiecesEachSide * 2 - pos->getPiecesInHandCount(BLACK) - pos->getPiecesInHandCount(WHITE)]; d = placingDepthTable_12[rule.nTotalPiecesEachSide * 2 - pos->count<IN_HAND>(BLACK) - pos->count<IN_HAND>(WHITE)];
} else { } else {
d = placingDepthTable_9[rule.nTotalPiecesEachSide * 2 - pos->getPiecesInHandCount(BLACK) - pos->getPiecesInHandCount(WHITE)]; d = placingDepthTable_9[rule.nTotalPiecesEachSide * 2 - pos->count<IN_HAND>(BLACK) - pos->count<IN_HAND>(WHITE)];
} }
} }
if (pos->phase & PHASE_MOVING) { if (pos->phase & PHASE_MOVING) {
int pb = pos->getPiecesOnBoardCount(BLACK); int pb = pos->count<ON_BOARD>(BLACK);
int pw = pos->getPiecesOnBoardCount(WHITE); int pw = pos->count<ON_BOARD>(WHITE);
int pieces = pb + pw; int pieces = pb + pw;
int diff = pb - pw; int diff = pb - pw;

View File

@ -228,7 +228,10 @@ enum PieceType : uint16_t
WHITE_STONE = 2, WHITE_STONE = 2,
BAN = 3, BAN = 3,
ALL_PIECES = 0, ALL_PIECES = 0,
PIECE_TYPE_NB = 4 PIECE_TYPE_NB = 4,
IN_HAND = 0x10,
ON_BOARD = 0x20,
}; };
enum Piece : uint8_t enum Piece : uint8_t

View File

@ -1180,10 +1180,10 @@ bool GameController::updateScence(Position *p)
if (j == (RANK_NB) * (FILE_NB + 1)) { if (j == (RANK_NB) * (FILE_NB + 1)) {
// 判断是被吃掉的子,还是未安放的子 // 判断是被吃掉的子,还是未安放的子
if (key & B_STONE) { if (key & B_STONE) {
pos = (key - 0x11 < nTotalPieces / 2 - p->getPiecesInHandCount(BLACK)) ? pos = (key - 0x11 < nTotalPieces / 2 - p->count<IN_HAND>(BLACK)) ?
scene.pos_p2_g : scene.pos_p1; scene.pos_p2_g : scene.pos_p1;
} else { } else {
pos = (key - 0x21 < nTotalPieces / 2 - p->getPiecesInHandCount(WHITE)) ? pos = (key - 0x21 < nTotalPieces / 2 - p->count<IN_HAND>(WHITE)) ?
scene.pos_p1_g : scene.pos_p2; scene.pos_p1_g : scene.pos_p2;
} }