group.h
Go to the documentation of this file.
/* group.h
*/
#ifndef _GROUP_H
#define _GROUP_H
#include "osl/rating/feature.h"
#include "osl/rating/range.h"
#include <vector>
#include <boost/ptr_container/ptr_vector.hpp>
namespace osl
{
namespace rating
{
class Group : public boost::ptr_vector<Feature>
{
public:
std::string group_name;
Group(const std::string& name);
Group(Feature *f) : group_name(f->name()) { push_back(f); }
virtual ~Group();
virtual void show(std::ostream&, int name_width, const range_t& range,
const std::vector<double>& weights) const;
virtual int findMatch(const NumEffectState& state, Move m, const RatingEnv& env) const;
void showMinMax(std::ostream& os, int name_width, const range_t& range,
const std::vector<double>& weights) const;
void showAll(std::ostream& os, int name_width, const range_t& range,
const std::vector<double>& weights) const;
void showTopN(std::ostream& os, int name_width, const range_t& range,
const std::vector<double>& weights, int n) const;
void saveResult(const std::string& directory, const range_t& range,
const std::vector<double>& weights) const;
bool load(const std::string& directory, const range_t& range,
std::vector<double>& weights) const;
virtual bool effectiveInCheck() const { return (*this)[0].effectiveInCheck(); }
};
struct TakeBackGroup : public Group
{
TakeBackGroup() : Group("TakeBack")
{
push_back(new TakeBack());
push_back(new TakeBack2());
}
#ifndef MINIMAL
void show(std::ostream& os, int name_width, const range_t& range,
const std::vector<double>& weights) const
{
showAll(os, name_width, range, weights);
}
#endif
int findMatch(const NumEffectState&, Move move, const RatingEnv& env) const
{
const Square to = move.to();
if (! env.history.hasLastMove() || env.history.lastMove().to() != to)
return -1;
if (! env.history.hasLastMove(2) || env.history.lastMove(2).to() != to)
return 0;
return 1;
}
bool effectiveInCheck() const { return true; }
};
struct CheckGroup : public Group
{
CheckGroup() : Group("Check")
{
for (int i=0; i<4; ++i)
for (int p=0; p<8; ++p) // progress8
push_back(new Check(i));
}
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
{
const bool direct = state.isDirectCheck(move);
const bool open = state.isOpenCheck(move);
int index = -1;
if (direct && !open)
index = Check::openLong(state, move);
else if (open)
index = direct + 2;
const int progress8 = env.progress.value()/2;
return index*8 + progress8;
}
bool effectiveInCheck() const { return true; }
};
class SendOffGroup : public Group
{
public:
SendOffGroup() : Group("SendOff")
{
for (int p=0; p<8; ++p) // progress8
push_back(new SendOff(0));
for (int p=0; p<8; ++p) // progress8
push_back(new SendOff(1));
}
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&, Move move, const RatingEnv& env) const
{
if (! env.sendoffs.isMember(move.to()))
return -1;
const int progress8 = env.progress.value()/2;
return (move.capturePtype() != PTYPE_EMPTY)*8 + progress8;
}
};
struct BlockGroup : public Group
{
BlockGroup() : Group("Block")
{
for (int s=0; s<=3; ++s) {
for (int o=0; o<=3; ++o) {
push_back(new Block(s, o));
}
}
}
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& ) const
{
const int index = Block::count(state, move.to(), state.turn())*4
+ Block::count(state, move.to(), alt(state.turn()));
return index;
}
bool effectiveInCheck() const { return true; }
};
struct OpenGroup : public Group
{
OpenGroup() : Group("Open")
{
for (int i=0; i<16; ++i)
push_back(new Open(i));
}
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& ) const
{
const int index = Open::index(state, move);
return index;
}
bool effectiveInCheck() const { return true; }
};
struct ChaseGroup : public Group
{
ChaseGroup();
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;
};
struct KaranariGroup : public Group
{
KaranariGroup();
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&) const;
};
struct ImmediateAddSupportGroup : public Group
{
ImmediateAddSupportGroup();
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
{
const int index = ImmediateAddSupport::index(state, move, env);
if (index < 0)
return index;
const int progress8 = env.progress.value()/2;
return index*8 + progress8;
}
};
struct BadLanceGroup : public Group
{
BadLanceGroup() : Group("BadLance")
{
push_back(new BadLance(false));
push_back(new BadLance(true));
}
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&) const
{
const Square front = Board_Table.nextSquare(move.player(), move.to(), U);
if (! BadLance::basicMatch(state, move, front))
return -1;
const int index = state.hasEffectAt(alt(move.player()), front);
return index;
}
};
struct PawnAttackGroup : public Group
{
PawnAttackGroup() : Group("PawnAttack")
{
for (int p=0; p<8; ++p) // progress8
push_back(new PawnAttack());
}
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;
}
};
}
}
#endif /* _GROUP_H */
// ;;; Local Variables:
// ;;; mode:c++
// ;;; c-basic-offset:2
// ;;; End:
osl::Move
圧縮していない moveの表現 .
Definition basic_type.h:1052
osl::Move::player
Player player() const
Definition basic_type.h:1195
osl::Move::capturePtype
Ptype capturePtype() const
Definition basic_type.h:1180
osl::Move::to
const Square to() const
Definition basic_type.h:1132
osl::NumEffectState
利きを持つ局面
Definition numEffectState.h:34
osl::NumEffectState::isOpenCheck
bool isOpenCheck(Move move) const
Definition numEffectState.cc:1074
osl::NumEffectState::isDirectCheck
bool isDirectCheck(Move move) const
Definition numEffectState.cc:1068
osl::NumEffectState::hasEffectAt
bool hasEffectAt(Square target) const
対象とするマスにあるプレイヤーの利きがあるかどうか.
Definition numEffectState.h:324
osl::SimpleState::turn
Player turn() const
Definition simpleState.h:220
osl::Square
Definition basic_type.h:532
osl::container::MoveStack::hasLastMove
bool hasLastMove(size_t last=1) const
Definition moveStack.h:27
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::BadLance
Definition rating/feature.h:218
osl::rating::BadLance::basicMatch
static bool basicMatch(const NumEffectState &state, Move move, Square front)
Definition rating/feature.h:224
osl::rating::Block
Definition rating/feature.h:86
osl::rating::Block::count
static int count(const NumEffectState &state, Square position, Player player)
Definition rating/feature.h:91
osl::rating::Check
Definition rating/feature.h:57
osl::rating::Check::openLong
static bool openLong(const NumEffectState &state, Move move)
Definition rating/feature.h:61
osl::rating::Feature
Definition rating/feature.h:15
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::saveResult
void saveResult(const std::string &directory, const range_t &range, const std::vector< double > &weights) const
Definition group.cc:33
osl::rating::Group::findMatch
virtual int findMatch(const NumEffectState &state, Move m, const RatingEnv &env) const
Definition group.cc:24
osl::rating::Group::load
bool load(const std::string &directory, const range_t &range, std::vector< double > &weights) const
Definition group.cc:47
osl::rating::Group::Group
Group(Feature *f)
Definition group.h:22
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::showMinMax
void showMinMax(std::ostream &os, int name_width, const range_t &range, const std::vector< double > &weights) const
Definition group.cc:85
osl::rating::Group::effectiveInCheck
virtual bool effectiveInCheck() const
Definition group.h:39
osl::rating::Group::group_name
std::string group_name
Definition group.h:19
osl::rating::Group::show
virtual void show(std::ostream &, int name_width, const range_t &range, const std::vector< double > &weights) const
Definition group.cc:62
osl::rating::Group::Group
Group(const std::string &name)
Definition group.cc:15
osl::rating::Group::~Group
virtual ~Group()
Definition group.cc:20
osl::rating::ImmediateAddSupport::index
static int index(const NumEffectState &state, Move move, const RatingEnv &env)
Definition feature.cc:89
osl::rating::Open
Definition rating/feature.h:120
osl::rating::Open::index
static int index(const NumEffectState &state, Move move)
Definition rating/feature.h:124
osl::rating::PawnAttack
Definition rating/feature.h:241
osl::rating::RatingEnv
Definition ratingEnv.h:16
osl::rating::RatingEnv::history
MoveStack history
Definition ratingEnv.h:18
osl::rating::RatingEnv::sendoffs
Square8 sendoffs
Definition ratingEnv.h:19
osl::rating::RatingEnv::progress
Progress16 progress
Definition ratingEnv.h:22
osl::rating::SendOffGroup::show
void show(std::ostream &os, int name_width, const range_t &range, const std::vector< double > &weights) const
Definition group.h:106
osl::rating::SendOffGroup::findMatch
int findMatch(const NumEffectState &, Move move, const RatingEnv &env) const
Definition group.h:111
osl::rating::SendOffGroup::SendOffGroup
SendOffGroup()
Definition group.h:99
osl::rating::SendOff
Definition rating/feature.h:75
osl::rating::TakeBack2
Definition rating/feature.h:41
osl::rating::TakeBack
Definition rating/feature.h:28
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_EMPTY
@ PTYPE_EMPTY
Definition basic_type.h:85
osl::Board_Table
const BoardTable Board_Table
Definition tables.cc:95
osl::U
@ U
Definition basic_type.h:314
osl::alt
constexpr Player alt(Player player)
Definition basic_type.h:13
range.h
feature.h
osl::container::Square8::isMember
bool isMember(Square position) const
Definition square8.h:22
osl::rating::BadLanceGroup::findMatch
int findMatch(const NumEffectState &state, Move move, const RatingEnv &) const
Definition group.h:216
osl::rating::BadLanceGroup::BadLanceGroup
BadLanceGroup()
Definition group.h:206
osl::rating::BadLanceGroup::show
void show(std::ostream &os, int name_width, const range_t &range, const std::vector< double > &weights) const
Definition group.h:211
osl::rating::BlockGroup::findMatch
int findMatch(const NumEffectState &state, Move move, const RatingEnv &) const
Definition group.h:135
osl::rating::BlockGroup::BlockGroup
BlockGroup()
Definition group.h:122
osl::rating::BlockGroup::effectiveInCheck
bool effectiveInCheck() const
Definition group.h:141
osl::rating::BlockGroup::show
void show(std::ostream &os, int name_width, const range_t &range, const std::vector< double > &weights) const
Definition group.h:130
osl::rating::ChaseGroup::findMatch
int findMatch(const NumEffectState &state, Move move, const RatingEnv &env) const
Definition group.cc:150
osl::rating::ChaseGroup::ChaseGroup
ChaseGroup()
Definition group.cc:134
osl::rating::ChaseGroup::show
void show(std::ostream &os, int name_width, const range_t &range, const std::vector< double > &weights) const
Definition group.h:167
osl::rating::CheckGroup::findMatch
int findMatch(const NumEffectState &state, Move move, const RatingEnv &env) const
Definition group.h:81
osl::rating::CheckGroup::CheckGroup
CheckGroup()
Definition group.h:70
osl::rating::CheckGroup::effectiveInCheck
bool effectiveInCheck() const
Definition group.h:93
osl::rating::CheckGroup::show
void show(std::ostream &os, int name_width, const range_t &range, const std::vector< double > &weights) const
Definition group.h:76
osl::rating::ImmediateAddSupportGroup::show
void show(std::ostream &os, int name_width, const range_t &range, const std::vector< double > &weights) const
Definition group.h:189
osl::rating::ImmediateAddSupportGroup::ImmediateAddSupportGroup
ImmediateAddSupportGroup()
Definition group.cc:198
osl::rating::ImmediateAddSupportGroup::findMatch
int findMatch(const NumEffectState &state, Move move, const RatingEnv &env) const
Definition group.h:194
osl::rating::KaranariGroup::findMatch
int findMatch(const NumEffectState &state, Move move, const RatingEnv &) const
Definition group.cc:192
osl::rating::KaranariGroup::show
void show(std::ostream &os, int name_width, const range_t &range, const std::vector< double > &weights) const
Definition group.h:178
osl::rating::KaranariGroup::KaranariGroup
KaranariGroup()
Definition group.cc:183
osl::rating::OpenGroup::effectiveInCheck
bool effectiveInCheck() const
Definition group.h:161
osl::rating::OpenGroup::OpenGroup
OpenGroup()
Definition group.h:146
osl::rating::OpenGroup::show
void show(std::ostream &os, int name_width, const range_t &range, const std::vector< double > &weights) const
Definition group.h:151
osl::rating::OpenGroup::findMatch
int findMatch(const NumEffectState &state, Move move, const RatingEnv &) const
Definition group.h:156
osl::rating::PawnAttackGroup::show
void show(std::ostream &os, int name_width, const range_t &range, const std::vector< double > &weights) const
Definition group.h:233
osl::rating::PawnAttackGroup::PawnAttackGroup
PawnAttackGroup()
Definition group.h:228
osl::rating::PawnAttackGroup::findMatch
int findMatch(const NumEffectState &state, Move move, const RatingEnv &env) const
Definition group.h:238
osl::rating::TakeBackGroup::effectiveInCheck
bool effectiveInCheck() const
Definition group.h:65
osl::rating::TakeBackGroup::findMatch
int findMatch(const NumEffectState &, Move move, const RatingEnv &env) const
Definition group.h:56
osl::rating::TakeBackGroup::show
void show(std::ostream &os, int name_width, const range_t &range, const std::vector< double > &weights) const
Definition group.h:50
osl::rating::TakeBackGroup::TakeBackGroup
TakeBackGroup()
Definition group.h:44