My Project
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"
7 #include "osl/numEffectState.h"
8 #include "osl/additionalEffect.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:
利きを持つ局面
int countEffect(Player player, Square target) const
利きの数を数える.
Player turn() const
Definition: simpleState.h:220
unsigned int index() const
Definition: basic_type.h:572
bool isOnBoard() const
盤面上を表すかどうかの判定. 1<=x() && x()<=9 && 1<=y() && y()<=9 Squareの内部表現に依存する.
Definition: basic_type.h:583
CArray< signed char, Square::SIZE > counteffect2_cache
Definition: ratingEnv.h:23
int min(Player p, int v1, int v2)
Definition: evalTraits.h:92
Player
Definition: basic_type.h:8
constexpr Player alt(Player player)
Definition: basic_type.h:13
static bool hasEffect(const NumEffectState &, Square target, Player attack)
target に attack の追加利きが一つでもあるか. 相手の影利きが先にある場合は対象としない.
static std::pair< int, int > count(const NumEffectState &state, Square position, const RatingEnv &env)
Definition: countEffect2.h:21
CountEffect2(int a, int d)
Definition: countEffect2.h:18
bool match(const NumEffectState &state, Square position, const RatingEnv &env) const
Definition: countEffect2.h:37
static const int Max
Definition: countEffect2.h:16
static std::string name(int attack, int defense)
Definition: countEffect2.cc:9
static int index(const NumEffectState &state, Square position, const RatingEnv &env)
Definition: countEffect2.h:43