countEffect2.h
Go to the documentation of this file.
00001 /* countEffect2.h
00002  */
00003 #ifndef _COUNTEFFECT2_H
00004 #define _COUNTEFFECT2_H
00005 
00006 #include "osl/rating/ratingEnv.h"
00007 #include "osl/state/numEffectState.h"
00008 #include "osl/effect_util/additionalEffect.h"
00009 
00010 namespace osl
00011 {
00012   namespace rating
00013   {
00014     struct CountEffect2
00015     {
00016       static const int Max = 2;
00017       int attack, defense;
00018       CountEffect2(int a, int d) : attack(a), defense(d)
00019       {
00020       }
00021       static std::pair<int,int> count(const NumEffectState& state, Square position,
00022                                       const RatingEnv& env) 
00023       {
00024         int attack = 0, defense = 0;
00025         if (position.isOnBoard()) {
00026           assert(position.isOnBoard());
00027           const Player turn = state.turn();
00028           attack = std::min(Max, state.countEffect(turn, position, env.my_pin));
00029           defense = std::min(Max, state.countEffect(alt(turn), position, env.op_pin));
00030           if (attack && (attack < Max))
00031             attack += AdditionalEffect::hasEffect(state, position, turn);
00032           if (defense && (defense < Max))
00033             defense += AdditionalEffect::hasEffect(state, position, alt(turn));
00034         }
00035         return std::make_pair(attack, defense);
00036       }
00037       bool match(const NumEffectState& state, Square position, const RatingEnv& env) const
00038       {
00039         std::pair<int,int> ad = count(state, position, env);
00040         return attack == ad.first && defense == ad.second;
00041       }
00042       static std::string name(int attack, int defense);
00043       static int index(const NumEffectState& state, Square position, const RatingEnv& env) 
00044       {
00045         if (! position.isOnBoard())
00046           return 0;
00047         if (env.counteffect2_cache[position.index()] < 0) 
00048         {
00049           std::pair<int,int> ad = count(state, position, env);
00050           env.counteffect2_cache[position.index()] = ad.first*(Max+1)+ad.second;
00051         }
00052         return env.counteffect2_cache[position.index()];
00053       }
00054     };
00055   }
00056 }
00057 
00058 #endif /* _COUNTEFFECT2_H */
00059 // ;;; Local Variables:
00060 // ;;; mode:c++
00061 // ;;; c-basic-offset:2
00062 // ;;; End:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines