00001
00002
00003 #include "osl/effect_util/effectUtil.h"
00004 #include "osl/effect_util/effectUtil.tcc"
00005 #include "osl/eval/pieceEval.h"
00006 #include "osl/eval/progressEval.h"
00007 #include "osl/eval/ml/openMidEndingEval.h"
00008 #include "osl/state/numEffectState.h"
00009
00010 void
00011 osl::effect_util::EffectUtil::
00012 findEffect(Player P, const NumEffectState& state, Square target,
00013 PieceVector& out)
00014 {
00015 effect_action::StorePiece store(&out);
00016 forEachEffect(P, state, target, store);
00017 }
00018
00019 #ifndef DFPNSTATONE
00020 namespace osl
00021 {
00022 #ifndef MINIMAL
00023 template void
00024 EffectUtil::findThreat<PieceEval>(const NumEffectState& state,
00025 Square position,
00026 PtypeO ptypeo,
00027 PieceVector& out);
00028 template void
00029 EffectUtil::findThreat<osl::eval::ProgressEval>(const NumEffectState& state,
00030 Square position,
00031 PtypeO ptypeo,
00032 PieceVector& out);
00033 #endif
00034 template void
00035 EffectUtil::findThreat<osl::eval::ml::OpenMidEndingEval>(
00036 const NumEffectState& state,
00037 Square position,
00038 PtypeO ptypeo,
00039 PieceVector& out);
00040 template Piece
00041 EffectUtil::safeCaptureNotByKing<BLACK>(NumEffectState const&, Square, Piece);
00042 template Piece
00043 EffectUtil::safeCaptureNotByKing<WHITE>(NumEffectState const&, Square, Piece);
00044 }
00045 #endif
00046
00047 template <class EvalT>
00048 struct osl::effect_util::EffectUtil::FindThreat
00049 {
00050 const NumEffectState& state;
00051 Player target;
00052 int attacker_value;
00053 PieceVector& supported, & unsupported;
00054 FindThreat(const NumEffectState& st, Player t, int a,
00055 PieceVector& s, PieceVector& u)
00056 : state(st), target(t), attacker_value(a), supported(s), unsupported(u)
00057 {
00058 }
00059 void operator()(Square pos)
00060 {
00061 const Piece cur = state.pieceOnBoard(pos);
00062 assert(cur.isPiece());
00063 if (cur.owner() != target)
00064 return;
00065 if (state.hasEffectAt(target, pos))
00066 {
00067 if (abs(EvalT::captureValue(cur.ptypeO()))
00068 > attacker_value)
00069 supported.push_back(cur);
00070 }
00071 else
00072 {
00073 unsupported.push_back(cur);
00074 }
00075 }
00076 };
00077
00078 template <class EvalT>
00079 void osl::EffectUtil::
00080 findThreat(const NumEffectState& state, Square position,
00081 PtypeO ptypeo, PieceVector& out)
00082 {
00083 PieceVector supported, unsupported;
00084 const int attacker_value = abs(EvalT::captureValue(ptypeo));
00085 FindThreat<EvalT> f(state, alt(getOwner(ptypeo)), attacker_value,
00086 supported, unsupported);
00087 forEachEffectOfPtypeO<FindThreat<EvalT>, false>
00088 (state, position, ptypeo, f);
00089
00090 unsupported.sortByPtype();
00091 supported.sortByPtype();
00092 PieceVector::iterator u=unsupported.begin(), s=supported.begin();
00093
00094 if (u!=unsupported.end())
00095 {
00096 while ((s!=supported.end())
00097 && ((abs(EvalT::captureValue(s->ptypeO()))
00098 - attacker_value)
00099 > abs(EvalT::captureValue(u->ptypeO()))))
00100 {
00101 out.push_back(*s);
00102 ++s;
00103 }
00104 }
00105 out.push_back(u, unsupported.end());
00106 out.push_back(s, supported.end());
00107 }
00108
00109
00110
00111
00112