My Project
pinAttack.h
Go to the documentation of this file.
1 /* pinAttack.h
2  */
3 #ifndef _PINATTACK_H
4 #define _PINATTACK_H
5 
6 #include "osl/rating/feature.h"
7 #include "osl/bits/ptypeTable.h"
8 
9 namespace osl
10 {
11  namespace rating
12  {
13  class PinAttack : public Feature
14  {
15  bool attack;
16  Ptype self, target;
17  public:
18  PinAttack(bool a, Ptype s, Ptype t)
19  : Feature(name(a,s,t)),
20  attack(a), self(s), target(t)
21  {
22  }
23  bool match(const NumEffectState& state, Move move, const RatingEnv&, Piece p) const
24  {
25  if (target != p.ptype())
26  return false;
27  return state.hasEffectIf(move.ptypeO(), move.to(), p.square())
28  && (move.isDrop()
29  || ! state.hasEffectByPiece(state.pieceOnBoard(move.from()), p.square()));
30  }
31  bool match(const NumEffectState& state, Move move, const RatingEnv& env) const
32  {
33  if (self != move.ptype())
34  return false;
35  if (state.countEffect(alt(state.turn()), move.to(), env.op_pin) > 0)
36  return false;
37  PieceMask pins = (attack ? env.op_pin : env.my_pin);
38  while (pins.any()) { // pin が複数あると不正確?
39  const Piece p = state.pieceOf(pins.takeOneBit());
40  if (match(state, move, env, p))
41  return true;
42  }
43  return false;
44  }
45  static int index(const NumEffectState& state, Move move, const RatingEnv&, bool attack, Piece p)
46  {
47  if (! (state.hasEffectIf(move.ptypeO(), move.to(), p.square())
48  && (move.isDrop()
49  || ! state.hasEffectByPiece(state.pieceOnBoard(move.from()), p.square()))))
50  return -1;
51  int index = (move.ptype() - PTYPE_PIECE_MIN) * (PTYPE_MAX+1 - PTYPE_PIECE_MIN) + p.ptype() - PTYPE_PIECE_MIN;
52  index *= 2;
53  return attack ? index : index + 1;
54  }
55  static int index(const NumEffectState& state, Move move, const RatingEnv& env, bool attack)
56  {
57  if (state.countEffect(alt(state.turn()), move.to(), env.op_pin) > 0)
58  return -1;
59  PieceMask pins = (attack ? env.op_pin : env.my_pin);
60  while (pins.any()) { // pin が複数あると不正確?
61  const Piece p = state.pieceOf(pins.takeOneBit());
62  const int i = index(state, move, env, attack, p);
63  if (i >= 0)
64  return i;
65  }
66  return -1;
67  }
68  static const std::string name(bool attack, Ptype self, Ptype target)
69  {
70  return std::string(Ptype_Table.getCsaName(self))+">"+Ptype_Table.getCsaName(target)+(attack ? "!" : "=");
71  }
72  };
73 
74  class EscapePin : public Feature
75  {
77  public:
78  explicit EscapePin(Ptype p) : Feature(Ptype_Table.getCsaName(p)), pinned(p) {}
79  bool match(const NumEffectState&, Move move, const RatingEnv& env) const
80  {
81  if (move.ptype() != KING)
82  return false;
84  & Ptype_Table.getMaskLow(pinned)).any();
85  }
86  };
87 
88  }
89 }
90 
91 #endif /* _PINATTACK_H */
92 // ;;; Local Variables:
93 // ;;; mode:c++
94 // ;;; c-basic-offset:2
95 // ;;; End:
osl::rating::PinAttack::target
Ptype target
Definition: pinAttack.h:16
osl::PieceMask::getMask
const mask_t getMask(int num) const
Definition: pieceMask.h:59
osl::PTYPE_PIECE_MIN
@ PTYPE_PIECE_MIN
Definition: basic_type.h:104
osl::rating::PinAttack::attack
bool attack
Definition: pinAttack.h:15
osl::rating::RatingEnv::op_pin
PieceMask op_pin
Definition: ratingEnv.h:20
ptypeTable.h
osl::rating::PinAttack::self
Ptype self
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::alt
constexpr Player alt(Player player)
Definition: basic_type.h:13
osl::rating::PinAttack::PinAttack
PinAttack(bool a, Ptype s, Ptype t)
Definition: pinAttack.h:18
osl::Move
圧縮していない moveの表現 .
Definition: basic_type.h:1052
osl::PtypeTable::getMaskLow
mask_t getMaskLow(Ptype ptype) const
Definition: ptypeTable.h:46
osl::rating::PinAttack
Definition: pinAttack.h:14
osl::rating::Feature::name
const std::string & name() const
Definition: rating/feature.h:24
osl::rating::PinAttack::index
static int index(const NumEffectState &state, Move move, const RatingEnv &env, bool attack)
Definition: pinAttack.h:55
osl::Ptype
Ptype
駒の種類を4ビットでコード化する
Definition: basic_type.h:84
osl::NumEffectState::hasEffectIf
bool hasEffectIf(PtypeO ptypeo, Square attacker, Square target) const
attackerにptypeoの駒がいると仮定した場合にtargetに利きがあるかどうか を stateをupdateしないで確かめる.
Definition: numEffectState.h:465
osl::Ptype_Table
const PtypeTable Ptype_Table
Definition: tables.cc:97
osl::Piece
駒.
Definition: basic_type.h:788
osl::rating::Feature
Definition: rating/feature.h:15
osl::SimpleState::pieceOf
const Piece pieceOf(int num) const
Definition: simpleState.h:76
osl::rating::RatingEnv
Definition: ratingEnv.h:16
osl::PTYPE_MAX
@ PTYPE_MAX
Definition: basic_type.h:105
osl::SimpleState::pieceOnBoard
const Piece pieceOnBoard(Square sq) const
Definition: simpleState.h:170
osl::KING
@ KING
Definition: basic_type.h:93
osl::container::PieceMask64::takeOneBit
int takeOneBit()
Definition: pieceMask64.h:82
osl::rating::EscapePin
Definition: pinAttack.h:75
osl::Move::isDrop
bool isDrop() const
Definition: basic_type.h:1150
osl::Move::ptypeO
PtypeO ptypeO() const
移動後のPtype, i.e., 成る手だった場合成った後
Definition: basic_type.h:1162
osl::NumEffectState::hasEffectByPiece
bool hasEffectByPiece(Piece attack, Square target) const
駒attack が target に利きを持つか (旧hasEffectToと統合)
Definition: numEffectState.h:450
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::match
bool match(const NumEffectState &state, Move move, const RatingEnv &, Piece p) const
Definition: pinAttack.h:23
osl::PtypeTable::getIndex
int getIndex(Ptype) const
Definition: ptypeTable.h:50
osl::rating::RatingEnv::my_pin
PieceMask my_pin
Definition: ratingEnv.h:20
osl::Move::from
const Square from() const
Definition: basic_type.h:1125
osl::NumEffectState
利きを持つ局面
Definition: numEffectState.h:34
osl::rating::EscapePin::pinned
Ptype pinned
Definition: pinAttack.h:76
osl::Piece::square
const Square square() const
Definition: basic_type.h:832
osl::PieceMask::any
bool any() const
Definition: pieceMask.h:57
osl::Piece::ptype
Ptype ptype() const
Definition: basic_type.h:821
osl::rating::EscapePin::EscapePin
EscapePin(Ptype p)
Definition: pinAttack.h:78
osl::Move::ptype
Ptype ptype() const
Definition: basic_type.h:1155
osl::SimpleState::turn
Player turn() const
Definition: simpleState.h:220
osl::rating::EscapePin::match
bool match(const NumEffectState &, Move move, const RatingEnv &env) const
Definition: pinAttack.h:79
osl::Move::to
const Square to() const
Definition: basic_type.h:1132
osl::PtypeTable::getCsaName
const char * getCsaName(Ptype ptype) const
Definition: ptypeTable.h:80
osl::PieceMask
駒番号のビットセット.
Definition: pieceMask.h:21
osl::NumEffectState::countEffect
int countEffect(Player player, Square target) const
利きの数を数える.
Definition: numEffectState.h:266
osl
Definition: additionalEffect.h:6
feature.h