effect5x3.h
Go to the documentation of this file.
00001 /* effect5x3.h
00002  */
00003 #ifndef PROGRESS_EFFECT5X3_H
00004 #define PROGRESS_EFFECT5X3_H
00005 
00006 #include "osl/progress/progress16.h"
00007 #include "osl/state/numEffectState.h"
00008 #include "osl/centering5x3.h"
00009 #include "osl/misc/carray.h"
00010 #include <algorithm>
00011 namespace osl
00012 {
00013   namespace progress
00014   {
00026     struct Effect5x3
00027     {
00028     public:
00029       static void updateStand(int& old_stand, Move last_move);
00030       static int makeProgressAll(Player defense, const NumEffectState& state,
00031                                  Square king);
00032       static int makeProgressArea(Player attack, const NumEffectState& state,
00033                                   Square king);
00034     public:
00035       static int makeProgressStand(Player attack, const NumEffectState& state);
00044       static int makeProgress(Player defense, const NumEffectState& state){
00045         return makeProgressAll(defense,state,state.kingSquare(defense));
00046       }
00047       static int makeProgress(const NumEffectState& state)
00048       {
00049         return makeProgress(BLACK, state) + makeProgress(WHITE, state);
00050       }
00054       static const Progress16 progress16(int progress)
00055       {
00056         assert(progress >= 0);
00057         const int rank = progress / 8; // 適当
00058         return Progress16(std::min(rank, 15));
00059       }
00064       static const Progress16 progress16each(int progress)
00065       {
00066         assert(progress >= 0);
00067         const int rank = progress / 8; // 調整中
00068         return Progress16(std::min(rank, 15));
00069       }
00070     protected:
00071       CArray<int,2> progresses, stand_progresses, area_progresses;
00072     public:
00073       explicit Effect5x3(const NumEffectState& state);
00074       void changeTurn() {}
00075       int progress(Player p) const { return progresses[p]; }
00076       const Progress16 progress16() const
00077       {
00078         return progress16(progresses[0] + progresses[1]);
00079       }
00080       const Progress16 progress16(Player p) const
00081       {
00082         return progress16each(progress(p));
00083       }
00084       // 必要なもの
00085       Effect5x3 expect(const NumEffectState& state, Move move) const;
00086       void update(const NumEffectState& new_state, Move last_move);
00087     };
00088     struct Effect5x3WithBonus : public Effect5x3
00089     {
00090       explicit Effect5x3WithBonus(const NumEffectState& state);
00091       template <Player Attack>
00092       static int makeProgressAreaBonus(const NumEffectState& state,
00093                                        Square king);
00094       template <Player Attack, bool AlwaysPromotable, bool AlwaysNotPromotable>
00095       static int makeProgressAreaBonus(const NumEffectState& state, 
00096                                        Square king, Square center);
00097       const Progress16 progress16bonus(Player p) const
00098       {
00099         return progress16each(progress_bonuses[p] +
00100                               stand_progresses[p]);
00101       }
00102       void update(const NumEffectState& new_state, Move last_move);
00103       Effect5x3WithBonus expect(const NumEffectState& state, Move move) const;
00104       // Public for testing
00105       int countEffectPieces(const NumEffectState &state, Player attack) const;
00106       // p is defense player
00107       const PieceMask effect5x3Mask(Player p) const { return effect_mask[p]; }
00108     private:
00109       void updateProgressBonuses(const NumEffectState& state, bool black=true, bool white=true);
00110       static int attackEffect3(const NumEffectState& state, Player attack, Square target);
00111       template <Player Defense>
00112       static PieceMask makeEffectMask(const NumEffectState& state);
00113       void updateStand(Player pl, Move m) { Effect5x3::updateStand(stand_progresses[pl], m); }
00114 
00115       CArray<int,2> progress_bonuses;
00116       CArray<PieceMask, 2> effect_mask;
00117     };
00118   } // namespace progress
00119 } // namespace osl
00120 
00121 #endif /* PROGRESS_EFFECT5X3_H */
00122 // ;;; Local Variables:
00123 // ;;; mode:c++
00124 // ;;; c-basic-offset:2
00125 // ;;; End:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines