3#ifndef OSL_NUM_EFFECT_STATE_TCC
4#define OSL_NUM_EFFECT_STATE_TCC
6#include "osl/numEffectState.h"
7#include "osl/move_classifier/kingOpenMove.h"
8#include "osl/bits/numSimpleEffect.tcc"
10template <osl::Player P>
11bool osl::NumEffectState::
12hasEffectByWithRemove(Square target,Square removed) const
14 const Piece piece = pieceAt(removed);
15 if (! piece.isPiece())
16 return hasEffectAt<P>(target);
17 if (piece.owner() == P)
19 if (hasEffectNotBy(P, piece, target))
24 if (hasEffectAt(P, target))
27 if (! longEffectAt(removed, P).any())
29 const Direction d = Board_Table.getLongDirection<BLACK>(Offset32(target,removed));
32 const int num=longEffectNumTable()[piece.number()][longToShort(d)];
33 return (! Piece::isEmptyNum(num)
34 && pieceOf(num).owner()==P);
39 template <osl::Player P, bool InterestEmpty, Direction Dir>
40 struct TestEffectOfMove
42 template <class State, class Function>
43 static void testShort(const State& s, int mask, Square from,
45 static_assert(! DirectionTraits<Dir>::isLong, "Dir");
46 if (! (mask & DirectionTraits<Dir>::mask))
49 const Offset offset = DirectionPlayerTraits<Dir,P>::offset();
50 const Square target = from+offset;
51 const Piece piece = s.pieceAt(target);
54 if (InterestEmpty || (! piece.isEmpty()))
57 template <class State, class Function>
58 static void testLong(const State& s, int mask, Square from,
60 static_assert(DirectionTraits<Dir>::isLong, "Dir");
61 if (! (mask & DirectionTraits<Dir>::mask))
64 const Offset offset = DirectionPlayerTraits<Dir,P>::offset();
66 Square target = from+offset;
67 Piece piece = s.pieceAt(target);
68 while (piece.isEmpty()) {
71 target = target+offset;
72 piece = s.pieceAt(target);
74 if (piece.isPiece()) {
82 const NumEffectState& state;
84 SafeCapture(const NumEffectState& s) : state(s), safe_one(Piece::EMPTY()) {
87 void doAction(Piece effect_piece, Square target) {
88 if (move_classifier::KingOpenMove<P>::isMember
89 (state, effect_piece.ptype(), effect_piece.square(), target))
91 safe_one = effect_piece;
96template <osl::Player P, class Function, bool InterestEmpty>
97void osl::NumEffectState::
98forEachEffectOfPtypeO(Square from, Ptype ptype, Function& f) const
100 const int mask = Ptype_Table.getMoveMask(ptype);
101 TestEffectOfMove<P,InterestEmpty,UL>::testShort(*this, mask, from, f);
102 TestEffectOfMove<P,InterestEmpty,U>::testShort(*this, mask, from, f);
103 TestEffectOfMove<P,InterestEmpty,UR>::testShort(*this, mask, from, f);
104 TestEffectOfMove<P,InterestEmpty,L>::testShort(*this, mask, from, f);
105 TestEffectOfMove<P,InterestEmpty,R>::testShort(*this, mask, from, f);
106 TestEffectOfMove<P,InterestEmpty,DL>::testShort(*this, mask, from, f);
107 TestEffectOfMove<P,InterestEmpty,D>::testShort(*this, mask, from, f);
108 TestEffectOfMove<P,InterestEmpty,DR>::testShort(*this, mask, from, f);
109 TestEffectOfMove<P,InterestEmpty,UUL>::testShort(*this, mask, from, f);
110 TestEffectOfMove<P,InterestEmpty,UUR>::testShort(*this, mask, from, f);
111 TestEffectOfMove<P,InterestEmpty,LONG_UL>::testLong(*this, mask, from, f);
112 TestEffectOfMove<P,InterestEmpty,LONG_U>::testLong(*this, mask, from, f);
113 TestEffectOfMove<P,InterestEmpty,LONG_UR>::testLong(*this, mask, from, f);
114 TestEffectOfMove<P,InterestEmpty,LONG_L>::testLong(*this, mask, from, f);
115 TestEffectOfMove<P,InterestEmpty,LONG_R>::testLong(*this, mask, from, f);
116 TestEffectOfMove<P,InterestEmpty,LONG_DL>::testLong(*this, mask, from, f);
117 TestEffectOfMove<P,InterestEmpty,LONG_D>::testLong(*this, mask, from, f);
118 TestEffectOfMove<P,InterestEmpty,LONG_DR>::testLong(*this, mask, from, f);
121template <class Function, bool InterestEmpty>
122void osl::NumEffectState::
123forEachEffectOfPtypeO(Square from, PtypeO ptypeo, Function& f) const
125 const Player P = getOwner(ptypeo);
127 this->template forEachEffectOfPtypeO<BLACK,Function,InterestEmpty>
128 (from, getPtype(ptypeo), f);
130 this->template forEachEffectOfPtypeO<WHITE,Function,InterestEmpty>
131 (from, getPtype(ptypeo), f);
135template <osl::Player P>
137osl::NumEffectState::safeCaptureNotByKing(Square target, Piece king) const
139 assert(king.owner() == P);
140 assert(king.ptype() == KING);
141 PieceMask ignore = pin(P);
142 ignore.set(king.number());
143 const Piece piece = findAttackNotBy(P, target, ignore);
146 SafeCapture safe_captures(*this);
147 this->template forEachEffectNotBy<P>(target, king, safe_captures);
149 return safe_captures.safe_one;
152#endif /* OSL_NUM_EFFECT_STATE_TCC */
153// ;;; Local Variables:
155// ;;; c-basic-offset:2