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