group/escape.h
Go to the documentation of this file.
/* escape.h
*/
#ifndef GROUP_ESCAPE_H
#define GROUP_ESCAPE_H
#include "osl/rating/group.h"
#include "osl/rating/feature/escape.h"
namespace osl
{
namespace rating
{
struct FromEffectGroup : public Group
{
FromEffectGroup();
void show(std::ostream& os, int name_width, const range_t& range,
const std::vector<double>& weights) const
{
showTopN(os, name_width, range, weights, 3);
}
int findMatch(const NumEffectState& state, Move move, const RatingEnv& env) const
{
if (move.isDrop())
return -1;
const int index = CountEffect2::index(state, move.from(), env);
const int progress8 = env.progress.value()/2;
return index*8 + progress8;
}
bool effectiveInCheck() const { return true; }
};
struct PtypeAttackedGroup : public Group
{
PtypeAttackedGroup();
void show(std::ostream& os, int name_width, const range_t& range,
const std::vector<double>& weights) const
{
showTopN(os, name_width, range, weights, 3);
}
int findMatch(const NumEffectState& state, Move move, const RatingEnv& env) const
{
if (move.isDrop())
return -1;
const int progress8 = env.progress.value()/2;
const Ptype self = move.oldPtype();
const Ptype attack = state.findCheapAttack(alt(move.player()), move.from()).ptype();
const int index = (self-PTYPE_PIECE_MIN)*(PTYPE_MAX+1-PTYPE_MIN)+attack;
return index*8 + progress8;
}
bool effectiveInCheck() const { return true; }
};
struct ToSupportedGroup : public Group
{
ToSupportedGroup() : Group("ToSupported")
{
for (int p=0; p<8; ++p) // progress8
push_back(new ToSupported());
}
void show(std::ostream& os, int name_width, const range_t& range,
const std::vector<double>& weights) const
{
showAll(os, name_width, range, weights);
}
int findMatch(const NumEffectState& state, Move move, const RatingEnv& env) const
{
if (! (*this)[0].match(state, move, env))
return -1;
const int progress8 = env.progress.value()/2;
return progress8;
}
bool effectiveInCheck() const { return true; }
};
struct ImmediateEscapeGroup : public Group
{
ImmediateEscapeGroup();
void show(std::ostream& os, int name_width, const range_t& range,
const std::vector<double>& weights) const
{
showTopN(os, name_width, range, weights, 3);
}
int findMatchWithoutProgress(const NumEffectState& state, Move move, const RatingEnv& env) const
{
if (move.isDrop())
return -1;
const Move last_move = env.history.lastMove();
if (! last_move.isNormal()
|| ! state.hasEffectIf(last_move.ptypeO(), last_move.to(), move.from()))
return -1;
return (move.ptype() - PTYPE_PIECE_MIN) * (PTYPE_MAX+1 - PTYPE_PIECE_MIN)
+ last_move.ptype() - PTYPE_PIECE_MIN;
}
int findMatch(const NumEffectState& state, Move move, const RatingEnv& env) const
{
const int index = findMatchWithoutProgress(state, move, env);
if (index < 0)
return index;
const int progress8 = env.progress.value()/2;
return index*8 + progress8;
}
};
class KingEscapeGroup : public Group
{
public:
KingEscapeGroup();
void show(std::ostream& os, int name_width, const range_t& range,
const std::vector<double>& weights) const
{
showAll(os, name_width, range, weights);
}
int findMatch(const NumEffectState& state, Move move, const RatingEnv& env) const
{
if (! state.inCheck())
return -1;
const Ptype self = move.ptype();
const int index = self-PTYPE_PIECE_MIN;
assert((*this)[index].match(state, move, env));
return index;
}
bool effectiveInCheck() const { return true; }
};
}
}
#endif /* GROUP_ESCAPE_H */
// ;;; Local Variables:
// ;;; mode:c++
// ;;; c-basic-offset:2
// ;;; End:
osl::Move
圧縮していない moveの表現 .
Definition basic_type.h:1052
osl::Move::ptypeO
PtypeO ptypeO() const
移動後のPtype, i.e., 成る手だった場合成った後
Definition basic_type.h:1162
osl::Move::ptype
Ptype ptype() const
Definition basic_type.h:1155
osl::Move::player
Player player() const
Definition basic_type.h:1195
osl::Move::isDrop
bool isDrop() const
Definition basic_type.h:1150
osl::Move::isNormal
bool isNormal() const
INVALID でも PASS でもない.
Definition basic_type.h:1088
osl::Move::oldPtype
Ptype oldPtype() const
移動前のPtype, i.e., 成る手だった場合成る前
Definition basic_type.h:1174
osl::Move::to
const Square to() const
Definition basic_type.h:1132
osl::Move::from
const Square from() const
Definition basic_type.h:1125
osl::NumEffectState
利きを持つ局面
Definition numEffectState.h:34
osl::NumEffectState::findCheapAttack
const Piece findCheapAttack(Player P, Square square) const
Definition numEffectState.h:560
osl::NumEffectState::hasEffectIf
bool hasEffectIf(PtypeO ptypeo, Square attacker, Square target) const
attackerにptypeoの駒がいると仮定した場合にtargetに利きがあるかどうか を stateをupdateしないで確かめる.
Definition numEffectState.h:465
osl::NumEffectState::inCheck
bool inCheck(Player P) const
Pの玉が王手状態
Definition numEffectState.h:88
osl::Piece::ptype
Ptype ptype() const
Definition basic_type.h:821
osl::container::MoveStack::lastMove
const Move lastMove(size_t last=1) const
Definition moveStack.h:28
osl::progress::ProgressN::value
int value() const
Definition progress.h:22
osl::rating::Group::showAll
void showAll(std::ostream &os, int name_width, const range_t &range, const std::vector< double > &weights) const
Definition group.cc:74
osl::rating::Group::showTopN
void showTopN(std::ostream &os, int name_width, const range_t &range, const std::vector< double > &weights, int n) const
Definition group.cc:100
osl::rating::Group::Group
Group(const std::string &name)
Definition group.cc:15
osl::rating::KingEscapeGroup::show
void show(std::ostream &os, int name_width, const range_t &range, const std::vector< double > &weights) const
Definition group/escape.h:108
osl::rating::KingEscapeGroup::findMatch
int findMatch(const NumEffectState &state, Move move, const RatingEnv &env) const
Definition group/escape.h:113
osl::rating::KingEscapeGroup::effectiveInCheck
bool effectiveInCheck() const
Definition group/escape.h:122
osl::rating::KingEscapeGroup::KingEscapeGroup
KingEscapeGroup()
Definition escape.cc:37
osl::rating::RatingEnv
Definition ratingEnv.h:16
osl::rating::RatingEnv::history
MoveStack history
Definition ratingEnv.h:18
osl::rating::RatingEnv::progress
Progress16 progress
Definition ratingEnv.h:22
osl::rating::ToSupported
Definition feature/escape.h:43
escape.h
group.h
osl::rating
Definition construct.h:18
osl::rating::range_t
std::pair< int, int > range_t
Definition range.h:10
osl
Definition additionalEffect.h:6
osl::Ptype
Ptype
駒の種類を4ビットでコード化する
Definition basic_type.h:84
osl::PTYPE_PIECE_MIN
@ PTYPE_PIECE_MIN
Definition basic_type.h:104
osl::PTYPE_MAX
@ PTYPE_MAX
Definition basic_type.h:105
osl::PTYPE_MIN
@ PTYPE_MIN
Definition basic_type.h:102
osl::alt
constexpr Player alt(Player player)
Definition basic_type.h:13
osl::rating::CountEffect2::index
static int index(const NumEffectState &state, Square position, const RatingEnv &env)
Definition countEffect2.h:43
osl::rating::FromEffectGroup::findMatch
int findMatch(const NumEffectState &state, Move move, const RatingEnv &env) const
Definition group/escape.h:21
osl::rating::FromEffectGroup::FromEffectGroup
FromEffectGroup()
Definition escape.cc:6
osl::rating::FromEffectGroup::effectiveInCheck
bool effectiveInCheck() const
Definition group/escape.h:29
osl::rating::FromEffectGroup::show
void show(std::ostream &os, int name_width, const range_t &range, const std::vector< double > &weights) const
Definition group/escape.h:16
osl::rating::ImmediateEscapeGroup::show
void show(std::ostream &os, int name_width, const range_t &range, const std::vector< double > &weights) const
Definition group/escape.h:78
osl::rating::ImmediateEscapeGroup::findMatchWithoutProgress
int findMatchWithoutProgress(const NumEffectState &state, Move move, const RatingEnv &env) const
Definition group/escape.h:83
osl::rating::ImmediateEscapeGroup::findMatch
int findMatch(const NumEffectState &state, Move move, const RatingEnv &env) const
Definition group/escape.h:94
osl::rating::ImmediateEscapeGroup::ImmediateEscapeGroup
ImmediateEscapeGroup()
Definition escape.cc:26
osl::rating::PtypeAttackedGroup::show
void show(std::ostream &os, int name_width, const range_t &range, const std::vector< double > &weights) const
Definition group/escape.h:35
osl::rating::PtypeAttackedGroup::PtypeAttackedGroup
PtypeAttackedGroup()
Definition escape.cc:15
osl::rating::PtypeAttackedGroup::effectiveInCheck
bool effectiveInCheck() const
Definition group/escape.h:50
osl::rating::PtypeAttackedGroup::findMatch
int findMatch(const NumEffectState &state, Move move, const RatingEnv &env) const
Definition group/escape.h:40
osl::rating::ToSupportedGroup::show
void show(std::ostream &os, int name_width, const range_t &range, const std::vector< double > &weights) const
Definition group/escape.h:60
osl::rating::ToSupportedGroup::ToSupportedGroup
ToSupportedGroup()
Definition group/escape.h:55
osl::rating::ToSupportedGroup::effectiveInCheck
bool effectiveInCheck() const
Definition group/escape.h:72
osl::rating::ToSupportedGroup::findMatch
int findMatch(const NumEffectState &state, Move move, const RatingEnv &env) const
Definition group/escape.h:65