pieceOnBoard.h
Go to the documentation of this file.
#ifndef OSL_PIECE_ON_BOARD_H
#define OSL_PIECE_ON_BOARD_H
#include "osl/numEffectState.h"
namespace osl
{
namespace move_generator
{
enum PromoteType{
NoPromoteType=0,
CanPromoteType=1,
CheckPromoteType=2,
MustPromoteType=3,
};
template<class Action,bool noCapturePromote=false>
struct PieceOnBoard
{
template<Player P>
static void generatePieceUnsafe(const NumEffectState& state,Piece p, Square target, Piece p1,Action& action)
{
assert(state.hasEffectByPiece(p, target));
Ptype ptype=p.ptype();
Square from=p.square();
if(canPromote(ptype)){
if(target.canPromote<P>()){
action.unknownMove(from,target,p1,promote(ptype),true,P);
int y=(P==BLACK ? target.y() : 10-target.y());
if(!Ptype_Table.isBetterToPromote(ptype) &&
(((ptype==LANCE || ptype==PAWN) ? y==3 : true )) &&
Ptype_Table.canDropTo(P,ptype,target))
action.unknownMove(from,target,p1,ptype,false,P);
}
else if(from.canPromote<P>()){
action.unknownMove(from,target,p1,promote(ptype),true,P);
if(!Ptype_Table.isBetterToPromote(ptype))
action.unknownMove(from,target,p1,ptype,false,P);
}
else
action.unknownMove(from,target,p1,ptype,false,P);
}
else{
action.unknownMove(from,target,p1,ptype,false,P);
}
}
template<Player P>
static void generatePiece(const NumEffectState& state,Piece p, Square target, Piece p1,Action& action)
{
if(p.ptype()==KING){
// 王手がかかっているときには自分の影になっている手も生成してしまう
const Player altP=alt(P);
// assert(!state.hasEffectAt<altP>(p.square()));
// 自殺手
if(state.hasEffectAt<altP>(target)) return;
}
if(state.pinOrOpen(P).test(p.number())){
Direction d=state.pinnedDir<P>(p);
Direction d1=Board_Table.getShort8Unsafe<P>(p.square(),target);
if(primDir(d)!=primDirUnsafe(d1)) return;
}
generatePieceUnsafe<P>(state,p,target,p1,action);
}
template<Player P,Ptype T>
static void generatePiecePtypeUnsafe(const NumEffectState& state,Piece p, Square target, Piece p1,Action& action)
{
assert(state.hasEffectByPiece(p, target));
assert(p.ptype()==T);
// Ptype ptype=p.ptype();
Square from=p.square();
if(canPromote(T) & (target.canPromote<P>() || from.canPromote<P>())){
action.unknownMove(from,target,p1,promote(T),true,P);
if(((T==PAWN || T==LANCE) &&
(P==BLACK ? target.y()==1 : target.y()==9))||
(T==KNIGHT && (P==BLACK ? target.y()<=2 : target.y()>=8)))
return;
if((T==ROOK || T==BISHOP || T==PAWN ||
(T==LANCE && (P==BLACK ? target.y()==2 : target.y()==8))))
return;
}
action.unknownMove(from,target,p1,T,false,P);
}
template<Player P,Ptype T>
static void generatePiecePtype(const NumEffectState& state,Piece p, Square target, Piece p1,Action& action)
{
if(T==KING){
assert(!state.hasEffectAt(alt(P),p.square()));
if(state.hasEffectAt(alt(P),target)) return;
}
else if(state.pin(P).test(p.number())){
Direction d=state.pinnedDir<P>(p);
Direction d1=Board_Table.getShort8Unsafe<P>(p.square(),target);
if(primDir(d)!=primDirUnsafe(d1)) return;
}
generatePiecePtypeUnsafe<P,T>(state,p,target,p1,action);
}
template <Player P,Ptype T,bool useDirMask>
static void generatePtype(const NumEffectState& state,Piece p, Action& action,int dirMask=0);
template <Player P,Ptype T>
static void generatePtype(const NumEffectState& state,Piece p, Action& action)
{
int dummy=0;
generatePtype<P,T,false>(state,p,action,dummy);
}
template <Player P,Ptype T,bool useDirMask>
static void generatePtypeUnsafe(const NumEffectState& state,Piece p, Action& action,int dirMask);
template <Player P,Ptype T>
static void generatePtypeUnsafe(const NumEffectState& state,Piece p, Action& action)
{
int dummy=0;
generatePtypeUnsafe<P,T,false>(state,p,action,dummy);
}
template <Player P,bool useDirMask>
static void generate(const NumEffectState& state,Piece p, Action& action,int dirMask=0);
};
struct GeneratePieceOnBoard
{
static void generate(Player turn, const NumEffectState& state, Piece target,
MoveVector&);
};
} // namespace move_generator
using move_generator::GeneratePieceOnBoard;
} // namespace osl
#endif /* OSL_PIECE_ON_BOARD_H */
// ;;; Local Variables:
// ;;; mode:c++
// ;;; c-basic-offset:2
// ;;; End:
osl::MoveVector
Definition container.h:293
osl::NumEffectState
利きを持つ局面
Definition numEffectState.h:34
osl::NumEffectState::pinnedDir
Direction pinnedDir(Piece p) const
pinされた駒がPのKingから見てどの方向か?
Definition numEffectState.h:203
osl::NumEffectState::hasEffectByPiece
bool hasEffectByPiece(Piece attack, Square target) const
駒attack が target に利きを持つか (旧hasEffectToと統合)
Definition numEffectState.h:450
osl::NumEffectState::hasEffectAt
bool hasEffectAt(Square target) const
対象とするマスにあるプレイヤーの利きがあるかどうか.
Definition numEffectState.h:324
osl::NumEffectState::pin
const PieceMask pin(Player king) const
Definition numEffectState.h:65
osl::NumEffectState::pinOrOpen
PieceMask pinOrOpen(Player king) const
Definition numEffectState.h:74
osl::PieceMask::test
bool test(int num) const
Definition pieceMask.h:45
osl::Piece
駒.
Definition basic_type.h:788
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::number
int number() const
Definition basic_type.h:828
osl::Square
Definition basic_type.h:532
osl::Square::y
int y() const
将棋としてのY座標を返す.
Definition basic_type.h:567
osl::Square::canPromote
bool canPromote() const
Definition basic_type.h:659
osl::move_generator
Definition addEffectWithEffect.cc:10
osl::move_generator::PromoteType
PromoteType
Definition pieceOnBoard.h:9
osl::move_generator::CanPromoteType
@ CanPromoteType
Definition pieceOnBoard.h:11
osl::move_generator::MustPromoteType
@ MustPromoteType
Definition pieceOnBoard.h:13
osl::move_generator::CheckPromoteType
@ CheckPromoteType
Definition pieceOnBoard.h:12
osl::move_generator::NoPromoteType
@ NoPromoteType
Definition pieceOnBoard.h:10
osl
Definition additionalEffect.h:6
osl::Ptype
Ptype
駒の種類を4ビットでコード化する
Definition basic_type.h:84
osl::ROOK
@ ROOK
Definition basic_type.h:100
osl::BISHOP
@ BISHOP
Definition basic_type.h:99
osl::PAWN
@ PAWN
Definition basic_type.h:95
osl::KING
@ KING
Definition basic_type.h:93
osl::KNIGHT
@ KNIGHT
Definition basic_type.h:97
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::Board_Table
const BoardTable Board_Table
Definition tables.cc:95
osl::primDirUnsafe
constexpr Direction primDirUnsafe(Direction d)
8方向について，primitiveな4方向を求める dとしてknight, INVALIDなども来る
Definition basic_type.h:374
osl::Direction
Direction
Definition basic_type.h:310
osl::Player
Player
Definition basic_type.h:8
osl::BLACK
@ BLACK
Definition basic_type.h:9
osl::primDir
constexpr Direction primDir(Direction d)
8方向について，primitiveな4方向を求める
Definition basic_type.h:366
osl::alt
constexpr Player alt(Player player)
Definition basic_type.h:13
osl::promote
Ptype promote(Ptype ptype)
promote可能なptypeに対して，promote後の型を返す promote不可のptypeを与えてはいけない．
Definition basic_type.h:173
numEffectState.h
osl::move_generator::GeneratePieceOnBoard
Definition pieceOnBoard.h:151
osl::move_generator::GeneratePieceOnBoard::generate
static void generate(Player turn, const NumEffectState &state, Piece target, MoveVector &)
Definition pieceOnBoard.cc:20
osl::move_generator::PieceOnBoard
特定のpieceを動かす手を生成
Definition pieceOnBoard.h:20
osl::move_generator::PieceOnBoard::generatePtype
static void generatePtype(const NumEffectState &state, Piece p, Action &action, int dirMask=0)
Generate moves without stating the Ptype as template param.
osl::move_generator::PieceOnBoard::generatePiece
static void generatePiece(const NumEffectState &state, Piece p, Square target, Piece p1, Action &action)
Definition pieceOnBoard.h:52
osl::move_generator::PieceOnBoard::generate
static void generate(const NumEffectState &state, Piece p, Action &action, int dirMask=0)
Generate moves without stating the Ptype as template param.
osl::move_generator::PieceOnBoard::generatePtypeUnsafe
static void generatePtypeUnsafe(const NumEffectState &state, Piece p, Action &action, int dirMask)
Generate moves without stating the Ptype as template param.
osl::move_generator::PieceOnBoard::generatePtypeUnsafe
static void generatePtypeUnsafe(const NumEffectState &state, Piece p, Action &action)
Definition pieceOnBoard.h:133
osl::move_generator::PieceOnBoard::generatePtype
static void generatePtype(const NumEffectState &state, Piece p, Action &action)
Definition pieceOnBoard.h:117
osl::move_generator::PieceOnBoard::generatePiecePtype
static void generatePiecePtype(const NumEffectState &state, Piece p, Square target, Piece p1, Action &action)
Definition pieceOnBoard.h:92
osl::move_generator::PieceOnBoard::generatePieceUnsafe
static void generatePieceUnsafe(const NumEffectState &state, Piece p, Square target, Piece p1, Action &action)
駒pがマスtargetに利きをもっているとして，手を生成する．
Definition pieceOnBoard.h:25
osl::move_generator::PieceOnBoard::generatePiecePtypeUnsafe
static void generatePiecePtypeUnsafe(const NumEffectState &state, Piece p, Square target, Piece p1, Action &action)
PtypeがTの駒pがマスtargetに利きをもっているとして，手を生成する． p1 - targetにある駒
Definition pieceOnBoard.h:73