All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
eval/ml/pieceStand.h
Go to the documentation of this file.
1 /* pieceStand.h
2  */
3 
4 #ifndef EVAL_ML_PIECESTAND_H
5 #define EVAL_ML_PIECESTAND_H
6 
7 #include "osl/eval/ml/weights.h"
10 #include "osl/ptype.h"
11 #include "osl/misc/carray.h"
15 
16 namespace osl
17 {
18  namespace eval
19  {
20  namespace ml
21  {
22  class PieceStand
23  {
24  static CArray<MultiInt, osl::Piece::SIZE> table;
25  public:
26  enum { DIM = osl::Piece::SIZE };
27  PieceStand() { };
28  static void setUp(const Weights &weights,int stage);
29  static MultiInt eval(const NumEffectState &state);
30  template<Player P>
31  static MultiInt evalWithUpdate(const NumEffectState &state,
32  Move moved, MultiInt last_value)
33  {
34  assert(moved.player()==P);
36  if (moved.isDrop())
37  {
38  const int count =
39  state.countPiecesOnStand(P, moved.ptype()) + 1;
40  const MultiInt value =
41  table[Ptype_Table.getIndexMin(moved.ptype()) + count - 1];
42  if(P==BLACK)
43  return last_value - value;
44  else
45  return last_value + value;
46  }
47  else if (captured != PTYPE_EMPTY)
48  {
49  Ptype ptype = unpromote(captured);
50  const int count = state.countPiecesOnStand(P, ptype);
51  const MultiInt value = table[(Ptype_Table.getIndexMin(ptype) + count - 1)];
52  if(P==BLACK)
53  return last_value + value;
54  else
55  return last_value - value;
56  }
57  else
58  return last_value;
59  }
60  };
61 
63  {
64  static CArray<MultiInt, 21> table;
65  public:
66  enum { DIM = 21 };
68  static void setUp(const Weights &weights,int stage);
69  static MultiInt eval(int black_count, int white_count);
70  };
71 
73  {
75  public:
76  enum { ONE_DIM = 5625, DIM = ONE_DIM * EvalStages};
78  static void setUp(const Weights &weights);
79  static MultiInt eval(const NumEffectState &state,
80  const CArray<bool, 2> &can_check);
81  static MultiInt evalWithUpdate(
82  const NumEffectState &state,
83  Move moved, const MultiInt &last_value,
84  const CArray<bool, 2> &could_check,
85  const CArray<bool, 2> &can_check);
86  private:
87  static MultiInt sumUp(const CArray<int, 6> &indices,
88  const CArray<MultiInt, 5625> &values);
89  static int index(int rook, int bishop, int gold, int silver,
90  int knight, int lance)
91  {
92  return lance +
93  5 * (knight + 5 * (silver + 5 * (gold + 5 * (3 * bishop + rook))));
94  }
95  static CArray<MultiInt, 5625> table;
96  static CArray<MultiInt, 5625> check_table;
97  };
98 
100  {
101  public:
102  enum { ONE_DIM = 44, DIM = ONE_DIM * EvalStages };
104  static void setUp(const Weights &weights);
105  static void eval(const NumEffectState &state, MultiIntPair& out);
106  template<Player P>
107  static void evalWithUpdateBang(
108  const NumEffectState &state,
109  Move moved, MultiIntPair &last_value_and_out);
110  private:
111  static CArray<MultiInt, 44> table;
112  static int index(Player player, Player turn, Ptype ptype, int count)
113  {
114  return Ptype_Table.getIndexMin(ptype) - 18 + count +
115  (turn == player ? 22 : 0);
116  }
117  };
119  {
120  private:
121  static CArray<MultiInt, 360> y_attack_table;
122  static CArray<MultiInt, 360> y_defense_table;
123  static CArray<MultiInt, 9*7*19> y_attack_table_sum;
124  static CArray<MultiInt, 9*7*19> y_defense_table_sum;
125  static int index(Ptype ptype, Player player, Square king, int count)
126  {
127  const int king_y = (player == BLACK ? king.y() : 10 - king.y());
128  return (king_y - 1) * 40 + Ptype_Table.getIndexMin(ptype) + count;
129  }
130  static int index(int i, Player player, Square king, int count)
131  {
132  const int king_y = (player == BLACK ? king.y() : 10 - king.y());
133  return (king_y - 1) * 7*19 + i*19 + count;
134  }
135  static void updateResult(NumEffectState const& state, MultiInt &result,int i, Ptype ptype, CArray<Square,2> const&kings);
136  public:
138  static void setUp(const Weights &weights);
139  static MultiInt eval(const NumEffectState &state);
140  template<Player P>
141  static MultiInt evalWithUpdate(
142  const NumEffectState &state, Move moved,
143  const MultiInt &last_value);
144  };
145 
147  {
148  public:
149  enum { ONE_DIM = 5625, DIM = ONE_DIM * EvalStages};
150  static void setUp(const Weights &weights);
151  template <Player Defense>
152  static bool canCheck(const NumEffectState &state)
153  {
155  const King8Info king(state.Iking8Info(Defense));
156  return (king.dropCandidate() != 0 ||
157  king.hasMoveCandidate<Attack>(state) ||
158  KnightCheck::canCheck<Defense>(state));
159  }
160  };
162  {
163  public:
164  enum { ONE_DIM = 16384, DIM = ONE_DIM * EvalStages };
165  static void setUp(const Weights &weights);
166  static MultiInt eval(const NumEffectState &state);
167  private:
168  static CArray<MultiInt, 16384> table;
169  };
170  }
171  }
172 }
173 #endif // EVAL_ML_PIECESTAND_H
174 // ;;; Local Variables:
175 // ;;; mode:c++
176 // ;;; c-basic-offset:2
177 // ;;; End: