All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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 #include "osl/neighboring8.h"
9 namespace osl
10 {
11  namespace rating
12  {
13  class Karanari : public Feature
14  {
16  public:
17  Karanari(bool b, bool c) : Feature(b ? "Bishop" : "Rook"), bishop(b), can_promote_area(c) {}
18  static bool matchGeneral(const NumEffectState& state, Move move)
19  {
20  if (! (move.isPromotion() && move.capturePtype() == PTYPE_EMPTY
21  && move.from().canPromote(state.turn())))
22  return false;
23  const Square op_king = state.kingSquare(alt(state.turn()));
24  if (! Neighboring8Direct::hasEffect(state, move.oldPtypeO(), move.from(), op_king)
25  && Neighboring8Direct::hasEffect(state, move.ptypeO(), move.to(), op_king))
26  return false;
27  return true;
28  }
29  bool match(const NumEffectState& state, Move move, const RatingEnv&) const
30  {
31  if (! (move.ptype() == (bishop ? PBISHOP : PROOK)
32  && matchGeneral(state, move)))
33  return false;
34  if (can_promote_area)
35  return move.to().canPromote(move.player());
36  const Square my_king = state.kingSquare(state.turn());
37  if (bishop && Neighboring8::isNeighboring8(move.to(), my_king))
38  return false;
39  return true;
40  }
41  static int index(const NumEffectState& state, Move move)
42  {
43  int base;
44  switch (move.ptype()) {
45  case PBISHOP:
46  base = 2;
47  break;
48  case PROOK:
49  base = 0;
50  break;
51  default:
52  return -1;
53  }
54  if (! matchGeneral(state, move))
55  return -1;
56  if (move.to().canPromote(move.player()))
57  return base;
58  const Square my_king = state.kingSquare(state.turn());
59  if (/*bishop*/ base && Neighboring8::isNeighboring8(move.to(), my_king))
60  return -1;
61  return base + 1;
62  }
63  };
64  }
65 }
66 
67 #endif /* _KARANARI_H */
68 // ;;; Local Variables:
69 // ;;; mode:c++
70 // ;;; c-basic-offset:2
71 // ;;; End: