pinAttack.h
Go to the documentation of this file.
/* pinAttack.h
*/
#ifndef _PINATTACK_H
#define _PINATTACK_H
#include "osl/rating/feature.h"
#include "osl/bits/ptypeTable.h"
namespace osl
{
namespace rating
{
class PinAttack : public Feature
{
bool attack;
Ptype self, target;
public:
PinAttack(bool a, Ptype s, Ptype t)
: Feature(name(a,s,t)),
attack(a), self(s), target(t)
{
}
bool match(const NumEffectState& state, Move move, const RatingEnv&, Piece p) const
{
if (target != p.ptype())
return false;
return state.hasEffectIf(move.ptypeO(), move.to(), p.square())
&& (move.isDrop()
|| ! state.hasEffectByPiece(state.pieceOnBoard(move.from()), p.square()));
}
bool match(const NumEffectState& state, Move move, const RatingEnv& env) const
{
if (self != move.ptype())
return false;
if (state.countEffect(alt(state.turn()), move.to(), env.op_pin) > 0)
return false;
PieceMask pins = (attack ? env.op_pin : env.my_pin);
while (pins.any()) { // pin が複数あると不正確?
const Piece p = state.pieceOf(pins.takeOneBit());
if (match(state, move, env, p))
return true;
}
return false;
}
static int index(const NumEffectState& state, Move move, const RatingEnv&, bool attack, Piece p)
{
if (! (state.hasEffectIf(move.ptypeO(), move.to(), p.square())
&& (move.isDrop()
|| ! state.hasEffectByPiece(state.pieceOnBoard(move.from()), p.square()))))
return -1;
int index = (move.ptype() - PTYPE_PIECE_MIN) * (PTYPE_MAX+1 - PTYPE_PIECE_MIN) + p.ptype() - PTYPE_PIECE_MIN;
index *= 2;
return attack ? index : index + 1;
}
static int index(const NumEffectState& state, Move move, const RatingEnv& env, bool attack)
{
if (state.countEffect(alt(state.turn()), move.to(), env.op_pin) > 0)
return -1;
PieceMask pins = (attack ? env.op_pin : env.my_pin);
while (pins.any()) { // pin が複数あると不正確?
const Piece p = state.pieceOf(pins.takeOneBit());
const int i = index(state, move, env, attack, p);
if (i >= 0)
return i;
}
return -1;
}
static const std::string name(bool attack, Ptype self, Ptype target)
{
return std::string(Ptype_Table.getCsaName(self))+">"+Ptype_Table.getCsaName(target)+(attack ? "!" : "=");
}
};
class EscapePin : public Feature
{
Ptype pinned;
public:
explicit EscapePin(Ptype p) : Feature(Ptype_Table.getCsaName(p)), pinned(p) {}
bool match(const NumEffectState&, Move move, const RatingEnv& env) const
{
if (move.ptype() != KING)
return false;
return (env.my_pin.getMask(Ptype_Table.getIndex(pinned))
& Ptype_Table.getMaskLow(pinned)).any();
}
};
}
}
#endif /* _PINATTACK_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::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::NumEffectState
利きを持つ局面
Definition numEffectState.h:34
osl::NumEffectState::countEffect
int countEffect(Player player, Square target) const
利きの数を数える.
Definition numEffectState.h:266
osl::NumEffectState::hasEffectByPiece
bool hasEffectByPiece(Piece attack, Square target) const
駒attack が target に利きを持つか (旧hasEffectToと統合)
Definition numEffectState.h:450
osl::NumEffectState::hasEffectIf
bool hasEffectIf(PtypeO ptypeo, Square attacker, Square target) const
attackerにptypeoの駒がいると仮定した場合にtargetに利きがあるかどうか を stateをupdateしないで確かめる.
Definition numEffectState.h:465
osl::PieceMask
駒番号のビットセット.
Definition pieceMask.h:21
osl::PieceMask::getMask
const mask_t getMask(int num) const
Definition pieceMask.h:59
osl::PieceMask::any
bool any() const
Definition pieceMask.h:57
osl::Piece
駒.
Definition basic_type.h:788
osl::Piece::ptype
Ptype ptype() const
Definition basic_type.h:821
osl::Piece::square
const Square square() const
Definition basic_type.h:832
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::pieceOf
const Piece pieceOf(int num) const
Definition simpleState.h:76
osl::container::PieceMask64::takeOneBit
int takeOneBit()
Definition pieceMask64.h:82
osl::rating::EscapePin::match
bool match(const NumEffectState &, Move move, const RatingEnv &env) const
Definition pinAttack.h:79
osl::rating::EscapePin::pinned
Ptype pinned
Definition pinAttack.h:76
osl::rating::EscapePin::EscapePin
EscapePin(Ptype p)
Definition pinAttack.h:78
osl::rating::Feature::Feature
Feature(const std::string &name)
Definition rating/feature.h:18
osl::rating::PinAttack::match
bool match(const NumEffectState &state, Move move, const RatingEnv &, Piece p) const
Definition pinAttack.h:23
osl::rating::PinAttack::index
static int index(const NumEffectState &state, Move move, const RatingEnv &env, bool attack)
Definition pinAttack.h:55
osl::rating::PinAttack::PinAttack
PinAttack(bool a, Ptype s, Ptype t)
Definition pinAttack.h:18
osl::rating::PinAttack::self
Ptype self
Definition pinAttack.h:16
osl::rating::PinAttack::name
static const std::string name(bool attack, Ptype self, Ptype target)
Definition pinAttack.h:68
osl::rating::PinAttack::match
bool match(const NumEffectState &state, Move move, const RatingEnv &env) const
Definition pinAttack.h:31
osl::rating::PinAttack::attack
bool attack
Definition pinAttack.h:15
osl::rating::PinAttack::target
Ptype target
Definition pinAttack.h:16
osl::rating::PinAttack::index
static int index(const NumEffectState &state, Move move, const RatingEnv &, bool attack, Piece p)
Definition pinAttack.h:45
osl::rating::RatingEnv
Definition ratingEnv.h:16
osl::rating::RatingEnv::op_pin
PieceMask op_pin
Definition ratingEnv.h:20
osl::rating::RatingEnv::my_pin
PieceMask my_pin
Definition ratingEnv.h:20
osl::rating
Definition construct.h:18
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::KING
@ KING
Definition basic_type.h:93
osl::Ptype_Table
const PtypeTable Ptype_Table
Definition tables.cc:97
osl::alt
constexpr Player alt(Player player)
Definition basic_type.h:13
ptypeTable.h
feature.h