position: 新增 count() 函数并应用
This commit is contained in:
parent
345764f058
commit
ed5227041c
|
@ -114,7 +114,7 @@ void MovePicker::score()
|
|||
// for 12 men, white 's 2nd move place star point is as important as close mill (TODO)
|
||||
#ifdef ALPHABETA_AI
|
||||
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))) {
|
||||
cur->value += RATING_STAR_SQUARE;
|
||||
}
|
||||
|
|
|
@ -77,10 +77,9 @@ public:
|
|||
|
||||
// Position representation
|
||||
Piece piece_on(Square s) const;
|
||||
bool empty(Square s) const;
|
||||
Color color_on(Square s);
|
||||
int getPiecesInHandCount(Color c) const;
|
||||
int getPiecesOnBoardCount(Color c) const;
|
||||
bool empty(Square s) const;
|
||||
template<PieceType Pt> int count(Color c) const;
|
||||
|
||||
// Properties of moves
|
||||
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 nPiecesOnBoard[c];
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline Piece *Position::get_board() const
|
||||
|
|
|
@ -121,15 +121,15 @@ Depth AIAlgorithm::changeDepth()
|
|||
|
||||
if (pos->phase & PHASE_PLACING) {
|
||||
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 {
|
||||
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) {
|
||||
int pb = pos->getPiecesOnBoardCount(BLACK);
|
||||
int pw = pos->getPiecesOnBoardCount(WHITE);
|
||||
int pb = pos->count<ON_BOARD>(BLACK);
|
||||
int pw = pos->count<ON_BOARD>(WHITE);
|
||||
|
||||
int pieces = pb + pw;
|
||||
int diff = pb - pw;
|
||||
|
|
|
@ -228,7 +228,10 @@ enum PieceType : uint16_t
|
|||
WHITE_STONE = 2,
|
||||
BAN = 3,
|
||||
ALL_PIECES = 0,
|
||||
PIECE_TYPE_NB = 4
|
||||
PIECE_TYPE_NB = 4,
|
||||
|
||||
IN_HAND = 0x10,
|
||||
ON_BOARD = 0x20,
|
||||
};
|
||||
|
||||
enum Piece : uint8_t
|
||||
|
|
|
@ -1180,10 +1180,10 @@ bool GameController::updateScence(Position *p)
|
|||
if (j == (RANK_NB) * (FILE_NB + 1)) {
|
||||
// 判断是被吃掉的子,还是未安放的子
|
||||
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;
|
||||
} 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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue