Use EFFECTIVE_SQUARE_NB

This commit is contained in:
Calcitem 2020-12-28 21:19:42 +08:00
parent 66b6eee8e9
commit afcc4a953d
6 changed files with 15 additions and 19 deletions

View File

@ -121,8 +121,7 @@ Value Evaluation<T>::value()
break;
case PHASE_GAMEOVER:
if (pos.pieces_count_on_board(BLACK) + pos.pieces_count_on_board(WHITE) >=
RANK_NB * FILE_NB) {
if (pos.pieces_count_on_board(BLACK) + pos.pieces_count_on_board(WHITE) >= EFFECTIVE_SQUARE_NB) {
if (rule.isBlackLoseButNotDrawWhenBoardFull) {
value -= VALUE_MATE;
} else {

View File

@ -51,13 +51,10 @@ template<>
ExtMove *generate<MOVE>(Position &pos, ExtMove *moveList)
{
Square newSquare, oldSquare;
const int MOVE_PRIORITY_TABLE_SIZE = FILE_NB * RANK_NB;
ExtMove *cur = moveList;
// move piece that location weak first
for (int i = MOVE_PRIORITY_TABLE_SIZE - 1; i >= 0; i--) {
for (int i = EFFECTIVE_SQUARE_NB - 1; i >= 0; i--) {
oldSquare = MoveList<LEGAL>::movePriorityTable[i];
if (!pos.select_piece(oldSquare)) {
@ -97,12 +94,10 @@ ExtMove *generate<REMOVE>(Position &pos, ExtMove *moveList)
Color us = pos.side_to_move();
Color them = ~us;
const int MOVE_PRIORITY_TABLE_SIZE = FILE_NB * RANK_NB;
ExtMove *cur = moveList;
if (pos.is_all_in_mills(them)) {
for (int i = MOVE_PRIORITY_TABLE_SIZE - 1; i >= 0; i--) {
for (int i = EFFECTIVE_SQUARE_NB - 1; i >= 0; i--) {
s = MoveList<LEGAL>::movePriorityTable[i];
if (pos.get_board()[s] & make_piece(them)) {
*cur++ = (Move)-s;
@ -112,7 +107,7 @@ ExtMove *generate<REMOVE>(Position &pos, ExtMove *moveList)
}
// not is all in mills
for (int i = MOVE_PRIORITY_TABLE_SIZE - 1; i >= 0; i--) {
for (int i = EFFECTIVE_SQUARE_NB - 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)) {
@ -129,8 +124,6 @@ ExtMove *generate<REMOVE>(Position &pos, ExtMove *moveList)
template<>
ExtMove *generate<LEGAL>(Position &pos, ExtMove *moveList)
{
const int MOVE_PRIORITY_TABLE_SIZE = FILE_NB * RANK_NB;
ExtMove *cur = moveList;
switch (pos.get_action()) {

View File

@ -69,18 +69,22 @@ struct MoveList
explicit MoveList(/* const */ Position &pos) : last(generate<T>(pos, moveList))
{
}
const ExtMove *begin() const
{
return moveList;
}
const ExtMove *end() const
{
return last;
}
size_t size() const
{
return last - moveList;
}
bool contains(Move move) const
{
return std::find(begin(), end(), move) != end();
@ -89,7 +93,7 @@ struct MoveList
static void create();
static void shuffle();
inline static std::array<Square, FILE_NB *RANK_NB> movePriorityTable {
inline static std::array<Square, EFFECTIVE_SQUARE_NB> movePriorityTable {
SQ_8, SQ_9, SQ_10, SQ_11, SQ_12, SQ_13, SQ_14, SQ_15,
SQ_16, SQ_17, SQ_18, SQ_19, SQ_20, SQ_21, SQ_22, SQ_23,
SQ_24, SQ_25, SQ_26, SQ_27, SQ_28, SQ_29, SQ_30, SQ_31,

View File

@ -1154,7 +1154,7 @@ bool Position::check_gameover_condition()
return true;
}
if (pieceCountOnBoard[BLACK] + pieceCountOnBoard[WHITE] >= RANK_NB * FILE_NB) {
if (pieceCountOnBoard[BLACK] + pieceCountOnBoard[WHITE] >= EFFECTIVE_SQUARE_NB) {
if (rule.isBlackLoseButNotDrawWhenBoardFull) {
set_gameover(WHITE, LOSE_REASON_BOARD_IS_FULL);
} else {
@ -1756,7 +1756,7 @@ void Position::surrounded_pieces_count(Square s, int &nOurPieces, int &nTheirPie
bool Position::is_all_surrounded() const
{
// Full
if (pieceCountOnBoard[BLACK] + pieceCountOnBoard[WHITE] >= RANK_NB * FILE_NB)
if (pieceCountOnBoard[BLACK] + pieceCountOnBoard[WHITE] >= EFFECTIVE_SQUARE_NB)
return true;
// Can fly
@ -1966,8 +1966,8 @@ void Position::turn(vector <string> &cmdlist, bool cmdChange /*= true*/)
for (r = 0; r < RANK_NB; r++) {
ch = board[RANK_NB + r];
board[RANK_NB + r] = board[RANK_NB * FILE_NB + r];
board[RANK_NB * FILE_NB + r] = ch;
board[RANK_NB + r] = board[EFFECTIVE_SQUARE_NB + r];
board[EFFECTIVE_SQUARE_NB + r] = ch;
}
reset_bb();

View File

@ -177,7 +177,7 @@ QPointF BoardItem::polar2pos(File file, Rank rank)
bool BoardItem::pos2polar(QPointF pos, File &file, Rank &rank)
{
// 寻找最近的落子点
for (int i = 0; i < FILE_NB * RANK_NB; i++) {
for (int i = 0; i < EFFECTIVE_SQUARE_NB; i++) {
// 如果pos点在落子点附近
if (QLineF(pos, position[i]).length() < PIECE_SIZE / 6) {
file = File(i / RANK_NB + 1);

View File

@ -75,7 +75,7 @@ private:
int sizeShadow {5};
// 24个落子点
QPointF position[FILE_NB * RANK_NB];
QPointF position[EFFECTIVE_SQUARE_NB];
// 是否有斜线
bool hasObliqueLine {false};