00001 #include "osl/effect_util/additionalEffect.h"
00002 #include "osl/effect_util/additionalOrShadow.h"
00003 #include "osl/effect_util/effectUtil.h"
00004 #include "osl/effect_util/effectUtil.tcc"
00005 #include <boost/foreach.hpp>
00006
00007 bool osl::effect_util::
00008 AdditionalEffect::hasEffect(const NumEffectState& state, Square target,
00009 Player attack)
00010 {
00011 PieceMask direct = state.effectSetAt(target) & state.piecesOnBoard(attack);
00012 PieceMask mask;
00013 mask.setAll();
00014 mask.clearBit<KNIGHT>();
00015 direct &= (state.promotedPieces() | mask);
00016
00017 while (direct.any()) {
00018 const int num = direct.takeOneBit();
00019 const Square p = state.pieceOf(num).square();
00020 const Direction d=Board_Table.getShort8<BLACK>(p,target);
00021 const int num1=state.longEffectNumTable()[num][d];
00022 if(!Piece::isEmptyNum(num1) && state.pieceOf(num1).owner()==attack) return true;
00023 }
00024 return false;
00025 }
00026
00027 template <int count_max>
00028 int osl::effect_util::
00029 AdditionalEffect::count(const NumEffectState& state, Square target,
00030 Player attack)
00031 {
00032 PieceVector direct_pieces;
00033 EffectUtil::findEffect(attack, state, target, direct_pieces);
00034 return AdditionalOrShadow::count<count_max>
00035 (direct_pieces, state, target, attack);
00036 }
00037
00038 bool osl::effect_util::
00039 AdditionalEffect::hasEffectStable(const NumEffectState& state, Square target,
00040 Player attack)
00041 {
00042 return count<1>(state, target, attack);
00043 }
00044
00045 int osl::effect_util::
00046 AdditionalEffect::count2(const NumEffectState& state, Square target,
00047 Player attack)
00048 {
00049 return count<2>(state, target, attack);
00050 }
00051
00052 void osl::effect_util::
00053 AdditionalEffect::find(const NumEffectState& state, Square target,
00054 const PieceVector& direct_effects,
00055 PieceVector& black, PieceVector& white)
00056 {
00057 BOOST_FOREACH(Piece p, direct_effects)
00058 {
00059 const Square from = p.square();
00060 const Offset32 diff32 = Offset32(from, target);
00061 const Offset step = Board_Table.getShortOffsetNotKnight(diff32);
00062 if (step.zero())
00063 continue;
00064
00065 Piece candidate=state.nextPiece(from, step);
00066 if (! candidate.isPiece())
00067 continue;
00068 const Offset32 diff_reverse = Offset32(target,candidate.square());
00069 for (; candidate.isPiece();
00070 candidate=state.nextPiece(candidate.square(), step))
00071 {
00072 const EffectContent effect
00073 = Ptype_Table.getEffect(candidate.ptypeO(), diff_reverse);
00074 if (! effect.hasEffect())
00075 break;
00076 if (candidate.owner() == BLACK)
00077 black.push_back(candidate);
00078 else
00079 white.push_back(candidate);
00080 }
00081 }
00082
00083 }
00084
00085 void osl::effect_util::
00086 AdditionalEffect::find(const NumEffectState& state, Square target,
00087 PieceVector& black, PieceVector& white)
00088 {
00089 PieceVector direct_pieces;
00090 EffectUtil::findEffect(BLACK, state, target, direct_pieces);
00091 find(state, target, direct_pieces, black, white);
00092
00093 direct_pieces.clear();
00094 EffectUtil::findEffect(WHITE, state, target, direct_pieces);
00095 find(state, target, direct_pieces, black, white);
00096 }
00097
00098 void osl::effect_util::
00099 AdditionalEffect::count(const NumEffectState& state, Square target,
00100 int& black, int& white)
00101 {
00102 PieceVector black_pieces, white_pieces;
00103 find(state, target, black_pieces, white_pieces);
00104 black = black_pieces.size();
00105 white = white_pieces.size();
00106 }
00107
00108
00109
00110
00111