move_action.h
Go to the documentation of this file.
/* move_action.h
*/
#ifndef OSL_MOVEACTION_H
#define OSL_MOVEACTION_H
#include "osl/numEffectState.h"
#include "osl/move_classifier/kingOpenMove.h"
namespace osl
{
namespace move_action
{
struct Store
{
FixedCapacityVectorPushBack<Move> moves;
template <size_t Capacity>
explicit Store(FixedCapacityVector<Move, Capacity>& v)
: moves(v.pushBackHelper())
{
}
void simpleMove(Square /*from*/,Square /*to*/,Ptype /*ptype*/, bool /*isPromote*/,Player /*p*/,Move move){
assert(move.isValid());
moves.push_back(move);
}
void unknownMove(Square /*from*/,Square /*to*/,Piece /*p1*/,Ptype /*ptype*/,bool /*isPromote*/,Player /*p*/,Move move)
{
assert(move.isValid());
moves.push_back(move);
}
void dropMove(Square /*to*/,Ptype /*ptype*/,Player /*p*/,Move move)
{
assert(move.isValid());
moves.push_back(move);
}
// old interfaces
void simpleMove(Square from,Square to,Ptype ptype,
bool isPromote,Player p)
{
simpleMove(from,to,ptype,isPromote,p,
Move(from,to,ptype,PTYPE_EMPTY,isPromote,p));
}
void unknownMove(Square from,Square to,Piece captured,
Ptype ptype,bool isPromote,Player p)
{
unknownMove(from,to,captured,ptype,isPromote,p,
Move(from,to,ptype,captured.ptype(),isPromote,p));
}
void dropMove(Square to,Ptype ptype,Player p)
{
dropMove(to,ptype,p,
Move(to,ptype,p));
}
};
template<Player P,class OrigAction>
class NoEffectFilter
{
const NumEffectState& state;
OrigAction & action;
Square removed;
public:
NoEffectFilter(const NumEffectState& s, OrigAction & action,Square pos) : state(s), action(action),removed(pos) {}
void simpleMove(Square from,Square to,Ptype ptype, bool isPromote,Player /* p */,Move m){
if(!state.template hasEffectByWithRemove<alt(P)>(to,removed))
action.simpleMove(from,to,ptype,isPromote,P,m);
}
void unknownMove(Square from,Square to,Piece p1,Ptype ptype,bool isPromote,Player /* p */,Move m){
if(!state.template hasEffectByWithRemove<alt(P)>(to,removed)){
action.unknownMove(from,to,p1,ptype,isPromote,P,m);
}
}
void dropMove(Square to,Ptype ptype,Player /* p */,Move m){
if(!state.template hasEffectByWithRemove<alt(P)>(to,removed))
action.dropMove(to,ptype,P,m);
}
// old interfaces
void simpleMove(Square from,Square to,Ptype ptype,
bool isPromote,Player p)
{
simpleMove(from,to,ptype,isPromote,p,
Move(from,to,ptype,PTYPE_EMPTY,isPromote,p));
}
void unknownMove(Square from,Square to,Piece captured,
Ptype ptype,bool isPromote,Player p)
{
unknownMove(from,to,captured,ptype,isPromote,p,
Move(from,to,ptype,captured.ptype(),isPromote,p));
}
void dropMove(Square to,Ptype ptype,Player p)
{
dropMove(to,ptype,p,
Move(to,ptype,p));
}
};
template<class OrigAction>
class NoAddEffectFilter
{
const NumEffectState& state;
OrigAction & action;
Square target;
public:
NoAddEffectFilter(const NumEffectState& s, OrigAction & action,Square target) : state(s), action(action),target(target) {}
void simpleMove(Square from,Square to,Ptype ptype, bool isPromote,Player p,Move m){
if(!state.hasEffectIf(newPtypeO(p,ptype),to,target))
action.simpleMove(from,to,ptype,isPromote,p,m);
}
void unknownMove(Square from,Square to,Piece p1,Ptype ptype,bool isPromote,Player p,Move m){
if(!state.hasEffectIf(newPtypeO(p,ptype),to,target))
action.unknownMove(from,to,p1,ptype,isPromote,p,m);
}
void dropMove(Square to,Ptype ptype,Player p,Move m){
if(!state.hasEffectIf(newPtypeO(p,ptype),to,target))
action.dropMove(to,ptype,p,m);
}
// old interfaces
void simpleMove(Square from,Square to,Ptype ptype,
bool isPromote,Player p)
{
simpleMove(from,to,ptype,isPromote,p,
Move(from,to,ptype,PTYPE_EMPTY,isPromote,p));
}
void unknownMove(Square from,Square to,Piece captured,
Ptype ptype,bool isPromote,Player p)
{
unknownMove(from,to,captured,ptype,isPromote,p,
Move(from,to,ptype,captured.ptype(),isPromote,p));
}
void dropMove(Square to,Ptype ptype,Player p)
{
dropMove(to,ptype,p,
Move(to,ptype,p));
}
};
template<Player P,class OrigAction>
struct NotKingOpenFilter
{
const NumEffectState& state;
OrigAction & action;
public:
NotKingOpenFilter(const NumEffectState& s, OrigAction & action)
: state(s), action(action) {
}
bool isNotKingOpenMove(Ptype ptype,Square from,Square to)
{
return !move_classifier::KingOpenMove<P>::isMember(state, ptype, from, to);
}
void simpleMove(Square from,Square to,Ptype ptype, bool isPromote,Player
#ifndef NDEBUG
p
#endif
,Move m
){
assert(p == P);
if(isNotKingOpenMove(ptype,from,to))
action.simpleMove(from,to,ptype,isPromote,P,m);
}
void unknownMove(Square from,Square to,Piece p1,Ptype ptype,bool isPromote,Player
#ifndef NDEBUG
p
#endif
,Move m
){
assert(p == P);
if(isNotKingOpenMove(ptype,from,to))
action.unknownMove(from,to,p1,ptype,isPromote,P,m);
}
void dropMove(Square to,Ptype ptype,Player
#ifndef NDEBUG
p
#endif
,Move m
){
assert(p == P);
action.dropMove(to,ptype,P,m);
}
// old interfaces
void simpleMove(Square from,Square to,Ptype ptype,
bool isPromote,Player p)
{
simpleMove(from,to,ptype,isPromote,p,
Move(from,to,ptype,PTYPE_EMPTY,isPromote,p));
}
void unknownMove(Square from,Square to,Piece captured,
Ptype ptype,bool isPromote,Player p)
{
unknownMove(from,to,captured,ptype,isPromote,p,
Move(from,to,ptype,captured.ptype(),isPromote,p));
}
void dropMove(Square to,Ptype ptype,Player p)
{
dropMove(to,ptype,p,
Move(to,ptype,p));
}
};
} // namespace move_action
} // namespace osl
#endif /* OSL_MOVEACTION_STORE */
// ;;; Local Variables:
// ;;; mode:c++
// ;;; c-basic-offset:2
// ;;; End:
osl::FixedCapacityVector
Definition container.h:137
osl::Move
圧縮していない moveの表現 .
Definition basic_type.h:1052
osl::Move::isValid
bool isValid() const
Definition basic_type.cc:246
osl::NumEffectState
利きを持つ局面
Definition numEffectState.h:34
osl::Piece
駒.
Definition basic_type.h:788
osl::Square
Definition basic_type.h:532
osl::detail::FixedCapacityVectorPushBack
Definition container.h:104
osl::move_action::NoAddEffectFilter::NoAddEffectFilter
NoAddEffectFilter(const NumEffectState &s, OrigAction &action, Square target)
Definition move_action.h:123
osl::move_action::NoAddEffectFilter::target
Square target
Definition move_action.h:121
osl::move_action::NoAddEffectFilter::simpleMove
void simpleMove(Square from, Square to, Ptype ptype, bool isPromote, Player p, Move m)
Definition move_action.h:124
osl::move_action::NoAddEffectFilter::unknownMove
void unknownMove(Square from, Square to, Piece captured, Ptype ptype, bool isPromote, Player p)
Definition move_action.h:143
osl::move_action::NoAddEffectFilter::dropMove
void dropMove(Square to, Ptype ptype, Player p)
Definition move_action.h:149
osl::move_action::NoAddEffectFilter::unknownMove
void unknownMove(Square from, Square to, Piece p1, Ptype ptype, bool isPromote, Player p, Move m)
Definition move_action.h:128
osl::move_action::NoAddEffectFilter::action
OrigAction & action
Definition move_action.h:120
osl::move_action::NoAddEffectFilter::simpleMove
void simpleMove(Square from, Square to, Ptype ptype, bool isPromote, Player p)
Definition move_action.h:137
osl::move_action::NoAddEffectFilter::dropMove
void dropMove(Square to, Ptype ptype, Player p, Move m)
Definition move_action.h:132
osl::move_action::NoAddEffectFilter::state
const NumEffectState & state
Definition move_action.h:119
osl::move_action::NoEffectFilter::NoEffectFilter
NoEffectFilter(const NumEffectState &s, OrigAction &action, Square pos)
Definition move_action.h:78
osl::move_action::NoEffectFilter::dropMove
void dropMove(Square to, Ptype ptype, Player p)
Definition move_action.h:106
osl::move_action::NoEffectFilter::removed
Square removed
Definition move_action.h:76
osl::move_action::NoEffectFilter::action
OrigAction & action
Definition move_action.h:75
osl::move_action::NoEffectFilter::simpleMove
void simpleMove(Square from, Square to, Ptype ptype, bool isPromote, Player p)
Definition move_action.h:94
osl::move_action::NoEffectFilter::unknownMove
void unknownMove(Square from, Square to, Piece captured, Ptype ptype, bool isPromote, Player p)
Definition move_action.h:100
osl::move_action::NoEffectFilter::unknownMove
void unknownMove(Square from, Square to, Piece p1, Ptype ptype, bool isPromote, Player, Move m)
Definition move_action.h:83
osl::move_action::NoEffectFilter::dropMove
void dropMove(Square to, Ptype ptype, Player, Move m)
Definition move_action.h:88
osl::move_action::NoEffectFilter::state
const NumEffectState & state
Definition move_action.h:74
osl::move_action::NoEffectFilter::simpleMove
void simpleMove(Square from, Square to, Ptype ptype, bool isPromote, Player, Move m)
Definition move_action.h:79
kingOpenMove.h
osl::move_action
Definition move_action.h:11
osl
Definition additionalEffect.h:6
osl::Ptype
Ptype
駒の種類を4ビットでコード化する
Definition basic_type.h:84
osl::PTYPE_EMPTY
@ PTYPE_EMPTY
Definition basic_type.h:85
osl::Player
Player
Definition basic_type.h:8
osl::alt
constexpr Player alt(Player player)
Definition basic_type.h:13
osl::newPtypeO
PtypeO newPtypeO(Player player, Ptype ptype)
Definition basic_type.h:211
osl::captured
PtypeO captured(PtypeO ptypeO)
unpromoteすると共に，ownerを反転する．
Definition basic_type.h:264
numEffectState.h
osl::move_action::NotKingOpenFilter::simpleMove
void simpleMove(Square from, Square to, Ptype ptype, bool isPromote, Player p)
Definition move_action.h:206
osl::move_action::NotKingOpenFilter::NotKingOpenFilter
NotKingOpenFilter(const NumEffectState &s, OrigAction &action)
Definition move_action.h:165
osl::move_action::NotKingOpenFilter::isNotKingOpenMove
bool isNotKingOpenMove(Ptype ptype, Square from, Square to)
Definition move_action.h:168
osl::move_action::NotKingOpenFilter::dropMove
void dropMove(Square to, Ptype ptype, Player p)
Definition move_action.h:218
osl::move_action::NotKingOpenFilter::unknownMove
void unknownMove(Square from, Square to, Piece captured, Ptype ptype, bool isPromote, Player p)
Definition move_action.h:212
osl::move_action::NotKingOpenFilter::simpleMove
void simpleMove(Square from, Square to, Ptype ptype, bool isPromote, Player p, Move m)
Definition move_action.h:172
osl::move_action::NotKingOpenFilter::dropMove
void dropMove(Square to, Ptype ptype, Player p, Move m)
dropMoveが自殺手になることはない
Definition move_action.h:196
osl::move_action::NotKingOpenFilter::state
const NumEffectState & state
Definition move_action.h:162
osl::move_action::NotKingOpenFilter::action
OrigAction & action
Definition move_action.h:163
osl::move_action::NotKingOpenFilter::unknownMove
void unknownMove(Square from, Square to, Piece p1, Ptype ptype, bool isPromote, Player p, Move m)
Definition move_action.h:183
osl::move_action::Store::dropMove
void dropMove(Square, Ptype, Player, Move move)
コマを打つMove
Definition move_action.h:43
osl::move_action::Store::moves
FixedCapacityVectorPushBack< Move > moves
Definition move_action.h:17
osl::move_action::Store::Store
Store(FixedCapacityVector< Move, Capacity > &v)
Definition move_action.h:19
osl::move_action::Store::dropMove
void dropMove(Square to, Ptype ptype, Player p)
Definition move_action.h:61
osl::move_action::Store::unknownMove
void unknownMove(Square from, Square to, Piece captured, Ptype ptype, bool isPromote, Player p)
Definition move_action.h:55
osl::move_action::Store::unknownMove
void unknownMove(Square, Square, Piece, Ptype, bool, Player, Move move)
Definition move_action.h:37
osl::move_action::Store::simpleMove
void simpleMove(Square from, Square to, Ptype ptype, bool isPromote, Player p)
Definition move_action.h:49
osl::move_action::Store::simpleMove
void simpleMove(Square, Square, Ptype, bool, Player, Move move)
コマをとらないMove
Definition move_action.h:24
osl::move_classifier::KingOpenMove::isMember
static bool isMember(const NumEffectState &state, Ptype, Square from, Square to)
king が59 rookが51->61の時，差は OFFSET -8 -> U OFFSET +8 -> D とはなるので，一直線のような気がする．ただし，そもとも， 59 - 51はpinにはならな...
Definition kingOpenMove.h:31