effect_action.h
Go to the documentation of this file.
#ifndef OSL_EFFECT_ACTION
#define OSL_EFFECT_ACTION
#include "osl/numEffectState.h"
namespace osl
{
namespace effect_action
{
template<class Action>
class AlwaysMove
{
private:
const NumEffectState& state;
Action& ac;
public:
AlwaysMove(const NumEffectState& s, Action & a) : state(s), ac(a) {}
template<Player P,Ptype Type>
void doActionPtype(Piece p1,Square to){
assert(Type == unpromote(p1.ptype()));
Square from=p1.square();
if (canPromote(Type) &&
!p1.isPromotedNotKingGold() &&
(to.canPromote<P>() || from.canPromote<P>())){
ac.unknownMove(from,to,state.pieceAt(to),promote(Type),true,P);
}
if (!canPromote(Type) ||
PtypePlayerTraits<Type,P>::canDropTo(to) ||
p1.isPromotedNotKingGold()){
ac.unknownMove(from,to,state.pieceAt(to),p1.ptype(),false,P);
}
}
template<Player P>
void doAction(Piece p1,Square to)
{
Square from=p1.square();
Ptype ptype=p1.ptype();
if(canPromote(ptype))
{
if (to.canPromote<P>())
{
ac.unknownMove(from,to,state.pieceAt(to),promote(ptype),true,P);
if(Ptype_Table.canDropTo(P, ptype,to))
{
ac.unknownMove(from,to,state.pieceAt(to),ptype,false,P);
}
}
else if (from.canPromote<P>())
{
ac.unknownMove(from,to,state.pieceAt(to),promote(ptype),true,P);
ac.unknownMove(from,to,state.pieceAt(to),ptype,false,P);
}
else
{
ac.unknownMove(from,to,state.pieceAt(to),ptype,false,P);
}
}
else
{
ac.unknownMove(from,to,state.pieceAt(to),ptype,false,P);
}
}
bool done() const{ return false; }
};
template<class Action>
class BetterToPromote
{
private:
const NumEffectState& state;
Action & ac;
public:
BetterToPromote(const NumEffectState& s, Action& a)
: state(s), ac(a)
{
}
template<Player P,Ptype Type>
void doActionPtype(Piece p1,Square to){
assert(Type == unpromote(p1.ptype()));
Square from=p1.square();
Piece target = state.pieceAt(to);
if (canPromote(Type) &&
!p1.isPromotedNotKingGold() &&
(to.canPromote<P>() || from.canPromote<P>())){
ac.unknownMove(from,to,target,promote(Type),true,P);
}
if (!canPromote(Type) ||
PtypePlayerTraits<Type,P>::canDropTo(to) ||
p1.isPromotedNotKingGold()){
if (! (to.canPromote<P>() || from.canPromote<P>())
|| (! PtypeTraits<Type>::betterToPromote
&& (p1.ptype() != LANCE
|| PtypePlayerTraits<LANCE,P>::canDropTo(to + DirectionPlayerTraits<U,P>::offset()))))
ac.unknownMove(from,to,target,p1.ptype(),false,P);
}
}
template<Player P>
void doAction(Piece p1,Square to)
{
Square from=p1.square();
Ptype ptype=p1.ptype();
Piece target = state.pieceAt(to);
if(canPromote(ptype))
{
if (to.canPromote<P>())
{
ac.unknownMove(from,to,target,promote(ptype),true,P);
if(Ptype_Table.canDropTo(P, ptype,to)
&& ! Ptype_Table.isBetterToPromote(ptype)
&& (ptype != LANCE
|| PtypePlayerTraits<LANCE,P>::canDropTo(to + DirectionPlayerTraits<U,P>::offset())))
{
ac.unknownMove(from,to,target,ptype,false,P);
}
return;
}
if (from.canPromote<P>())
{
ac.unknownMove(from,to,target,promote(ptype),true,P);
if(! Ptype_Table.isBetterToPromote(ptype)
&& (ptype != LANCE
|| PtypePlayerTraits<LANCE,P>::canDropTo(to + DirectionPlayerTraits<U,P>::offset())))
ac.unknownMove(from,to,target,ptype,false,P);
return;
}
// fall through
}
ac.unknownMove(from,to,target,ptype,false,P);
}
};
struct StorePiece
{
PieceVector *store;
explicit StorePiece(PieceVector *s) : store(s)
{
}
template<Player P,Ptype Type>
void doActionPtype(Piece p, Square pos)
{
doAction<P>(p, pos);
}
template<Player P>
void doAction(Piece p, Square)
{
store->push_back(p);
}
};
struct StorePtypeOSquare
{
PtypeOSquareVector *out;
Square target;
StorePtypeOSquare(PtypeOSquareVector *s, Square t)
: out(s), target(t)
{
}
template<Player P,Ptype Type>
void doActionPtype(Piece p)
{
store(p);
}
template<Player P>
void doAction(Piece p, Square)
{
store(p);
}
void store(Piece p)
{
const PtypeO ptypeO = p.ptypeO();
out->push_back(std::make_pair(ptypeO, p.square()));
}
};
} // namespace effect_action
} // namespace osl
#endif // OSL_EFFECT_ACTION
// ;;; Local Variables:
// ;;; mode:c++
// ;;; c-basic-offset:2
// ;;; End:
osl::NumEffectState
利きを持つ局面
Definition numEffectState.h:34
osl::PieceVector
Definition container.h:305
osl::Piece
駒.
Definition basic_type.h:788
osl::Piece::ptypeO
PtypeO ptypeO() const
Definition basic_type.h:824
osl::Piece::ptype
Ptype ptype() const
Definition basic_type.h:821
osl::Piece::square
const Square square() const
Definition basic_type.h:832
osl::Piece::isPromotedNotKingGold
bool isPromotedNotKingGold() const
Definition basic_type.h:908
osl::PtypeOSquareVector
Definition container.h:322
osl::Square
Definition basic_type.h:532
osl::Square::canPromote
bool canPromote() const
Definition basic_type.h:659
osl::effect_action::AlwaysMove::AlwaysMove
AlwaysMove(const NumEffectState &s, Action &a)
Definition effect_action.h:19
osl::effect_action::AlwaysMove::state
const NumEffectState & state
Definition effect_action.h:16
osl::effect_action::AlwaysMove::doAction
void doAction(Piece p1, Square to)
Ptypeをtemplate引数にできない場合
Definition effect_action.h:42
osl::effect_action::AlwaysMove::ac
Action & ac
Definition effect_action.h:17
osl::effect_action::AlwaysMove::done
bool done() const
Definition effect_action.h:71
osl::effect_action::AlwaysMove::doActionPtype
void doActionPtype(Piece p1, Square to)
Ptypeをtemplate引数にできる場合
Definition effect_action.h:24
osl::effect_action::BetterToPromote::doAction
void doAction(Piece p1, Square to)
Ptypeをtemplate引数にできない場合
Definition effect_action.h:112
osl::effect_action::BetterToPromote::doActionPtype
void doActionPtype(Piece p1, Square to)
Definition effect_action.h:89
osl::effect_action::BetterToPromote::BetterToPromote
BetterToPromote(const NumEffectState &s, Action &a)
Definition effect_action.h:84
osl::effect_action::BetterToPromote::state
const NumEffectState & state
Definition effect_action.h:81
osl::effect_action::BetterToPromote::ac
Action & ac
Definition effect_action.h:82
osl::effect_action
Definition effect_action.h:8
osl
Definition additionalEffect.h:6
osl::Ptype
Ptype
駒の種類を4ビットでコード化する
Definition basic_type.h:84
osl::LANCE
@ LANCE
Definition basic_type.h:96
osl::Ptype_Table
const PtypeTable Ptype_Table
Definition tables.cc:97
osl::canPromote
bool canPromote(Ptype ptype)
ptypeがpromote可能な型かどうかのチェック promote済みの場合はfalseを返す
Definition basic_type.h:147
osl::unpromote
Ptype unpromote(Ptype ptype)
ptypeがpromote後の型の時に，promote前の型を返す． promoteしていない型の時はそのまま返す
Definition basic_type.h:157
osl::PtypeO
PtypeO
Player + Ptype [-15, 15] PtypeO の O は Owner の O.
Definition basic_type.h:199
osl::promote
Ptype promote(Ptype ptype)
promote可能なptypeに対して，promote後の型を返す promote不可のptypeを与えてはいけない．
Definition basic_type.h:173
numEffectState.h
osl::DirectionPlayerTraits
Definition directionTraits.h:242
osl::PtypePlayerTraits::canDropTo
static bool canDropTo(Square pos)
Definition ptypeTraits.h:364
osl::PtypeTraits
Definition ptypeTraits.h:12
osl::effect_action::StorePiece::doActionPtype
void doActionPtype(Piece p, Square pos)
Definition effect_action.h:157
osl::effect_action::StorePiece::store
PieceVector * store
Definition effect_action.h:152
osl::effect_action::StorePiece::doAction
void doAction(Piece p, Square)
Definition effect_action.h:162
osl::effect_action::StorePiece::StorePiece
StorePiece(PieceVector *s)
Definition effect_action.h:153
osl::effect_action::StorePtypeOSquare::target
Square target
Definition effect_action.h:174
osl::effect_action::StorePtypeOSquare::out
PtypeOSquareVector * out
Definition effect_action.h:173
osl::effect_action::StorePtypeOSquare::store
void store(Piece p)
Definition effect_action.h:190
osl::effect_action::StorePtypeOSquare::doActionPtype
void doActionPtype(Piece p)
Definition effect_action.h:180
osl::effect_action::StorePtypeOSquare::StorePtypeOSquare
StorePtypeOSquare(PtypeOSquareVector *s, Square t)
Definition effect_action.h:175
osl::effect_action::StorePtypeOSquare::doAction
void doAction(Piece p, Square)
Definition effect_action.h:185