king8Group.cc
Go to the documentation of this file.
/* king8Group.cc
*/
#include "osl/rating/group/king8Group.h"
#include <sstream>
osl::rating::AttackKing8Group::AttackKing8Group()
: Group("AttackKing8")
{
for (int attack=0; attack<3; ++attack) {
for (int defense=0; defense<3; ++defense) {
for (int s=PTYPE_PIECE_MIN; s<= PTYPE_MAX; ++s) {
for (int t=PTYPE_PIECE_MIN; t<= PTYPE_MAX; ++t) {
for (int p=0; p<8; ++p) // progress8
push_back(new AttackKing8(static_cast<Ptype>(s), static_cast<Ptype>(t), true, attack, defense));
for (int p=0; p<8; ++p) // progress8
push_back(new AttackKing8(static_cast<Ptype>(s), static_cast<Ptype>(t), false, attack, defense));
}
for (int p=0; p<8; ++p) // progress8
push_back(new AttackKing8(static_cast<Ptype>(s), PTYPE_EMPTY, true, attack, defense));
}
}
}
}
int osl::rating::AttackKing8Group::findMatch(const NumEffectState& state, Move move, const RatingEnv& env) const
{
const Ptype self = move.ptype();
const Square position
= Neighboring8Direct::findNearest(state, move.ptypeO(), move.to(),
state.kingSquare(alt(state.turn())));
if (position.isPieceStand() || position == move.from())
return -1;
if (! move.isDrop() && state.hasEffectByPiece(state.pieceOnBoard(move.from()), position))
return -1;
const Piece p = state.pieceAt(position);
const Ptype target = p.ptype();
const int base = CountEffect2::index(state, position, env)
* (PTYPE_MAX+1 - PTYPE_PIECE_MIN) * ((PTYPE_MAX+1 - PTYPE_PIECE_MIN)*2 +1);
const int self_index = self - PTYPE_PIECE_MIN;
int index = base + self_index*((PTYPE_MAX+1 - PTYPE_PIECE_MIN)*2 +1);
if (!isPiece(target)) {
index += (PTYPE_MAX+1 - PTYPE_PIECE_MIN)*2;
}
else {
index += (target - PTYPE_PIECE_MIN)*2 + (p.owner() != move.player());
}
const int progress8 = env.progress.value()/2;
return index*8 + progress8;
}
osl::rating::DefenseKing8Group::DefenseKing8Group()
: Group("DefenseKing8")
{
for (int danger=0; danger<=4; ++danger) {
for (int s=PTYPE_PIECE_MIN; s<= PTYPE_MAX; ++s) {
for (int p=0; p<8; ++p) // progress8
push_back(new DefenseKing8(static_cast<Ptype>(s), true, danger));
for (int p=0; p<8; ++p) // progress8
push_back(new DefenseKing8(static_cast<Ptype>(s), false, danger));
}
}
}
int osl::rating::DefenseKing8Group::findMatch(const NumEffectState& state, Move move, const RatingEnv& env) const
{
assert(env.attack_count_for_turn == DefenseKing8::count(state));
const int self_index = (move.ptype() - PTYPE_PIECE_MIN)*2;
int index;
if (DefenseKing8::matchDrop(state, move))
index = env.attack_count_for_turn*(PTYPE_MAX+1-PTYPE_PIECE_MIN)*2 + self_index;
else if (DefenseKing8::matchMove(state, move))
index = env.attack_count_for_turn*(PTYPE_MAX+1-PTYPE_PIECE_MIN)*2 + self_index + 1;
else
return -1;
const int progress8 = env.progress.value()/2;
return index*8 + progress8;
}
/* ------------------------------------------------------------------------- */
// ;;; 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::to
const Square to() const
Definition basic_type.h:1132
osl::Move::from
const Square from() const
Definition basic_type.h:1125
osl::Neighboring8Direct::findNearest
static Square findNearest(const NumEffectState &state, PtypeO ptypeo, Square from, Square target)
Definition neighboring8Direct.h:124
osl::NumEffectState
利きを持つ局面
Definition numEffectState.h:34
osl::NumEffectState::hasEffectByPiece
bool hasEffectByPiece(Piece attack, Square target) const
駒attack が target に利きを持つか (旧hasEffectToと統合)
Definition numEffectState.h:450
osl::Piece
駒.
Definition basic_type.h:788
osl::Piece::ptype
Ptype ptype() const
Definition basic_type.h:821
osl::Piece::owner
Player owner() const
Definition basic_type.h:963
osl::SimpleState::pieceOnBoard
const Piece pieceOnBoard(Square sq) const
Definition simpleState.h:170
osl::SimpleState::turn
Player turn() const
Definition simpleState.h:220
osl::SimpleState::kingSquare
Square kingSquare() const
Definition simpleState.h:94
osl::SimpleState::pieceAt
const Piece pieceAt(Square sq) const
Definition simpleState.h:167
osl::Square
Definition basic_type.h:532
osl::Square::isPieceStand
bool isPieceStand() const
Definition basic_type.h:576
osl::progress::ProgressN::value
int value() const
Definition progress.h:22
osl::rating::AttackKing8
Definition std/osl/rating/feature/king8.h:15
osl::rating::DefenseKing8
Definition std/osl/rating/feature/king8.h:47
osl::rating::DefenseKing8::matchDrop
static bool matchDrop(const NumEffectState &state, Move move)
Definition std/osl/rating/feature/king8.h:91
osl::rating::DefenseKing8::matchMove
static bool matchMove(const NumEffectState &state, Move move)
Definition std/osl/rating/feature/king8.h:101
osl::rating::DefenseKing8::count
static int count(const NumEffectState &state)
Definition std/osl/rating/feature/king8.h:57
osl::rating::Group::Group
Group(const std::string &name)
Definition group.cc:15
osl::rating::RatingEnv
Definition ratingEnv.h:16
osl::rating::RatingEnv::attack_count_for_turn
int attack_count_for_turn
Definition ratingEnv.h:21
osl::rating::RatingEnv::progress
Progress16 progress
Definition ratingEnv.h:22
king8Group.h
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_EMPTY
@ PTYPE_EMPTY
Definition basic_type.h:85
osl::isPiece
constexpr bool isPiece(Ptype ptype)
ptypeが空白やEDGEでないかのチェック
Definition basic_type.h:120
osl::alt
constexpr Player alt(Player player)
Definition basic_type.h:13
osl::rating::AttackKing8Group::AttackKing8Group
AttackKing8Group()
Definition king8Group.cc:6
osl::rating::AttackKing8Group::findMatch
int findMatch(const NumEffectState &state, Move m, const RatingEnv &) const
Definition king8Group.cc:25
osl::rating::CountEffect2::index
static int index(const NumEffectState &state, Square position, const RatingEnv &env)
Definition countEffect2.h:43
osl::rating::DefenseKing8Group::findMatch
int findMatch(const NumEffectState &state, Move m, const RatingEnv &) const
Definition king8Group.cc:67
osl::rating::DefenseKing8Group::DefenseKing8Group
DefenseKing8Group()
Definition king8Group.cc:54