All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
eval/ml/king8.h
Go to the documentation of this file.
1 /* king8.h
2  */
3 
4 #ifndef EVAL_ML_KING8_H
5 #define EVAL_ML_KING8_H
6 
7 #include "osl/eval/ml/weights.h"
9 #include "osl/ptype.h"
10 #include "osl/misc/carray.h"
13 
14 namespace osl
15 {
16  namespace eval
17  {
18  namespace ml
19  {
21  {
22  public:
23  enum { DIM = 32 + 32 + 288 + 288 };
24  static void setUp(const Weights &weights);
25  static int eval(const osl::state::NumEffectState &state);
26  private:
28  {
29  NOT_EMPTY = -1,
30  NO_EFFECT = 0,
34  };
35  static CArray<int, 32> empty_table;
36  static CArray<int, 32> defense_table;
37  static CArray<int, 288> empty_y_table;
38  static CArray<int, 288> defense_y_table;
39  static int index(const Direction dir,
40  EffectState state);
41  static int indexY(Piece king,
42  const Direction dir,
43  EffectState state);
44  static void effectState(const NumEffectState &state,
45  const Player defense,
46  const Direction dir,
47  EffectState &empty,
48  EffectState &/*defense*/);
49  };
50 
51 
53  {
54  public:
55  enum { DIM = 32 };
56  typedef CArray<int, 32> table_t;
58  {
59  NOT_EMPTY = -1,
60  NO_EFFECT = 0,
64  };
65  template <class MakeEffectState>
66  static const CArray<int,2> evalCommon(const osl::state::NumEffectState &state, const table_t&);
67  template <class MakeEffectState>
68  static const CArray<int,2> evalWithUpdateCommon(const osl::state::NumEffectState &new_state, Move last_move,
69  const CArray<int,2>& last_value, const table_t&);
70 
71  template <class MakeEffectState>
72  static std::pair<CArray<int,2>, CArray<int,2> >
73  evalWithUpdateCommon(const NumEffectState &new_state, Move last_move,
74  const CArray<int,2>& last_value_opening, const CArray<int,2>& last_value_ending,
75  const table_t&, const table_t&);
76 
77  struct MakeEffectStateSimple;
78  struct MakeEffectStateDefense;
79  protected:
80  static int index(const Direction dir, EffectState state)
81  {
82  return dir * 4 + state;
83  }
84  };
85  class King8EffectEmptySquareBoth;
86  template <bool Opening>
88  {
90  static table_t table;
91  public:
92  static void setUp(const Weights &weights);
93  static const CArray<int,2> eval(const osl::state::NumEffectState &state);
94  static const CArray<int,2> evalWithUpdate(const osl::state::NumEffectState &new_state, Move last_move,
95  const CArray<int,2>& last_value);
96  };
97 
99  {
100  public:
101  static std::pair<CArray<int,2>, CArray<int,2> >
102  evalWithUpdate(const osl::state::NumEffectState &new_state, Move last_move,
103  const CArray<int,2>& last_value_opening,
104  const CArray<int,2>& last_value_ending);
105  };
107  : public King8EffectEmptySquare<true>
108  {
109  };
111  : public King8EffectEmptySquare<false>
112  {
113  };
114 
116  template <bool Opening>
118  : public King8EffectBase
119  {
121  static CArray<int, 32> table;
122  public:
123  static void setUp(const Weights &weights);
124  static const CArray<int,2> eval(const osl::state::NumEffectState &state);
125  static const CArray<int,2> evalWithUpdate(const osl::state::NumEffectState &new_state, Move last_move,
126  const CArray<int,2>& last_value);
127  };
129  {
130  public:
131  static std::pair<CArray<int,2>, CArray<int,2> >
132  evalWithUpdate(const osl::state::NumEffectState &new_state, Move last_move,
133  const CArray<int,2>& last_value_opening,
134  const CArray<int,2>& last_value_ending);
135  };
136 
138  : public King8EffectDefenseSquare<true>
139  {
140  };
142  : public King8EffectDefenseSquare<false>
143  {
144  };
145 
147  {
148  public:
149  enum { ONE_DIM = 32, DIM = 32 * 5 * 2};
150  private:
151  static CArray<int, ONE_DIM> base_table;
152  static CArray<int, ONE_DIM> u_table;
153  static CArray<int, ONE_DIM> d_table;
154  static CArray<int, ONE_DIM> l_table;
155  static CArray<int, ONE_DIM> r_table;
156  static CArray<int, ONE_DIM> base_defense_piece_table;
157  static CArray<int, ONE_DIM> u_defense_piece_table;
158  static CArray<int, ONE_DIM> d_defense_piece_table;
159  static CArray<int, ONE_DIM> l_defense_piece_table;
160  static CArray<int, ONE_DIM> r_defense_piece_table;
161  public:
163  {
164  NOT_EMPTY = -1,
169  };
170  static void setUp(const Weights &weights);
172  static int eval(const osl::state::NumEffectState &state,
173  PieceMask black_mask, PieceMask white_mask);
174  static void effectState(const NumEffectState &state,
175  const Player defense,
176  const Direction dir,
177  EffectState &empty,
178  EffectState &/*defense*/);
179  static int index(const Direction dir, EffectState state);
180  };
181 
183  {
184  enum { DIM = 10 };
185  typedef CArray<MultiInt, 10> table_t;
186  static const MultiIntPair eval(const NumEffectState &state,
187  const table_t& table);
188  template <osl::Player P>
189  static int index(Square king, int diff);
190  template <osl::Player P>
191  static bool isBlocked(const NumEffectState &state,
192  int diff);
193 #if 0
194  static std::pair<CArray<int,2>,CArray<int,2> >
195  evalWithUpdate(const NumEffectState &new_state, Move last_move,
196  const CArray<int,2>& last_value_o,
197  const CArray<int,2>& last_value_e,
198  const table_t& table_o, const table_t& table_e);
199 #endif
200  };
201  class KingXBlockedBoth;
202 
204  {
205  friend class KingXBlockedBoth;
206  friend class KingXBlockedYBase;
207  public:
208  static void setUp(const Weights &weights,int stage);
210  {
211  return KingXBlockedBase::eval(state, table);
212  }
213  private:
214  static table_t table;
215  };
216 
217  class KingXBlockedYBase// : public KingXBlockedBase
218  {
219  public:
220  enum { DIM = 90 };
221  typedef CArray<MultiInt, 90> table_t;
222  static const MultiIntPair eval(const NumEffectState &state,
223  const table_t& table);
224  static void
225  evalWithUpdateBang(const NumEffectState &state, Move laste_move,
226  MultiIntPair &last_values_and_out);
227  template <osl::Player P>
228  static int index(Square king, int diff);
229  private:
230  template <int Sign>
231  static void adjust(int index, int index_y, MultiInt &out);
232  };
233 
235  {
236  friend class KingXBlockedBoth;
237  friend class KingXBlockedYBase;
238  public:
239  static void setUp(const Weights &weights,int stage);
240  static const MultiIntPair eval(const NumEffectState &state)
241  {
242  return KingXBlockedYBase::eval(state, table);
243  }
244  private:
245  static table_t table;
246  };
247 
249  {
250  public:
251  static void
252  evalWithUpdateBang(const NumEffectState &new_state, Move last_move,
253  MultiIntPair& last_values_and_out);
254  };
255 
257  {
258  friend class KingXBlockedYBase;
259  public:
260  enum { ONE_DIM = 5, DIM = ONE_DIM * EvalStages };
261  static void setUp(const Weights &weights);
262  static MultiIntPair eval(const NumEffectState &state);
263  private:
264  static CArray<MultiInt, ONE_DIM> table;
265  static int index(const Square king)
266  {
267  const int x = king.x();
268  return (x > 5 ? 9 - x : x - 1);;
269  }
270  template <Player P>
271  static int indexY(const Square king)
272  {
273  const int x = king.x();
274  const int y = (P == BLACK ? king.y() : 10 - king.y());
275  return (y - 1) * 5 + (x > 5 ? 9 - x : x - 1);
276  }
277  template <int Sign>
278  static void adjust(int index, int index_y, MultiInt &out);
279  };
280 
282  {
283  friend class KingXBlockedYBase;
284  friend class KingXBothBlocked;
285  public:
286  enum { ONE_DIM = 5 * 9, DIM = ONE_DIM * EvalStages };
287  static void setUp(const Weights &weights);
288  private:
289  static CArray<MultiInt, ONE_DIM> table;
290  };
291 
293  {
294  friend class KingXBlocked3Y;
295  public:
296  enum { ONE_DIM = 80, DIM = ONE_DIM * EvalStages };
297  static MultiInt eval(const NumEffectState &state);
298  static void setUp(const Weights &weights);
299  private:
300  template <int Sign>
301  static void adjust(int index_y, MultiInt &result)
302  {
303  if(Sign>0)
304  result += y_table[index_y];
305  else
306  result -= y_table[index_y];
307  }
308  template <Player P>
309  static int index(const Square king, bool is_l,
310  bool u_blocked, bool opp_u_blocked, bool opp_blocked)
311  {
312  int x = king.x();
313  if (x >= 6)
314  {
315  x = 10 - x;
316  if (P == BLACK)
317  {
318  is_l = !is_l;
319  }
320  }
321  else if (P == WHITE && x <= 4)
322  {
323  is_l = !is_l;
324  }
325  return x - 1 + 5 * ((is_l ? 1 : 0) + 2 * ((u_blocked ? 1 : 0) + 2 * ((opp_u_blocked ? 1 : 0) +2 * (opp_blocked ? 1 : 0))));
326  }
327  template <Player P>
328  static int indexY(const Square king, bool is_l,
329  bool u_blocked, bool opp_u_blocked,
330  bool opp_blocked)
331  {
332  int x = king.x();
333  const int y = (P == BLACK ? king.y() : 10 - king.y());
334  if (x >= 6)
335  {
336  x = 10 - x;
337  if (P == BLACK)
338  {
339  is_l = !is_l;
340  }
341  }
342  else if (P == WHITE && x <= 4)
343  {
344  is_l = !is_l;
345  }
346  return x - 1 + 5 * (y - 1 + 9 * ((is_l ? 1 : 0) + 2 * ((u_blocked ? 1 : 0) + 2 * ((opp_u_blocked ? 1 : 0) + 2 * (opp_blocked ? 1 : 0)))));
347  }
348  static CArray<MultiInt, 80> table;
349  static CArray<MultiInt, 720> y_table;
350  };
351 
353  {
354  public:
355  enum { ONE_DIM = 720, DIM = ONE_DIM * EvalStages };
356  static void setUp(const Weights &weights);
357  };
358 
360  {
361  public:
362  enum { DIM = 4 };
363  static void setUp(const Weights &weights,int stage);
364  static MultiInt eval(const osl::state::NumEffectState &state);
365  static int index(Square king, Square target);
366  template <osl::Player Defense>
367  static MultiInt evalOne(const NumEffectState &state);
368  private:
369  static CArray<MultiInt, 4> table;
370  };
371  }
372  }
373 }
374 
375 #endif // EVAL_ML_KING8_H
376 // ;;; Local Variables:
377 // ;;; mode:c++
378 // ;;; c-basic-offset:2
379 // ;;; End: