/usr/include/osl/effect_util/effectUtil.tcc is in libosl-dev 0.6.0-3.1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | #ifndef _EFFECTUTIL_TCC
#define _EFFECTUTIL_TCC
#include "osl/effect_util/effectUtil.h"
#include "osl/effect_action/storePiece.h"
#include "osl/move_classifier/kingOpenMove.h"
#include "osl/container/pieceVector.h"
#include <boost/static_assert.hpp>
namespace osl
{
namespace effect_util
{
template <osl::Player P, bool InterestEmpty, Direction Dir>
struct TestEffectOfMove
{
template <class State, class Function>
static void testShort(const State& s, int mask, Square from,
Function& f)
{
BOOST_STATIC_ASSERT(! DirectionTraits<Dir>::isLong);
if (! (mask & DirectionTraits<Dir>::mask))
return;
const Offset offset = DirectionPlayerTraits<Dir,P>::offset();
const Square target = from+offset;
const Piece piece = s.pieceAt(target);
if (piece.isEdge())
return;
if (InterestEmpty || (! piece.isEmpty()))
f(target);
}
template <class State, class Function>
static void testLong(const State& s, int mask, Square from,
Function& f)
{
BOOST_STATIC_ASSERT(DirectionTraits<Dir>::isLong);
if (! (mask & DirectionTraits<Dir>::mask))
return;
const Offset offset = DirectionPlayerTraits<Dir,P>::offset();
Square target = from+offset;
Piece piece = s.pieceAt(target);
while (piece.isEmpty())
{
if (InterestEmpty)
f(target);
target = target+offset;
piece = s.pieceAt(target);
}
if (piece.isPiece())
{
f(target);
}
}
};
} // namespace effect_util
} // namespace osl
template <osl::Player P, class Function, bool InterestEmpty>
void osl::effect_util::EffectUtil::
forEachEffectOfPtypeO(const NumEffectState& state, Square from, Ptype ptype,
Function& f)
{
const int mask = Ptype_Table.getMoveMask(ptype);
TestEffectOfMove<P,InterestEmpty,UL>::testShort(state, mask, from, f);
TestEffectOfMove<P,InterestEmpty,U>::testShort(state, mask, from, f);
TestEffectOfMove<P,InterestEmpty,UR>::testShort(state, mask, from, f);
TestEffectOfMove<P,InterestEmpty,L>::testShort(state, mask, from, f);
TestEffectOfMove<P,InterestEmpty,R>::testShort(state, mask, from, f);
TestEffectOfMove<P,InterestEmpty,DL>::testShort(state, mask, from, f);
TestEffectOfMove<P,InterestEmpty,D>::testShort(state, mask, from, f);
TestEffectOfMove<P,InterestEmpty,DR>::testShort(state, mask, from, f);
TestEffectOfMove<P,InterestEmpty,UUL>::testShort(state, mask, from, f);
TestEffectOfMove<P,InterestEmpty,UUR>::testShort(state, mask, from, f);
TestEffectOfMove<P,InterestEmpty,LONG_UL>::testLong(state, mask, from, f);
TestEffectOfMove<P,InterestEmpty,LONG_U>::testLong(state, mask, from, f);
TestEffectOfMove<P,InterestEmpty,LONG_UR>::testLong(state, mask, from, f);
TestEffectOfMove<P,InterestEmpty,LONG_L>::testLong(state, mask, from, f);
TestEffectOfMove<P,InterestEmpty,LONG_R>::testLong(state, mask, from, f);
TestEffectOfMove<P,InterestEmpty,LONG_DL>::testLong(state, mask, from, f);
TestEffectOfMove<P,InterestEmpty,LONG_D>::testLong(state, mask, from, f);
TestEffectOfMove<P,InterestEmpty,LONG_DR>::testLong(state, mask, from, f);
}
template <class Function, bool InterestEmpty>
void osl::effect_util::EffectUtil::
forEachEffectOfPtypeO(const NumEffectState& state, Square from, PtypeO ptypeo,
Function& f)
{
const Player P = getOwner(ptypeo);
if (P == BLACK)
forEachEffectOfPtypeO<BLACK,Function,InterestEmpty>
(state, from, getPtype(ptypeo), f);
else
forEachEffectOfPtypeO<WHITE,Function,InterestEmpty>
(state, from, getPtype(ptypeo), f);
}
struct osl::effect_util::EffectUtil::SafeCapture
{
public:
const NumEffectState& state;
Piece safe_one;
SafeCapture(const NumEffectState& s) : state(s), safe_one(Piece::EMPTY())
{
}
template <Player P>
void doAction(Piece effect_piece, Square target)
{
if (move_classifier::KingOpenMove<P>::isMember
(state, effect_piece.ptype(), effect_piece.square(), target))
return;
safe_one = effect_piece;
}
};
template <osl::Player P>
osl::Piece
osl::effect_util::EffectUtil::safeCaptureNotByKing(const NumEffectState& state, Square target,
Piece king)
{
assert(king.owner() == P);
assert(king.ptype() == KING);
PieceMask ignore = state.pin(P);
ignore.set(king.number());
const Piece piece = state.findAttackNotBy(P, target, ignore);
if (piece.isPiece())
return piece;
SafeCapture safe_captures(state);
state.template forEachEffectNotBy<P>(target, king, safe_captures);
return safe_captures.safe_one;
}
template <class EvalT>
struct osl::effect_util::EffectUtil::FindThreat
{
const NumEffectState& state;
Player target;
int attacker_value;
PieceVector& supported, & unsupported;
FindThreat(const NumEffectState& st, Player t, int a,
PieceVector& s, PieceVector& u)
: state(st), target(t), attacker_value(a), supported(s), unsupported(u)
{
}
void operator()(Square pos)
{
const Piece cur = state.pieceOnBoard(pos);
assert(cur.isPiece());
if (cur.owner() != target)
return;
if (state.hasEffectAt(target, pos))
{
if (abs(EvalT::captureValue(cur.ptypeO()))
> attacker_value)
supported.push_back(cur);
}
else
{
unsupported.push_back(cur);
}
}
};
template <class EvalT>
void osl::EffectUtil::
findThreat(const NumEffectState& state, Square position,
PtypeO ptypeo, PieceVector& out)
{
PieceVector supported, unsupported;
const int attacker_value = abs(EvalT::captureValue(ptypeo));
FindThreat<EvalT> f(state, alt(getOwner(ptypeo)), attacker_value,
supported, unsupported);
forEachEffectOfPtypeO<FindThreat<EvalT>, false>
(state, position, ptypeo, f);
unsupported.sortByPtype();
supported.sortByPtype();
PieceVector::iterator u=unsupported.begin(), s=supported.begin();
if (u!=unsupported.end())
{
while ((s!=supported.end())
&& ((abs(EvalT::captureValue(s->ptypeO()))
- attacker_value)
> abs(EvalT::captureValue(u->ptypeO()))))
{
out.push_back(*s);
++s;
}
}
out.push_back(u, unsupported.end());
out.push_back(s, supported.end());
}
#endif /* _EFFECTUTIL_TCC */
// ;;; Local Variables:
// ;;; mode:c++
// ;;; c-basic-offset:2
// ;;; End:
|