sendOffSquare.h
Go to the documentation of this file.
00001 /* sendOffSquare.h
00002  */
00003 #ifndef OSL_SENDOFFPOSITION_H
00004 #define OSL_SENDOFFPOSITION_H
00005 
00006 #include "osl/state/numEffectState.h"
00007 #include "osl/container/square8.h"
00008 namespace osl
00009 {
00010   namespace effect_util
00011   {
00012     struct Offset8 : public FixedCapacityVector<int,8>
00013     {
00014     };
00016     struct SendOffSquare
00017     {
00018       typedef uint8_t SendOff8;
00019       template <Player Attack>
00020       static bool onlyOneSupport(const NumEffectState& state, Square target)
00021       {
00022         const Piece p = state.pieceAt(target);
00023         if (! p.isOnBoardByOwner<PlayerTraits<Attack>::opponent>())
00024           return false;
00025         return state.hasEffectAt<Attack>(target) 
00026           && (state.countEffect(alt(Attack), target) == 1);
00027       }
00028       template <Player Attack>
00029       static SendOff8 find(const NumEffectState& state, Square king_position,
00030                               Square8& out);
00031       static SendOff8 find(Player attack,
00032                               const NumEffectState& state, Square king_position,
00033                               Square8& out);
00034       static SendOff8 invalidData() { return 0xff; }
00035       static void unpack(SendOff8, Square king, Square8& out);
00036       struct Table
00037       {
00038         CArray<Offset,8> normal;
00039         CArray<Offset8,8> reverse;
00040         CArray<Offset8,256> reverse_all;
00041         Table();
00042       };
00043     private:
00044       static const Table table;
00045       template <Player Attack>
00046       static void testSquare(const NumEffectState& state, Square candidate,
00047                                int id, int& out)
00048       {
00049         if (onlyOneSupport<Attack>(state, candidate))
00050         {
00051           out |= (1<<id);
00052         }
00053       }
00054     };
00055   } // namespace effect_util
00056   using effect_util::SendOffSquare;
00057 } // namespace osl
00058 
00059 #endif /* OSL_SENDOFFPOSITION_H */
00060 // ;;; Local Variables:
00061 // ;;; mode:c++
00062 // ;;; c-basic-offset:2
00063 // ;;; coding:utf-8
00064 // ;;; End:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines