My Project
pinAttack.h
Go to the documentation of this file.
1/* pinAttack.h
2 */
3#ifndef _PINATTACK_H
4#define _PINATTACK_H
5
8
9namespace osl
10{
11 namespace rating
12 {
13 class PinAttack : public Feature
14 {
15 bool attack;
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;
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;
85 }
86 };
87
88 }
89}
90
91#endif /* _PINATTACK_H */
92// ;;; Local Variables:
93// ;;; mode:c++
94// ;;; c-basic-offset:2
95// ;;; End:
圧縮していない moveの表現 .
Definition: basic_type.h:1052
PtypeO ptypeO() const
移動後のPtype, i.e., 成る手だった場合成った後
Definition: basic_type.h:1162
Ptype ptype() const
Definition: basic_type.h:1155
bool isDrop() const
Definition: basic_type.h:1150
const Square to() const
Definition: basic_type.h:1132
const Square from() const
Definition: basic_type.h:1125
利きを持つ局面
int countEffect(Player player, Square target) const
利きの数を数える.
bool hasEffectByPiece(Piece attack, Square target) const
駒attack が target に利きを持つか (旧hasEffectToと統合)
bool hasEffectIf(PtypeO ptypeo, Square attacker, Square target) const
attackerにptypeoの駒がいると仮定した場合にtargetに利きがあるかどうか を stateをupdateしないで確かめる.
駒番号のビットセット.
Definition: pieceMask.h:21
const mask_t getMask(int num) const
Definition: pieceMask.h:59
bool any() const
Definition: pieceMask.h:57
Ptype ptype() const
Definition: basic_type.h:821
const Square square() const
Definition: basic_type.h:832
int getIndex(Ptype) const
Definition: ptypeTable.h:50
const char * getCsaName(Ptype ptype) const
Definition: ptypeTable.h:80
mask_t getMaskLow(Ptype ptype) const
Definition: ptypeTable.h:46
const Piece pieceOnBoard(Square sq) const
Definition: simpleState.h:170
Player turn() const
Definition: simpleState.h:220
const Piece pieceOf(int num) const
Definition: simpleState.h:76
bool match(const NumEffectState &, Move move, const RatingEnv &env) const
Definition: pinAttack.h:79
const std::string & name() const
bool match(const NumEffectState &state, Move move, const RatingEnv &, Piece p) const
Definition: pinAttack.h:23
static int index(const NumEffectState &state, Move move, const RatingEnv &env, bool attack)
Definition: pinAttack.h:55
PinAttack(bool a, Ptype s, Ptype t)
Definition: pinAttack.h:18
static const std::string name(bool attack, Ptype self, Ptype target)
Definition: pinAttack.h:68
bool match(const NumEffectState &state, Move move, const RatingEnv &env) const
Definition: pinAttack.h:31
static int index(const NumEffectState &state, Move move, const RatingEnv &, bool attack, Piece p)
Definition: pinAttack.h:45
Ptype
駒の種類を4ビットでコード化する
Definition: basic_type.h:84
@ PTYPE_PIECE_MIN
Definition: basic_type.h:104
@ PTYPE_MAX
Definition: basic_type.h:105
@ KING
Definition: basic_type.h:93
const PtypeTable Ptype_Table
Definition: tables.cc:97
constexpr Player alt(Player player)
Definition: basic_type.h:13