My Project
core/osl/eval/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/weights.h"
10#include "osl/bits/king8Info.h"
11
12namespace osl
13{
14 namespace eval
15 {
16 namespace ml
17 {
19 {
20 public:
21 enum { DIM = 32 + 32 + 288 + 288 };
22 static void setUp(const Weights &weights);
23 static int eval(const NumEffectState &state);
24 private:
37 static int index(const Direction dir,
38 EffectState state);
39 static int indexY(Piece king,
40 const Direction dir,
41 EffectState state);
42 static void effectState(const NumEffectState &state,
43 const Player defense,
44 const Direction dir,
45 EffectState &empty,
46 EffectState &/*defense*/);
47 };
48
49
51 {
52 public:
53 enum { DIM = 32 };
63 template <class MakeEffectState>
64 static const CArray<int,2> evalCommon(const NumEffectState &state, const table_t&);
65 template <class MakeEffectState>
66 static const CArray<int,2> evalWithUpdateCommon(const NumEffectState &new_state, Move last_move,
67 const CArray<int,2>& last_value, const table_t&);
68
69 template <class MakeEffectState>
70 static std::pair<CArray<int,2>, CArray<int,2> >
71 evalWithUpdateCommon(const NumEffectState &new_state, Move last_move,
72 const CArray<int,2>& last_value_opening, const CArray<int,2>& last_value_ending,
73 const table_t&, const table_t&);
74
77 protected:
78 static int index(const Direction dir, EffectState state)
79 {
80 return dir * 4 + state;
81 }
82 };
83 class King8EffectEmptySquareBoth;
84 template <bool Opening>
86 {
88 static table_t table;
89 public:
90 static void setUp(const Weights &weights);
91 static const CArray<int,2> eval(const NumEffectState &state);
92 static const CArray<int,2> evalWithUpdate(const NumEffectState &new_state, Move last_move,
93 const CArray<int,2>& last_value);
94 };
95
97 {
98 public:
99 static std::pair<CArray<int,2>, CArray<int,2> >
100 evalWithUpdate(const NumEffectState &new_state, Move last_move,
101 const CArray<int,2>& last_value_opening,
102 const CArray<int,2>& last_value_ending);
103 };
105 : public King8EffectEmptySquare<true>
106 {
107 };
109 : public King8EffectEmptySquare<false>
110 {
111 };
112
114 template <bool Opening>
116 : public King8EffectBase
117 {
120 public:
121 static void setUp(const Weights &weights);
122 static const CArray<int,2> eval(const NumEffectState &state);
123 static const CArray<int,2> evalWithUpdate(const NumEffectState &new_state, Move last_move,
124 const CArray<int,2>& last_value);
125 };
127 {
128 public:
129 static std::pair<CArray<int,2>, CArray<int,2> >
130 evalWithUpdate(const NumEffectState &new_state, Move last_move,
131 const CArray<int,2>& last_value_opening,
132 const CArray<int,2>& last_value_ending);
133 };
134
136 : public King8EffectDefenseSquare<true>
137 {
138 };
140 : public King8EffectDefenseSquare<false>
141 {
142 };
143
145 {
146 public:
147 enum { ONE_DIM = 32, DIM = 32 * 5 * 2};
148 private:
159 public:
168 static void setUp(const Weights &weights);
170 static int eval(const NumEffectState &state,
171 PieceMask black_mask, PieceMask white_mask);
172 static void effectState(const NumEffectState &state,
173 const Player defense,
174 const Direction dir,
175 EffectState &empty,
176 EffectState &/*defense*/);
177 static int index(const Direction dir, EffectState state);
178 };
179
181 {
182 enum { DIM = 10 };
184 static const MultiIntPair eval(const NumEffectState &state,
185 const table_t& table);
186 template <osl::Player P>
187 static int index(Square king, int diff);
188 template <osl::Player P>
189 static bool isBlocked(const NumEffectState &state,
190 int diff);
191#if 0
192 static std::pair<CArray<int,2>,CArray<int,2> >
193 evalWithUpdate(const NumEffectState &new_state, Move last_move,
194 const CArray<int,2>& last_value_o,
195 const CArray<int,2>& last_value_e,
196 const table_t& table_o, const table_t& table_e);
197#endif
198 };
199 class KingXBlockedBoth;
200
202 {
203 friend class KingXBlockedBoth;
204 friend class KingXBlockedYBase;
205 public:
206 static void setUp(const Weights &weights,int stage);
207 static MultiIntPair eval(const NumEffectState &state)
208 {
209 return KingXBlockedBase::eval(state, table);
210 }
211 private:
213 };
214
215 class KingXBlockedYBase// : public KingXBlockedBase
216 {
217 public:
218 enum { DIM = 90 };
220 static const MultiIntPair eval(const NumEffectState &state,
221 const table_t& table);
222 static void
223 evalWithUpdateBang(const NumEffectState &state, Move laste_move,
224 MultiIntPair &last_values_and_out);
225 template <osl::Player P>
226 static int index(Square king, int diff);
227 private:
228 template <int Sign>
229 static void adjust(int index, int index_y, MultiInt &out);
230 };
231
233 {
234 friend class KingXBlockedBoth;
235 friend class KingXBlockedYBase;
236 public:
237 static void setUp(const Weights &weights,int stage);
238 static const MultiIntPair eval(const NumEffectState &state)
239 {
240 return KingXBlockedYBase::eval(state, table);
241 }
242 private:
244 };
245
247 {
248 public:
249 static void
250 evalWithUpdateBang(const NumEffectState &new_state, Move last_move,
251 MultiIntPair& last_values_and_out);
252 };
253
255 {
256 friend class KingXBlockedYBase;
257 public:
258 enum { ONE_DIM = 5, DIM = ONE_DIM * EvalStages };
259 static void setUp(const Weights &weights);
260 static MultiIntPair eval(const NumEffectState &state);
261 private:
263 static int index(const Square king)
264 {
265 const int x = king.x();
266 return (x > 5 ? 9 - x : x - 1);;
267 }
268 template <Player P>
269 static int indexY(const Square king)
270 {
271 const int x = king.x();
272 const int y = (P == BLACK ? king.y() : 10 - king.y());
273 return (y - 1) * 5 + (x > 5 ? 9 - x : x - 1);
274 }
275 template <int Sign>
276 static void adjust(int index, int index_y, MultiInt &out);
277 };
278
280 {
281 friend class KingXBlockedYBase;
282 friend class KingXBothBlocked;
283 public:
284 enum { ONE_DIM = 5 * 9, DIM = ONE_DIM * EvalStages };
285 static void setUp(const Weights &weights);
286 private:
288 };
289
291 {
292 friend class KingXBlocked3Y;
293 public:
294 enum { ONE_DIM = 80, DIM = ONE_DIM * EvalStages };
295 static MultiInt eval(const NumEffectState &state);
296 static void setUp(const Weights &weights);
297 private:
298 template <int Sign>
299 static void adjust(int index_y, MultiInt &result)
300 {
301 if(Sign>0)
302 result += y_table[index_y];
303 else
304 result -= y_table[index_y];
305 }
306 template <Player P>
307 static int index(const Square king, bool is_l,
308 bool u_blocked, bool opp_u_blocked, bool opp_blocked)
309 {
310 int x = king.x();
311 if (x >= 6)
312 {
313 x = 10 - x;
314 if (P == BLACK)
315 {
316 is_l = !is_l;
317 }
318 }
319 else if (P == WHITE && x <= 4)
320 {
321 is_l = !is_l;
322 }
323 return x - 1 + 5 * ((is_l ? 1 : 0) + 2 * ((u_blocked ? 1 : 0) + 2 * ((opp_u_blocked ? 1 : 0) +2 * (opp_blocked ? 1 : 0))));
324 }
325 template <Player P>
326 static int indexY(const Square king, bool is_l,
327 bool u_blocked, bool opp_u_blocked,
328 bool opp_blocked)
329 {
330 int x = king.x();
331 const int y = (P == BLACK ? king.y() : 10 - king.y());
332 if (x >= 6)
333 {
334 x = 10 - x;
335 if (P == BLACK)
336 {
337 is_l = !is_l;
338 }
339 }
340 else if (P == WHITE && x <= 4)
341 {
342 is_l = !is_l;
343 }
344 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)))));
345 }
348 };
349
351 {
352 public:
353 enum { ONE_DIM = 720, DIM = ONE_DIM * EvalStages };
354 static void setUp(const Weights &weights);
355 };
356
358 {
359 public:
360 enum { DIM = 4 };
361 static void setUp(const Weights &weights,int stage);
362 static MultiInt eval(const NumEffectState &state);
363 static int index(Square king, Square target);
364 template <osl::Player Defense>
365 static MultiInt evalOne(const NumEffectState &state);
366 private:
368 };
369 }
370 }
371}
372
373#endif // EVAL_ML_KING8_H
374// ;;; Local Variables:
375// ;;; mode:c++
376// ;;; c-basic-offset:2
377// ;;; End:
圧縮していない moveの表現 .
利きを持つ局面
駒番号のビットセット.
Definition pieceMask.h:21
int y() const
将棋としてのY座標を返す.
Definition basic_type.h:567
int x() const
将棋としてのX座標を返す.
Definition basic_type.h:563
static MultiInt evalOne(const NumEffectState &state)
Definition king8.cc:1043
static void setUp(const Weights &weights, int stage)
Definition king8.cc:1027
static CArray< MultiInt, 4 > table
static int index(Square king, Square target)
Definition king8.cc:1036
static CArray< int, ONE_DIM > l_defense_piece_table
static CArray< int, ONE_DIM > d_defense_piece_table
static CArray< int, ONE_DIM > d_table
static CArray< int, ONE_DIM > u_table
static CArray< int, ONE_DIM > r_table
static CArray< int, ONE_DIM > u_defense_piece_table
static CArray< int, ONE_DIM > base_defense_piece_table
static CArray< int, ONE_DIM > r_defense_piece_table
static void setUp(const Weights &weights)
Definition king8.cc:408
static int index(const Direction dir, EffectState state)
Definition king8.cc:481
static CArray< int, ONE_DIM > l_table
static CArray< int, ONE_DIM > base_table
static void effectState(const NumEffectState &state, const Player defense, const Direction dir, EffectState &empty, EffectState &)
Definition king8.cc:436
static const CArray< int, 2 > evalCommon(const NumEffectState &state, const table_t &)
static std::pair< CArray< int, 2 >, CArray< int, 2 > > evalWithUpdateCommon(const NumEffectState &new_state, Move last_move, const CArray< int, 2 > &last_value_opening, const CArray< int, 2 > &last_value_ending, const table_t &, const table_t &)
static int index(const Direction dir, EffectState state)
static const CArray< int, 2 > evalWithUpdateCommon(const NumEffectState &new_state, Move last_move, const CArray< int, 2 > &last_value, const table_t &)
static std::pair< CArray< int, 2 >, CArray< int, 2 > > evalWithUpdate(const NumEffectState &new_state, Move last_move, const CArray< int, 2 > &last_value_opening, const CArray< int, 2 > &last_value_ending)
Definition king8.cc:374
static const CArray< int, 2 > evalWithUpdate(const NumEffectState &new_state, Move last_move, const CArray< int, 2 > &last_value)
Definition king8.cc:364
static void setUp(const Weights &weights)
Definition king8.cc:348
static const CArray< int, 2 > eval(const NumEffectState &state)
Definition king8.cc:358
static std::pair< CArray< int, 2 >, CArray< int, 2 > > evalWithUpdate(const NumEffectState &new_state, Move last_move, const CArray< int, 2 > &last_value_opening, const CArray< int, 2 > &last_value_ending)
Definition king8.cc:336
static const CArray< int, 2 > eval(const NumEffectState &state)
Definition king8.cc:321
static const CArray< int, 2 > evalWithUpdate(const NumEffectState &new_state, Move last_move, const CArray< int, 2 > &last_value)
Definition king8.cc:327
static void setUp(const Weights &weights)
Definition king8.cc:310
static CArray< int, 32 > defense_table
static int indexY(Piece king, const Direction dir, EffectState state)
Definition king8.cc:89
static CArray< int, 288 > empty_y_table
static CArray< int, 32 > empty_table
static void setUp(const Weights &weights)
Definition king8.cc:17
static int index(const Direction dir, EffectState state)
Definition king8.cc:82
static void effectState(const NumEffectState &state, const Player defense, const Direction dir, EffectState &empty, EffectState &)
Definition king8.cc:101
static CArray< int, 288 > defense_y_table
static void setUp(const Weights &weights)
Definition king8.cc:945
static CArray< MultiInt, 80 > table
static CArray< MultiInt, 720 > y_table
static void setUp(const Weights &weights)
Definition king8.cc:936
static void adjust(int index_y, MultiInt &result)
static int indexY(const Square king, bool is_l, bool u_blocked, bool opp_u_blocked, bool opp_blocked)
static int index(const Square king, bool is_l, bool u_blocked, bool opp_u_blocked, bool opp_blocked)
static void evalWithUpdateBang(const NumEffectState &new_state, Move last_move, MultiIntPair &last_values_and_out)
Definition king8.cc:916
static void evalWithUpdateBang(const NumEffectState &state, Move laste_move, MultiIntPair &last_values_and_out)
Definition king8.cc:824
static int index(Square king, int diff)
Definition king8.cc:879
static const MultiIntPair eval(const NumEffectState &state, const table_t &table)
Definition king8.cc:743
static void adjust(int index, int index_y, MultiInt &out)
Definition king8.cc:813
static const MultiIntPair eval(const NumEffectState &state)
static void setUp(const Weights &weights, int stage)
Definition king8.cc:924
static MultiIntPair eval(const NumEffectState &state)
static void setUp(const Weights &weights, int stage)
Definition king8.cc:907
static CArray< MultiInt, ONE_DIM > table
static void setUp(const Weights &weights)
Definition king8.cc:613
static void adjust(int index, int index_y, MultiInt &out)
Definition king8.cc:625
static int indexY(const Square king)
static CArray< MultiInt, ONE_DIM > table
static void setUp(const Weights &weights)
Definition king8.cc:603
static int index(const Square king)
Direction
Definition basic_type.h:310
Player
Definition basic_type.h:8
@ WHITE
Definition basic_type.h:10
@ BLACK
Definition basic_type.h:9
const int EvalStages
Definition midgame.h:12
static bool isBlocked(const NumEffectState &state, int diff)
Definition king8.cc:692
static int index(Square king, int diff)
Definition king8.cc:669
static const MultiIntPair eval(const NumEffectState &state, const table_t &table)
Definition king8.cc:724