position: refactor: 部分函数改为 inline

This commit is contained in:
Calcitem 2020-09-01 00:40:32 +08:00
parent 67cee4cd84
commit a87504b134
2 changed files with 76 additions and 58 deletions

View File

@ -660,20 +660,6 @@ out:
return true;
}
bool Position::put_piece(File file, Rank rank)
{
Square s = Position::polar_to_square(file, rank);
return put_piece(s, true);
}
bool Position::remove_piece(File file, Rank rank)
{
Square s = Position::polar_to_square(file, rank);
return remove_piece(s, 1);
}
bool Position::remove_piece(Square s, bool updateCmdlist)
{
if (phase & PHASE_NOTPLAYING)
@ -802,20 +788,6 @@ bool Position::select_piece(Square s)
return false;
}
bool Position::select_piece(File file, Rank rank)
{
return select_piece(Position::polar_to_square(file, rank));
}
bool Position::move_piece(Square from, Square to)
{
if (select_piece(from)) {
return put_piece(to);
}
return false;
}
bool Position::giveup(Color loser)
{
if (phase & PHASE_NOTPLAYING ||
@ -1256,18 +1228,7 @@ time_t Position::get_elapsed_time(int us)
return elapsedSeconds[us];
}
void Position::construct_key()
{
st.key = 0;
}
Key Position::key()
{
// TODO: Move to suitable function
return update_key_misc();
}
Key Position::update_key(Square s)
inline Key Position::update_key(Square s)
{
// PieceType is board[s]
@ -1282,7 +1243,7 @@ Key Position::update_key(Square s)
return st.key;
}
Key Position::revert_key(Square s)
inline Key Position::revert_key(Square s)
{
return update_key(s);
}

View File

@ -255,11 +255,7 @@ public:
Move move { MOVE_NONE };
};
inline bool Position::empty(Square s) const
{
return piece_on(s) == NO_PIECE;
}
extern std::ostream &operator<<(std::ostream &os, const Position &pos);
inline Color Position::side_to_move() const
{
@ -272,6 +268,78 @@ inline Piece Position::piece_on(Square s) const
return board[s];
}
inline bool Position::empty(Square s) const
{
return piece_on(s) == NO_PIECE;
}
template<PieceType Pt> inline int Position::count(Color c) const
{
if (Pt == ON_BOARD) {
return pieceCountOnBoard[c];
} else if (Pt == IN_HAND) {
return pieceCountInHand[c];
}
return 0;
}
inline Key Position::key()
{
// TODO: Move to suitable function
return update_key_misc();
}
inline void Position::construct_key()
{
st.key = 0;
}
inline int Position::game_ply() const
{
return gamePly;
}
inline int Position::rule50_count() const
{
return st.rule50;
}
inline Thread *Position::this_thread() const
{
return thisThread;
}
inline bool Position::select_piece(File file, Rank rank)
{
return select_piece(Position::polar_to_square(file, rank));
}
inline bool Position::put_piece(File file, Rank rank)
{
Square s = Position::polar_to_square(file, rank);
return put_piece(s, true);
}
inline bool Position::remove_piece(File file, Rank rank)
{
Square s = Position::polar_to_square(file, rank);
return remove_piece(s, 1);
}
inline bool Position::move_piece(Square from, Square to)
{
if (select_piece(from)) {
return put_piece(to);
}
return false;
}
/// Mill Game
inline char Position::color_to_char(Color color)
{
return static_cast<char>('0' + color);
@ -286,17 +354,6 @@ inline std::string Position::char_to_string(char ch)
}
}
template<PieceType Pt> inline int Position::count(Color c) const
{
if (Pt == ON_BOARD) {
return pieceCountOnBoard[c];
} else if (Pt == IN_HAND) {
return pieceCountInHand[c];
}
return 0;
}
inline Piece *Position::get_board() const
{
return (Piece *)board;