karanari.h
Go to the documentation of this file.
/* karanari.h
*/
#ifndef _KARANARI_H
#define _KARANARI_H
#include "osl/rating/feature.h"
#include "osl/effect_util/neighboring8Direct.h"
namespace osl
{
namespace rating
{
class Karanari : public Feature
{
bool bishop, can_promote_area;
public:
Karanari(bool b, bool c) : Feature(b ? "Bishop" : "Rook"), bishop(b), can_promote_area(c) {}
static bool matchGeneral(const NumEffectState& state, Move move)
{
if (! (move.isPromotion() && move.capturePtype() == PTYPE_EMPTY
&& move.from().canPromote(state.turn())))
return false;
const Square op_king = state.kingSquare(alt(state.turn()));
if (! Neighboring8Direct::hasEffect(state, move.oldPtypeO(), move.from(), op_king)
&& Neighboring8Direct::hasEffect(state, move.ptypeO(), move.to(), op_king))
return false;
return true;
}
bool match(const NumEffectState& state, Move move, const RatingEnv&) const
{
if (! (move.ptype() == (bishop ? PBISHOP : PROOK)
&& matchGeneral(state, move)))
return false;
if (can_promote_area)
return move.to().canPromote(move.player());
const Square my_king = state.kingSquare(state.turn());
if (bishop && move.to().isNeighboring8(my_king))
return false;
return true;
}
static int index(const NumEffectState& state, Move move)
{
int base;
switch (move.ptype()) {
case PBISHOP:
base = 2;
break;
case PROOK:
base = 0;
break;
default:
return -1;
}
if (! matchGeneral(state, move))
return -1;
if (move.to().canPromote(move.player()))
return base;
const Square my_king = state.kingSquare(state.turn());
if (/*bishop*/ base && move.to().isNeighboring8(my_king))
return -1;
return base + 1;
}
};
}
}
#endif /* _KARANARI_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::isPromotion
bool isPromotion() const
Definition basic_type.h:1147
osl::Move::ptype
Ptype ptype() const
Definition basic_type.h:1155
osl::Move::player
Player player() const
Definition basic_type.h:1195
osl::Move::oldPtypeO
PtypeO oldPtypeO() const
移動前のPtypeO, i.e., 成る手だった場合成る前
Definition basic_type.h:1168
osl::Move::capturePtype
Ptype capturePtype() const
Definition basic_type.h:1180
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::hasEffect
static bool hasEffect(const NumEffectState &state, PtypeO ptypeo, Square from, Square target)
ptypeo の駒がfromからtargetの8近傍に直接の利きを持つか
Definition neighboring8Direct.h:108
osl::NumEffectState
利きを持つ局面
Definition numEffectState.h:34
osl::SimpleState::turn
Player turn() const
Definition simpleState.h:220
osl::SimpleState::kingSquare
Square kingSquare() const
Definition simpleState.h:94
osl::Square
Definition basic_type.h:532
osl::Square::isNeighboring8
bool isNeighboring8(Square to) const
Definition basic_type.cc:202
osl::Square::canPromote
bool canPromote() const
Definition basic_type.h:659
osl::rating::Feature::Feature
Feature(const std::string &name)
Definition rating/feature.h:18
osl::rating::Karanari::index
static int index(const NumEffectState &state, Move move)
Definition karanari.h:40
osl::rating::Karanari::can_promote_area
bool can_promote_area
Definition karanari.h:14
osl::rating::Karanari::matchGeneral
static bool matchGeneral(const NumEffectState &state, Move move)
Definition karanari.h:17
osl::rating::Karanari::match
bool match(const NumEffectState &state, Move move, const RatingEnv &) const
Definition karanari.h:28
osl::rating::Karanari::bishop
bool bishop
Definition karanari.h:14
osl::rating::Karanari::Karanari
Karanari(bool b, bool c)
Definition karanari.h:16
osl::rating::RatingEnv
Definition ratingEnv.h:16
osl::rating
Definition construct.h:18
osl
Definition additionalEffect.h:6
osl::PROOK
@ PROOK
Definition basic_type.h:92
osl::PTYPE_EMPTY
@ PTYPE_EMPTY
Definition basic_type.h:85
osl::PBISHOP
@ PBISHOP
Definition basic_type.h:91
osl::alt
constexpr Player alt(Player player)
Definition basic_type.h:13
neighboring8Direct.h
feature.h