My Project
karanari.h
Go to the documentation of this file.
1/* karanari.h
2 */
3#ifndef _KARANARI_H
4#define _KARANARI_H
5
8namespace osl
9{
10 namespace rating
11 {
12 class Karanari : public Feature
13 {
15 public:
16 Karanari(bool b, bool c) : Feature(b ? "Bishop" : "Rook"), bishop(b), can_promote_area(c) {}
17 static bool matchGeneral(const NumEffectState& state, Move move)
18 {
19 if (! (move.isPromotion() && move.capturePtype() == PTYPE_EMPTY
20 && move.from().canPromote(state.turn())))
21 return false;
22 const Square op_king = state.kingSquare(alt(state.turn()));
23 if (! Neighboring8Direct::hasEffect(state, move.oldPtypeO(), move.from(), op_king)
24 && Neighboring8Direct::hasEffect(state, move.ptypeO(), move.to(), op_king))
25 return false;
26 return true;
27 }
28 bool match(const NumEffectState& state, Move move, const RatingEnv&) const
29 {
30 if (! (move.ptype() == (bishop ? PBISHOP : PROOK)
31 && matchGeneral(state, move)))
32 return false;
34 return move.to().canPromote(move.player());
35 const Square my_king = state.kingSquare(state.turn());
36 if (bishop && move.to().isNeighboring8(my_king))
37 return false;
38 return true;
39 }
40 static int index(const NumEffectState& state, Move move)
41 {
42 int base;
43 switch (move.ptype()) {
44 case PBISHOP:
45 base = 2;
46 break;
47 case PROOK:
48 base = 0;
49 break;
50 default:
51 return -1;
52 }
53 if (! matchGeneral(state, move))
54 return -1;
55 if (move.to().canPromote(move.player()))
56 return base;
57 const Square my_king = state.kingSquare(state.turn());
58 if (/*bishop*/ base && move.to().isNeighboring8(my_king))
59 return -1;
60 return base + 1;
61 }
62 };
63 }
64}
65
66#endif /* _KARANARI_H */
67// ;;; Local Variables:
68// ;;; mode:c++
69// ;;; c-basic-offset:2
70// ;;; End:
圧縮していない moveの表現 .
PtypeO ptypeO() const
移動後のPtype, i.e., 成る手だった場合成った後
bool isPromotion() const
Ptype ptype() const
Player player() const
PtypeO oldPtypeO() const
移動前のPtypeO, i.e., 成る手だった場合成る前
Ptype capturePtype() const
const Square to() const
const Square from() const
利きを持つ局面
Player turn() const
Square kingSquare() const
Definition simpleState.h:94
bool isNeighboring8(Square to) const
bool canPromote() const
Definition basic_type.h:659
static bool hasEffect(const NumEffectState &state, PtypeO ptypeo, Square from, Square target)
ptypeo の駒がfromからtargetの8近傍に直接の利きを持つか
static int index(const NumEffectState &state, Move move)
Definition karanari.h:40
static bool matchGeneral(const NumEffectState &state, Move move)
Definition karanari.h:17
bool match(const NumEffectState &state, Move move, const RatingEnv &) const
Definition karanari.h:28
Karanari(bool b, bool c)
Definition karanari.h:16
@ PROOK
Definition basic_type.h:92
@ PTYPE_EMPTY
Definition basic_type.h:85
@ PBISHOP
Definition basic_type.h:91
constexpr Player alt(Player player)
Definition basic_type.h:13