My Project
karanari.h
Go to the documentation of this file.
1 /* karanari.h
2  */
3 #ifndef _KARANARI_H
4 #define _KARANARI_H
5 
6 #include "osl/rating/feature.h"
8 namespace 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;
33  if (can_promote_area)
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:
osl::Square
Definition: basic_type.h:532
osl::alt
constexpr Player alt(Player player)
Definition: basic_type.h:13
neighboring8Direct.h
osl::rating::Karanari::index
static int index(const NumEffectState &state, Move move)
Definition: karanari.h:40
osl::Move
圧縮していない moveの表現 .
Definition: basic_type.h:1052
osl::rating::Feature
Definition: rating/feature.h:15
osl::rating::RatingEnv
Definition: ratingEnv.h:16
osl::Move::oldPtypeO
PtypeO oldPtypeO() const
移動前のPtypeO, i.e., 成る手だった場合成る前
Definition: basic_type.h:1168
osl::rating::Karanari::match
bool match(const NumEffectState &state, Move move, const RatingEnv &) const
Definition: karanari.h:28
osl::Move::capturePtype
Ptype capturePtype() const
Definition: basic_type.h:1180
osl::Move::ptypeO
PtypeO ptypeO() const
移動後のPtype, i.e., 成る手だった場合成った後
Definition: basic_type.h:1162
osl::PBISHOP
@ PBISHOP
Definition: basic_type.h:91
osl::Move::from
const Square from() const
Definition: basic_type.h:1125
osl::NumEffectState
利きを持つ局面
Definition: numEffectState.h:34
osl::rating::Karanari::Karanari
Karanari(bool b, bool c)
Definition: karanari.h:16
osl::Square::canPromote
bool canPromote() const
Definition: basic_type.h:659
osl::SimpleState::kingSquare
Square kingSquare() const
Definition: simpleState.h:94
osl::rating::Karanari::matchGeneral
static bool matchGeneral(const NumEffectState &state, Move move)
Definition: karanari.h:17
osl::Square::isNeighboring8
bool isNeighboring8(Square to) const
Definition: basic_type.cc:202
osl::rating::Karanari::bishop
bool bishop
Definition: karanari.h:14
osl::Move::ptype
Ptype ptype() const
Definition: basic_type.h:1155
osl::rating::Karanari
Definition: karanari.h:13
osl::PTYPE_EMPTY
@ PTYPE_EMPTY
Definition: basic_type.h:85
osl::PROOK
@ PROOK
Definition: basic_type.h:92
osl::SimpleState::turn
Player turn() const
Definition: simpleState.h:220
osl::effect_util::Neighboring8Direct::hasEffect
static bool hasEffect(const NumEffectState &state, PtypeO ptypeo, Square from, Square target)
ptypeo の駒がfromからtargetの8近傍に直接の利きを持つか
Definition: neighboring8Direct.h:108
osl::Move::to
const Square to() const
Definition: basic_type.h:1132
osl::Move::isPromotion
bool isPromotion() const
Definition: basic_type.h:1147
osl::Move::player
Player player() const
Definition: basic_type.h:1195
osl
Definition: additionalEffect.h:6
feature.h
osl::rating::Karanari::can_promote_area
bool can_promote_area
Definition: karanari.h:14