types: 新增 is_ok(Move m) 函数
顺带新增未完成的 Position::legal() 函数。
This commit is contained in:
parent
b0e01f64b4
commit
806b97d334
|
@ -349,6 +349,39 @@ const string Position::fen() const
|
|||
}
|
||||
|
||||
|
||||
/// Position::legal() tests whether a pseudo-legal move is legal
|
||||
|
||||
bool Position::legal(Move m) const
|
||||
{
|
||||
assert(is_ok(m));
|
||||
|
||||
Color us = sideToMove;
|
||||
Square from = from_sq(m);
|
||||
Square to = to_sq(m);
|
||||
|
||||
if (phase == PHASE_MOVING && type_of(move) != MOVETYPE_REMOVE) {
|
||||
if (color_of(moved_piece(m)) != us) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Add more
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/// Position::pseudo_legal() takes a random move and tests whether the move is
|
||||
/// pseudo legal. It is used to validate moves from TT that can be corrupted
|
||||
/// due to SMP concurrent access or hash position key aliasing.
|
||||
|
||||
bool Position::pseudo_legal(const Move m) const
|
||||
{
|
||||
// TODO
|
||||
return legal(m);
|
||||
}
|
||||
|
||||
|
||||
/// Position::do_move() makes a move, and saves all information necessary
|
||||
/// to a StateInfo object. The move is assumed to be legal. Pseudo-legal
|
||||
/// moves should be filtered out before this function is called.
|
||||
|
|
|
@ -84,6 +84,7 @@ public:
|
|||
// Properties of moves
|
||||
bool legal(Move m) const;
|
||||
bool pseudo_legal(const Move m) const;
|
||||
Piece moved_piece(Move m) const;
|
||||
|
||||
// Doing and undoing moves
|
||||
void do_move(Move m, StateInfo &newSt);
|
||||
|
@ -262,6 +263,11 @@ inline bool Position::empty(Square s) const
|
|||
return piece_on(s) == NO_PIECE;
|
||||
}
|
||||
|
||||
inline Piece Position::moved_piece(Move m) const
|
||||
{
|
||||
return piece_on(from_sq(m));
|
||||
}
|
||||
|
||||
template<PieceType Pt> inline int Position::count(Color c) const
|
||||
{
|
||||
if (Pt == ON_BOARD) {
|
||||
|
|
|
@ -523,11 +523,9 @@ inline const Move reverse_move(Move m)
|
|||
return make_move(to_sq(m), from_sq(m));
|
||||
}
|
||||
|
||||
#if 0
|
||||
constexpr bool is_ok(Move m)
|
||||
static inline bool is_ok(Move m)
|
||||
{
|
||||
return from_sq(m) != to_sq(m); // Catch MOVE_NULL and MOVE_NONE
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // #ifndef TYPES_H_INCLUDED
|
||||
|
|
Loading…
Reference in New Issue