My Project
countEffect2.h
Go to the documentation of this file.
1/* countEffect2.h
2 */
3#ifndef _COUNTEFFECT2_H
4#define _COUNTEFFECT2_H
5
9
10namespace osl
11{
12 namespace rating
13 {
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))
32 if (defense && (defense < Max))
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
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 の追加利きが一つでもあるか. 相手の影利きが先にある場合は対象としない.
bool match(const NumEffectState &state, Square position, const RatingEnv &env) const
static std::pair< int, int > count(const NumEffectState &state, Square position, const RatingEnv &env)
static std::string name(int attack, int defense)
static int index(const NumEffectState &state, Square position, const RatingEnv &env)