countEffect2.h
Go to the documentation of this file.
/* countEffect2.h
*/
#ifndef _COUNTEFFECT2_H
#define _COUNTEFFECT2_H
#include "osl/rating/ratingEnv.h"
#include "osl/numEffectState.h"
#include "osl/additionalEffect.h"
namespace osl
{
namespace rating
{
struct CountEffect2
{
static const int Max = 2;
int attack, defense;
CountEffect2(int a, int d) : attack(a), defense(d)
{
}
static std::pair<int,int> count(const NumEffectState& state, Square position,
const RatingEnv& env)
{
int attack = 0, defense = 0;
if (position.isOnBoard()) {
assert(position.isOnBoard());
const Player turn = state.turn();
attack = std::min(Max, state.countEffect(turn, position, env.my_pin));
defense = std::min(Max, state.countEffect(alt(turn), position, env.op_pin));
if (attack && (attack < Max))
attack += AdditionalEffect::hasEffect(state, position, turn);
if (defense && (defense < Max))
defense += AdditionalEffect::hasEffect(state, position, alt(turn));
}
return std::make_pair(attack, defense);
}
bool match(const NumEffectState& state, Square position, const RatingEnv& env) const
{
std::pair<int,int> ad = count(state, position, env);
return attack == ad.first && defense == ad.second;
}
static std::string name(int attack, int defense);
static int index(const NumEffectState& state, Square position, const RatingEnv& env)
{
if (! position.isOnBoard())
return 0;
if (env.counteffect2_cache[position.index()] < 0)
{
std::pair<int,int> ad = count(state, position, env);
env.counteffect2_cache[position.index()] = ad.first*(Max+1)+ad.second;
}
return env.counteffect2_cache[position.index()];
}
};
}
}
#endif /* _COUNTEFFECT2_H */
// ;;; Local Variables:
// ;;; mode:c++
// ;;; c-basic-offset:2
// ;;; End:
additionalEffect.h
osl::NumEffectState
利きを持つ局面
Definition numEffectState.h:34
osl::NumEffectState::countEffect
int countEffect(Player player, Square target) const
利きの数を数える.
Definition numEffectState.h:266
osl::SimpleState::turn
Player turn() const
Definition simpleState.h:220
osl::Square
Definition basic_type.h:532
osl::Square::index
unsigned int index() const
Definition basic_type.h:572
osl::Square::isOnBoard
bool isOnBoard() const
盤面上を表すかどうかの判定． 1<=x() && x()<=9 && 1<=y() && y()<=9 Squareの内部表現に依存する．
Definition basic_type.h:583
osl::rating::RatingEnv
Definition ratingEnv.h:16
osl::rating::RatingEnv::op_pin
PieceMask op_pin
Definition ratingEnv.h:20
osl::rating::RatingEnv::counteffect2_cache
CArray< signed char, Square::SIZE > counteffect2_cache
Definition ratingEnv.h:23
osl::rating::RatingEnv::my_pin
PieceMask my_pin
Definition ratingEnv.h:20
osl::rating
Definition construct.h:18
osl
Definition additionalEffect.h:6
osl::Player
Player
Definition basic_type.h:8
osl::alt
constexpr Player alt(Player player)
Definition basic_type.h:13
numEffectState.h
ratingEnv.h
osl::AdditionalEffect::hasEffect
static bool hasEffect(const NumEffectState &, Square target, Player attack)
target に attack の追加利きが一つでもあるか． 相手の影利きが先にある場合は対象としない．
Definition additionalEffect.cc:5
osl::rating::CountEffect2::CountEffect2
CountEffect2(int a, int d)
Definition countEffect2.h:18
osl::rating::CountEffect2::match
bool match(const NumEffectState &state, Square position, const RatingEnv &env) const
Definition countEffect2.h:37
osl::rating::CountEffect2::count
static std::pair< int, int > count(const NumEffectState &state, Square position, const RatingEnv &env)
Definition countEffect2.h:21
osl::rating::CountEffect2::attack
int attack
Definition countEffect2.h:17
osl::rating::CountEffect2::Max
static const int Max
Definition countEffect2.h:16
osl::rating::CountEffect2::name
static std::string name(int attack, int defense)
Definition countEffect2.cc:9
osl::rating::CountEffect2::defense
int defense
Definition countEffect2.h:17
osl::rating::CountEffect2::index
static int index(const NumEffectState &state, Square position, const RatingEnv &env)
Definition countEffect2.h:43