movegen/movepick: Position * 改为 Position &
This commit is contained in:
parent
490983195d
commit
31d9bd8294
|
@ -284,30 +284,30 @@ void MoveList::shuffle()
|
|||
|
||||
/// generate generates all the legal moves in the given position
|
||||
|
||||
ExtMove *generate(Position *position, ExtMove *moveList)
|
||||
ExtMove *generate(Position &position, ExtMove *moveList)
|
||||
{
|
||||
Square s;
|
||||
|
||||
Color us = position->side_to_move();
|
||||
Color us = position.side_to_move();
|
||||
Color them = ~us;
|
||||
|
||||
const int MOVE_PRIORITY_TABLE_SIZE = FILE_NB * RANK_NB;
|
||||
|
||||
ExtMove *cur = moveList;
|
||||
|
||||
switch (position->action) {
|
||||
switch (position.action) {
|
||||
case ACTION_SELECT:
|
||||
case ACTION_PLACE:
|
||||
if (position->phase & (PHASE_PLACING | PHASE_READY)) {
|
||||
if (position.phase & (PHASE_PLACING | PHASE_READY)) {
|
||||
for (auto i : MoveList::movePriorityTable) {
|
||||
if (position->board[i]) {
|
||||
if (position.board[i]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
#ifdef MCTS_AI
|
||||
moves.push_back((Move)i);
|
||||
#else // MCTS_AI
|
||||
if (position->phase != PHASE_READY) {
|
||||
if (position.phase != PHASE_READY) {
|
||||
*cur++ = (Move)i;
|
||||
} else {
|
||||
#ifdef FIRST_MOVE_STAR_PREFERRED
|
||||
|
@ -323,22 +323,22 @@ ExtMove *generate(Position *position, ExtMove *moveList)
|
|||
break;
|
||||
}
|
||||
|
||||
if (position->phase & PHASE_MOVING) {
|
||||
if (position.phase & PHASE_MOVING) {
|
||||
Square newSquare, oldSquare;
|
||||
|
||||
// move piece that location weak first
|
||||
for (int i = MOVE_PRIORITY_TABLE_SIZE - 1; i >= 0; i--) {
|
||||
oldSquare = MoveList::movePriorityTable[i];
|
||||
|
||||
if (!position->select_piece(oldSquare)) {
|
||||
if (!position.select_piece(oldSquare)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (position->pieceCountOnBoard[position->sideToMove] > rule.nPiecesAtLeast ||
|
||||
if (position.pieceCountOnBoard[position.sideToMove] > rule.nPiecesAtLeast ||
|
||||
!rule.allowFlyWhenRemainThreePieces) {
|
||||
for (int direction = MD_BEGIN; direction < MD_NB; direction++) {
|
||||
newSquare = static_cast<Square>(MoveList::moveTable[oldSquare][direction]);
|
||||
if (newSquare && !position->board[newSquare]) {
|
||||
if (newSquare && !position.board[newSquare]) {
|
||||
Move m = make_move(oldSquare, newSquare);
|
||||
*cur++ = (Move)m;
|
||||
}
|
||||
|
@ -346,7 +346,7 @@ ExtMove *generate(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->board[newSquare]) {
|
||||
if (!position.board[newSquare]) {
|
||||
Move m = make_move(oldSquare, newSquare);
|
||||
*cur++ = (Move)m;
|
||||
}
|
||||
|
@ -357,10 +357,10 @@ ExtMove *generate(Position *position, ExtMove *moveList)
|
|||
break;
|
||||
|
||||
case ACTION_REMOVE:
|
||||
if (position->is_all_in_mills(them)) {
|
||||
if (position.is_all_in_mills(them)) {
|
||||
for (int i = MOVE_PRIORITY_TABLE_SIZE - 1; i >= 0; i--) {
|
||||
s = MoveList::movePriorityTable[i];
|
||||
if (position->board[s]& (them << PLAYER_SHIFT)) {
|
||||
if (position.board[s]& (them << PLAYER_SHIFT)) {
|
||||
*cur++ = (Move)-s;
|
||||
}
|
||||
}
|
||||
|
@ -370,8 +370,8 @@ ExtMove *generate(Position *position, ExtMove *moveList)
|
|||
// not is all in mills
|
||||
for (int i = MOVE_PRIORITY_TABLE_SIZE - 1; i >= 0; i--) {
|
||||
s = MoveList::movePriorityTable[i];
|
||||
if (position->board[s] & (them << PLAYER_SHIFT)) {
|
||||
if (rule.allowRemovePieceInMill || !position->in_how_many_mills(s, NOBODY)) {
|
||||
if (position.board[s] & (them << PLAYER_SHIFT)) {
|
||||
if (rule.allowRemovePieceInMill || !position.in_how_many_mills(s, NOBODY)) {
|
||||
*cur++ = (Move)-s;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,13 +51,13 @@ inline bool operator<(const ExtMove &f, const ExtMove &s)
|
|||
return f.value < s.value;
|
||||
}
|
||||
|
||||
ExtMove *generate(Position *pos, ExtMove *moveList);
|
||||
ExtMove *generate(Position &pos, ExtMove *moveList);
|
||||
|
||||
/// The MoveList struct is a simple wrapper around generate(). It sometimes comes
|
||||
/// in handy to use this class instead of the low level generate() function.
|
||||
struct MoveList
|
||||
{
|
||||
explicit MoveList(Position *pos) : last(generate(pos, moveList)) {}
|
||||
explicit MoveList(Position &pos) : last(generate(pos, moveList)) {}
|
||||
|
||||
const ExtMove *begin() const
|
||||
{
|
||||
|
|
|
@ -46,7 +46,7 @@ void partial_insertion_sort(ExtMove *begin, ExtMove *end, int limit)
|
|||
/// ordering is at the current node.
|
||||
|
||||
/// MovePicker constructor for the main search
|
||||
MovePicker::MovePicker(Position *p)
|
||||
MovePicker::MovePicker(Position &p)
|
||||
: pos(p)
|
||||
{
|
||||
#ifdef HOSTORY_HEURISTIC
|
||||
|
@ -67,7 +67,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 = pos->in_how_many_mills(sq, pos->sideToMove, sqsrc);
|
||||
int nOurMills = pos.in_how_many_mills(sq, pos.sideToMove, sqsrc);
|
||||
int nTheirMills = 0;
|
||||
|
||||
#ifdef SORT_MOVE_WITH_HUMAN_KNOWLEDGES
|
||||
|
@ -78,17 +78,17 @@ void MovePicker::score()
|
|||
#ifdef ALPHABETA_AI
|
||||
cur->value += RATING_ONE_MILL * nOurMills;
|
||||
#endif
|
||||
} else if (pos->get_phase() == PHASE_PLACING) {
|
||||
} else if (pos.get_phase() == PHASE_PLACING) {
|
||||
// placing phrase, check if place sq can block their close mill
|
||||
nTheirMills = pos->in_how_many_mills(sq, pos->them);
|
||||
nTheirMills = pos.in_how_many_mills(sq, pos.them);
|
||||
#ifdef ALPHABETA_AI
|
||||
cur->value += RATING_BLOCK_ONE_MILL * nTheirMills;
|
||||
#endif
|
||||
}
|
||||
#if 1
|
||||
else if (pos->get_phase() == PHASE_MOVING) {
|
||||
else if (pos.get_phase() == PHASE_MOVING) {
|
||||
// moving phrase, check if place sq can block their close mill
|
||||
nTheirMills = pos->in_how_many_mills(sq, pos->them);
|
||||
nTheirMills = pos.in_how_many_mills(sq, pos.them);
|
||||
|
||||
if (nTheirMills) {
|
||||
int nOurPieces = 0;
|
||||
|
@ -96,7 +96,7 @@ void MovePicker::score()
|
|||
int nBanned = 0;
|
||||
int nEmpty = 0;
|
||||
|
||||
pos->surrounded_pieces_count(sq, nOurPieces, nTheirPieces, nBanned, nEmpty);
|
||||
pos.surrounded_pieces_count(sq, nOurPieces, nTheirPieces, nBanned, nEmpty);
|
||||
|
||||
#ifdef ALPHABETA_AI
|
||||
if (sq % 2 == 0 && nTheirPieces == 3) {
|
||||
|
@ -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->count<ON_BOARD>(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;
|
||||
}
|
||||
|
@ -125,7 +125,7 @@ void MovePicker::score()
|
|||
int nBanned = 0;
|
||||
int nEmpty = 0;
|
||||
|
||||
pos->surrounded_pieces_count(sq, nOurPieces, nTheirPieces, nBanned, nEmpty);
|
||||
pos.surrounded_pieces_count(sq, nOurPieces, nTheirPieces, nBanned, nEmpty);
|
||||
|
||||
#ifdef ALPHABETA_AI
|
||||
if (nOurMills > 0) {
|
||||
|
@ -143,7 +143,7 @@ void MovePicker::score()
|
|||
}
|
||||
|
||||
// remove point is in their mill
|
||||
nTheirMills = pos->in_how_many_mills(sq, pos->them);
|
||||
nTheirMills = pos.in_how_many_mills(sq, pos.them);
|
||||
if (nTheirMills) {
|
||||
if (nTheirPieces >= 2) {
|
||||
// if nearby their piece, prefer do not remove
|
||||
|
|
|
@ -50,7 +50,7 @@ class MovePicker
|
|||
public:
|
||||
MovePicker(const MovePicker &) = delete;
|
||||
MovePicker &operator=(const MovePicker &) = delete;
|
||||
MovePicker(Position *position);
|
||||
MovePicker(Position &position);
|
||||
|
||||
Move next_move();
|
||||
|
||||
|
@ -68,7 +68,7 @@ public:
|
|||
return endMoves;
|
||||
}
|
||||
|
||||
Position *pos;
|
||||
Position &pos;
|
||||
Move ttMove { MOVE_NONE };
|
||||
ExtMove *cur, *endMoves;
|
||||
ExtMove moves[MAX_MOVES] { MOVE_NONE };
|
||||
|
|
|
@ -809,7 +809,7 @@ Value search(Position *pos, Stack<Position> &ss, Depth depth, Depth originDepth,
|
|||
return bestValue;
|
||||
}
|
||||
|
||||
MovePicker mp(pos);
|
||||
MovePicker mp(*pos);
|
||||
Move nextMove = mp.next_move();
|
||||
int moveCount = mp.move_count();
|
||||
|
||||
|
|
|
@ -168,7 +168,7 @@ void ThreadPool::clear()
|
|||
/// ThreadPool::start_thinking() wakes up main thread waiting in idle_loop() and
|
||||
/// returns immediately. Main thread will wake up other threads and start the search.
|
||||
|
||||
void ThreadPool::start_thinking(Position *pos, StateListPtr &states,
|
||||
void ThreadPool::start_thinking(Position &pos, StateListPtr &states,
|
||||
const Search::LimitsType &limits, bool ponderMode)
|
||||
{
|
||||
|
||||
|
@ -180,7 +180,7 @@ void ThreadPool::start_thinking(Position *pos, StateListPtr &states,
|
|||
Search::Limits = limits;
|
||||
Search::RootMoves rootMoves;
|
||||
|
||||
for (const auto &m : MoveList(pos))
|
||||
for (auto &m : MoveList(pos))
|
||||
if (limits.searchmoves.empty()
|
||||
|| std::count(limits.searchmoves.begin(), limits.searchmoves.end(), m))
|
||||
rootMoves.emplace_back(m);
|
||||
|
@ -208,7 +208,7 @@ void ThreadPool::start_thinking(Position *pos, StateListPtr &states,
|
|||
th->nodes = th->tbHits = th->nmpMinPly = 0;
|
||||
th->rootDepth = th->completedDepth = 0;
|
||||
th->rootMoves = rootMoves;
|
||||
th->rootPos.set(pos->fen(), &setupStates->back(), th);
|
||||
th->rootPos.set(pos.fen(), &setupStates->back(), th);
|
||||
}
|
||||
|
||||
setupStates->back() = tmp;
|
||||
|
|
|
@ -96,7 +96,7 @@ struct MainThread : public Thread
|
|||
struct ThreadPool : public std::vector<Thread *>
|
||||
{
|
||||
|
||||
void start_thinking(Position *, StateListPtr &, const Search::LimitsType &, bool = false);
|
||||
void start_thinking(Position &, StateListPtr &, const Search::LimitsType &, bool = false);
|
||||
void clear();
|
||||
void set(size_t);
|
||||
|
||||
|
|
Loading…
Reference in New Issue