All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
countEffect2.h
Go to the documentation of this file.
1 /* countEffect2.h
2  */
3 #ifndef _COUNTEFFECT2_H
4 #define _COUNTEFFECT2_H
5 
6 #include "osl/rating/ratingEnv.h"
9 
10 namespace osl
11 {
12  namespace rating
13  {
14  struct CountEffect2
15  {
16  static const int Max = 2;
18  CountEffect2(int a, int d) : attack(a), defense(d)
19  {
20  }
21  static std::pair<int,int> count(const NumEffectState& state, Square position,
22  const RatingEnv& env)
23  {
24  int attack = 0, defense = 0;
25  if (position.isOnBoard()) {
26  assert(position.isOnBoard());
27  const Player turn = state.turn();
28  attack = std::min(Max, state.countEffect(turn, position, env.my_pin));
29  defense = std::min(Max, state.countEffect(alt(turn), position, env.op_pin));
30  if (attack && (attack < Max))
31  attack += AdditionalEffect::hasEffect(state, position, turn);
32  if (defense && (defense < Max))
33  defense += AdditionalEffect::hasEffect(state, position, alt(turn));
34  }
35  return std::make_pair(attack, defense);
36  }
37  bool match(const NumEffectState& state, Square position, const RatingEnv& env) const
38  {
39  std::pair<int,int> ad = count(state, position, env);
40  return attack == ad.first && defense == ad.second;
41  }
42  static std::string name(int attack, int defense);
43  static int index(const NumEffectState& state, Square position, const RatingEnv& env)
44  {
45  if (! position.isOnBoard())
46  return 0;
47  if (env.counteffect2_cache[position.index()] < 0)
48  {
49  std::pair<int,int> ad = count(state, position, env);
50  env.counteffect2_cache[position.index()] = ad.first*(Max+1)+ad.second;
51  }
52  return env.counteffect2_cache[position.index()];
53  }
54  };
55  }
56 }
57 
58 #endif /* _COUNTEFFECT2_H */
59 // ;;; Local Variables:
60 // ;;; mode:c++
61 // ;;; c-basic-offset:2
62 // ;;; End: