00001 #ifndef _EFFECTUTIL_H
00002 #define _EFFECTUTIL_H
00003
00004 #include "osl/state/numEffectState.h"
00005 #include "osl/misc/carray.h"
00006 #include "osl/container/pieceVector.h"
00007
00008 #include <iosfwd>
00009 #include <cassert>
00010
00011 namespace osl
00012 {
00013 namespace state
00014 {
00015 class SimpleState;
00016 }
00017 namespace container
00018 {
00019 class PieceVector;
00020 }
00021
00022 namespace effect_util
00023 {
00024 using state::SimpleState;
00030 struct EffectUtil
00031 {
00038 template <class EffectState>
00039 static Piece cheapestPiece(Player P, const EffectState&,
00040 Position effectTarget);
00041 static Ptype cheapestPtype(Player P, const NumEffectState&,
00042 Position effect_target);
00050 template <class EffectState>
00051 static Piece promotablePiece(Player P, const EffectState&,
00052 Position effectTarget);
00053
00054
00058 template <class EffectState>
00059 static bool isKingInCheck(Player P, const EffectState& state)
00060 {
00061 const Position king_position=state.getKingPosition(P);
00062
00063 if (king_position.isPieceStand())
00064 return false;
00065 return state.hasEffectBy(alt(P), king_position);
00066 }
00071 template <class EffectState>
00072 static Piece kingAttackPiece(Player P, const EffectState& state)
00073 {
00074 const Position king_position = state.getKingPosition(P);
00075
00076 if (king_position.isPieceStand())
00077 return Piece::EMPTY();
00078 return state.hasEffectPiece(alt(P), king_position);
00079 }
00083 template <class EffectState>
00084 static void showEffect(const EffectState& state, Position target,
00085 std::ostream&);
00086
00092 template <class State, class Function, bool InterestEmpty>
00093 static void forEachEffectOfPtypeO(const State& state, Position, PtypeO,
00094 Function& f);
00095 template <Player P, class State, class Function, bool InterestEmpty>
00096 static void forEachEffectOfPtypeO(const State& state, Position, Ptype,
00097 Function& f);
00103 template <class State, class Function, bool InterestEmpty>
00104 static void forEachEffectOfMove(const State& state, Move m, Function& f);
00105 template <class State, class Function>
00106 static void forEachEffectPositionOfMove(const State& state, Move m, Function& f)
00107 {
00108 forEachEffectOfMove<State,Function,true>(state, m, f);
00109 }
00110 template <class State, class Function>
00111 static void forEachEffectPieceOfMove(const State& state, Move m, Function& f)
00112 {
00113 forEachEffectOfMove<State,Function,false>(state, m, f);
00114 }
00115
00121 static Piece mostValuableEffectOfMoveNotKing(Player target,
00122 const SimpleState& state, Move m);
00123
00129 static void mostValuableEffectOfMoveNotKing(Player target,
00130 const SimpleState& state,
00131 Move m, CArray<Piece,2>& out);
00132
00139 template <Player P, class EffectState>
00140 static Piece safeCaptureNotByKing(const EffectState& state, Position target,
00141 Piece king);
00142 template <class EffectState>
00143 static Piece safeCaptureNotByKing(Player P, const EffectState& state,
00144 Position target)
00145 {
00146 const Piece king = state.getKingPiece(P);
00147 if (P == BLACK)
00148 return safeCaptureNotByKing<BLACK,EffectState>(state, target, king);
00149 else
00150 return safeCaptureNotByKing<WHITE,EffectState>(state, target, king);
00151 }
00152
00158 template <class EffectState, class Action>
00159 static void forEachEffect(Player P, const EffectState& state, Position pos,
00160 Action& a)
00161 {
00162 if (P == BLACK)
00163 state.template forEachEffect<BLACK>(pos,a);
00164 else
00165 state.template forEachEffect<WHITE>(pos,a);
00166 }
00170 template <class EffectState>
00171 static void findEffect(Player P, const EffectState& state, Position target,
00172 container::PieceVector& out);
00181 template<Player P>
00182 static bool isOpenAttackMove(const SimpleState& state, Position target, Position from, Position to);
00192 template<Player P>
00193 static bool isAddEffectMove(const SimpleState& state, Position target,Move move);
00194
00198 static void findThreat(const NumEffectState& state, Position position,
00199 PtypeO ptypeo, PieceVector& out);
00200
00201 class SelectMostValuable;
00202 class FindThreat;
00203 template <int N> class SelectMostValuableN;
00204 template <class EffectState> class SafeCapture;
00205 };
00206
00207 }
00208 using effect_util::EffectUtil;
00209 }
00210
00211 #endif
00212
00213
00214
00215