My Project
kingTable.h
Go to the documentation of this file.
1/* kingTable.h
2 */
3
4#ifndef EVAL_ML_KINGTABLE_H
5#define EVAL_ML_KINGTABLE_H
6
7#include "osl/eval/weights.h"
8#include "osl/eval/midgame.h"
10#include <cstdlib>
11namespace osl
12{
13 namespace eval
14 {
15 namespace ml
16 {
18 {
21 static int index(const NumEffectState &,
22 Player owner,
23 const Square position,
24 Square king)
25 {
26 return std::abs(position.x() - king.x()) * 17 +
27 (owner == BLACK ? (king.y() - position.y()) :
28 (position.y() - king.y())) + 8;
29 }
30 static int index(const NumEffectState &state,
31 Player owner,
32 const Square position,
33 bool same_king)
34 {
35 const Square king = state.kingSquare(
36 same_king ? owner : alt(owner));
37 return index(state, owner, position, king);
38 }
39 static int index(const NumEffectState &state,
40 PtypeO ptypeo,
41 const Square position,
42 bool same_king)
43 {
44 return index(state, getOwner(ptypeo), position, same_king);
45 }
46 static int index(const NumEffectState &state,
47 const Piece piece,
48 bool same_king)
49 {
50 return index(state, piece.owner(), piece.square(), same_king);
51 }
52 enum { DIM = ((osl::PTYPE_MAX - osl::PTYPE_PIECE_MIN + 1) *
53 (17 * 9)) * 2};
54 enum { TABLE_DIM = DIM / 2};
55 static void setUp(const Weights &weights, int stage);
56 static MultiInt eval(const NumEffectState &state);
57 template<Player P>
58 static MultiInt evalWithUpdate(const NumEffectState &state, Move moved,
59 const MultiInt& last_values);
60
61 };
62
64 {
65 public:
66 enum { ONE_DIM = 4284, DIM = ONE_DIM * EvalStages };
67 static MultiInt eval(const NumEffectState &state);
69 const NumEffectState &state,
70 Move moved,
71 const CArray<PieceMask, 2> &effected_mask,
72 const MultiInt &last_values);
73 static void setUp(const Weights &weights);
74 template <int Sign>
75 static void adjust(int attack, int defense, MultiInt& out);
76 private:
77 static int index(const Player player, const Square king,
78 const Ptype ptype, const Square pos)
79 {
80 const int x = std::abs(pos.x() - king.x());
81 const int y = (king.y() - pos.y()) *
82 (player == osl::BLACK ? 1 : -1) + 8;
83 return (ptype - osl::PTYPE_PIECE_MIN) * 17 * 9 + (x * 17 + y);
84 }
85 static int index(const Player player, const Square king,
86 const Piece piece)
87 {
88 return index(player, king, piece.ptype(), piece.square());
89 }
91 };
92
93 struct PtypeYY
94 {
95 enum { ONE_DIM = 2592, DIM = ONE_DIM * EvalStages};
96 static void setUp(const Weights &weights);
97 static MultiInt eval(const NumEffectState &state);
99 const NumEffectState& state,
100 Move moved,
101 const MultiInt &last_values);
103 template <int Sign>
104 static void adjust(int black, int white, MultiInt &out);
105 private:
106 template <Player KingPlayer>
107 static int index(const Piece p, const Square king)
108 {
109 return index<KingPlayer>(p.ptypeO(), p.square(), king);
110 }
111
112 template <Player KingPlayer>
113 static int index(const PtypeO ptypeO, const Square position,
114 const Square king)
115 {
116 const int king_y = (KingPlayer == BLACK ? king.y() : 10 - king.y());
117 const int piece_y = (KingPlayer == BLACK ? position.y() :
118 10 - position.y());
119 return (king_y - 1) * 9 * 32 + (piece_y - 1) * 32 +
120 (KingPlayer == BLACK ? ptypeO : alt(ptypeO)) - PTYPEO_MIN;
121 }
122 };
123
125 {
126 private:
127 static void countEffectAndPieces(const NumEffectState &state,
128 const Player attack,
129 int &effect,
130 int &piece);
131 static int index(int effect, int piece_count);
132 public:
133 enum { DIM = 17 * 128 };
135 static void setUp(const Weights &weights);
136 static int eval(const NumEffectState &state);
137 };
138
140 {
141 private:
142 static int index(int effect, int piece_count)
143 {
144 return effect + 128 * piece_count;
145 }
146 public:
147 template <Player Attack>
148 static void countEffectAndPiecesBoth(
149 const NumEffectState &state,
150 PieceMask& effect25,
151 PieceMask& effect_supported,
152 int &attack_effect,
153 int &attack_piece,
154 int &defense_effect,
155 int &defence_piece,
156 int &attack_piece_supported,
157 CArray<int, 5> &effect_vertical,
158 CArray<int, 5> &king_vertical);
159 enum { DIM = 17 * 128 * 2};
160 static CArray<int, DIM/2> attack_table;
161 static CArray<int, DIM/2> defense_table;
162 static void setUp(const Weights &weights);
163 static int eval(const NumEffectState &,
164 int black_attack_effect, int black_attack_piece,
165 int white_attack_effect, int white_attack_piece,
166 int black_defense_effect, int black_defense_piece,
167 int white_defense_effect, int white_defense_piece)
168 {
169 return attack_table[index(black_attack_effect, black_attack_piece)] -
170 attack_table[index(white_attack_effect, white_attack_piece)] +
171 defense_table[index(black_defense_effect, black_defense_piece)] -
172 defense_table[index(white_defense_effect, white_defense_piece)];
173 }
174 };
175
177 {
178 private:
179 static int index(int effect, int piece_count)
180 {
181 return effect + 128 * piece_count;
182 }
183 public:
184 enum { DIM = 17 * 128};
186 static void setUp(const Weights &weights)
187 {
188 for (size_t i = 0; i < weights.dimension(); ++i)
189 {
190 table[i] = weights.value(i);
191 }
192 }
193 static int eval(const NumEffectState &,
194 int black_effect, int black_piece,
195 int white_effect, int white_piece)
196 {
197 return table[index(black_effect, black_piece)] -
198 table[index(white_effect, white_piece)];
199 }
200 };
201
203 {
204 private:
205 static int index(int effect, int piece_count)
206 {
207 return effect + 128 * piece_count;
208 }
209 public:
210 enum { DIM = 17 * 128};
212 static void setUp(const Weights &weights,int stage)
213 {
214 for (size_t i = 0; i < weights.dimension(); ++i)
215 {
216 table[i][stage] = weights.value(i);
217 }
218 }
220 int black_effect, int black_piece,
221 int white_effect, int white_piece)
222 {
223 return table[index(black_effect, black_piece)] -
224 table[index(white_effect, white_piece)];
225 }
226 };
227
228
230 {
231 private:
232 static int index(int king_y, int effect, int piece_count)
233 {
234 return effect + 128 * piece_count + (king_y - 1) * 128 * 17;
235 }
236 public:
237 enum { DIM = 17 * 128 * 9};
239 static void setUp(const Weights &weights)
240 {
241 for (size_t i = 0; i < weights.dimension(); ++i)
242 {
243 table[i] = weights.value(i);
244 }
245 }
246 static int eval(const NumEffectState &state,
247 int black_effect, int black_piece,
248 int white_effect, int white_piece)
249 {
250 // ugly hack. -1 is attack. 0 >= is defense
251 return table[index(10 - state.kingSquare<WHITE>().y(),
252 black_effect, black_piece)] -
253 table[index(state.kingSquare<BLACK>().y(),
254 white_effect, white_piece)];
255 }
256 };
257
259 {
260 private:
261 static int index(int king_y, int effect, int piece_count)
262 {
263 return effect + 128 * piece_count + (king_y - 1) * 128 * 17;
264 }
265 public:
266 enum { DIM = 17 * 128 * 9};
268 static void setUp(const Weights &weights,int stage)
269 {
270 for (size_t i = 0; i < weights.dimension(); ++i)
271 {
272 table[i][stage] = weights.value(i);
273 }
274 }
275 static MultiInt eval(const NumEffectState &state,
276 int black_effect, int black_piece,
277 int white_effect, int white_piece)
278 {
279 return table[index(state.kingSquare<BLACK>().y(),
280 black_effect, black_piece)] -
281 table[index(10 - state.kingSquare<WHITE>().y(),
282 white_effect, white_piece)];
283 }
284 };
285
287 {
288 public:
289 enum { DIM = 17 * 128 * 2 * 9};
290 private:
291 static int index(int king_y, int effect, int piece_count)
292 {
293 return effect + 128 * piece_count + (king_y - 1) * 128 * 17;
294 }
295 static CArray<int, DIM/2> attack_table;
296 static CArray<int, DIM/2> defense_table;
297 public:
298 static void setUp(const Weights &weights);
299 static int eval(const NumEffectState &state,
300 int black_attack_effect, int black_attack_piece,
301 int white_attack_effect, int white_attack_piece,
302 int black_defense_effect, int black_defense_piece,
303 int white_defense_effect, int white_defense_piece)
304 {
305 return attack_table[index(10 - state.kingSquare<WHITE>().y(),
306 black_attack_effect, black_attack_piece)] -
308 white_attack_effect, white_attack_piece)] +
310 black_defense_effect, black_defense_piece)] -
311 defense_table[index(10 - state.kingSquare<WHITE>().y(),
312 white_defense_effect, white_defense_piece)];
313 }
314 };
315
317 {
318 public:
319 enum { ONE_DIM = 17 * 13 * 64, DIM = ONE_DIM * EvalStages };
320 private:
321 static int index(int effect, int piece_count,
322 int stand_count)
323 {
324 return (effect + 64 * piece_count) * 13 + stand_count;
325 }
327 public:
328 static void setUp(const Weights &weights);
330 const NumEffectState &,
331 int black_attack_effect, int black_attack_piece,
332 int white_attack_effect, int white_attack_piece,
333 int black_stand_count, int white_stand_count)
334 {
335 const int black_index = index(black_attack_effect,
336 black_attack_piece,
337 black_stand_count);
338 const int white_index = index(white_attack_effect,
339 white_attack_piece,
340 white_stand_count);
341 return table[black_index] - table[white_index];
342 }
343 };
345 {
346 public:
347 enum { ONE_DIM = 17 * 13 * 64 * 9, DIM = ONE_DIM * EvalStages };
348 private:
349 static int index(int king_y, int effect, int piece_count,
350 int stand_count)
351 {
352 return ((effect + 64 * piece_count) * 13 + stand_count) * 9 +
353 (king_y - 1);
354 }
356 public:
357 static void setUp(const Weights &weights);
359 const NumEffectState &state,
360 int black_attack_effect, int black_attack_piece,
361 int white_attack_effect, int white_attack_piece,
362 int black_stand_count, int white_stand_count)
363 {
364 const int black_index = index(10 - state.kingSquare<WHITE>().y(),
365 black_attack_effect, black_attack_piece,
366 black_stand_count);
367 const int white_index = index(state.kingSquare<BLACK>().y(),
368 white_attack_effect, white_attack_piece,
369 white_stand_count);
370 return table[black_index] - table[white_index];
371 }
372 };
374 {
375 public:
376 enum { ONE_DIM = 17 * 17, DIM = ONE_DIM * EvalStages };
377 private:
378 static int index(int piece_count, int supported)
379 {
380 return supported * 17 + piece_count;
381 }
383 public:
384 static void setUp(const Weights &weights);
386 int black_attack_piece,
387 int white_attack_piece,
388 int black_attack_supported_piece, int white_attack_supported_piece)
389 {
390 const int black_index = index(black_attack_piece,
391 black_attack_supported_piece);
392 const int white_index = index(white_attack_piece,
393 white_attack_supported_piece);
394 return table[black_index] - table[white_index];
395 }
396 };
398 {
399 public:
400 enum { ONE_DIM = 17 * 17 * 9, DIM = ONE_DIM * EvalStages };
401 private:
402 static int index(int piece_count, int supported, int y)
403 {
404 return (supported * 17 + piece_count) * 9 + y - 1;
405 }
407 public:
408 static void setUp(const Weights &weights);
410 int black_attack_piece,
411 int white_attack_piece,
412 int black_attack_supported_piece, int white_attack_supported_piece,
413 int black_king_y, int white_king_y)
414 {
415 const int black_index = index(black_attack_piece,
416 black_attack_supported_piece,
417 10 - white_king_y);
418 const int white_index = index(white_attack_piece,
419 white_attack_supported_piece,
420 black_king_y);
421 return table[black_index] - table[white_index];
422 }
423 };
425 {
426 enum { DIM = 3 * 5 };
427 template <Player defense>
428 static int evalOne(const NumEffectState &state, const CArray<int, 15>& table);
429 template <Player defense>
430 static std::pair<int,int> evalOne(const NumEffectState &state, const CArray<int, 15>& opening, const CArray<int, 15>& ending);
431 static std::pair<CArray<int,2>, CArray<int,2> >
432 eval(const NumEffectState &state, const CArray<int, 15>& opening, const CArray<int, 15>& ending);
433 static std::pair<CArray<int,2>, CArray<int,2> >
434 evalWithUpdate(const NumEffectState &state, Move last_move,
435 const CArray<int, 15>& opening, const CArray<int, 15>& ending,
436 const CArray<int,2>& last_opening_value, const CArray<int,2>& last_ending_value);
437 static int index(int rel_x, int rel_y)
438 {
439 return (rel_y + 2) * 3 + std::abs(rel_x);
440 }
441 static void setUpBase(const Weights &weigths, CArray<int, 15>& table);
442 };
443
446 {
448 public:
449 static void setUp(const Weights &weigths) { setUpBase(weigths, table); }
450 static const CArray<int,2> eval(const NumEffectState &state);
451 static const CArray<int, 15>& weights() { return table; }
452 };
453
456 {
458 public:
459 static void setUp(const Weights &weigths) { setUpBase(weigths, table); }
460 static const CArray<int,2> eval(const NumEffectState &state);
461 static const CArray<int, 15>& weights() { return table; }
462 };
463
464 template <bool Opening>
466 {
467 public:
468 enum { DIM = 5 * 5 * 5 * 9 };
469 private:
471 template <Player player>
472 static int index(Square king,
473 Square target);
474 static int index(Square king,
475 Square target, Player player) {
476 if (player == BLACK)
477 return index<BLACK>(king, target);
478 else
479 return index<WHITE>(king, target);
480 }
481 template <Player Defense>
482 static int evalOne(const NumEffectState &state);
483 public:
484 static int evalWithUpdate(
485 const NumEffectState &state, osl::Move moved,
486 int last_value);
487 static void setUp(const Weights &weigths);
488 static int eval(const NumEffectState &state);
489 };
490
492 {
493 };
495 {
496 };
497
510 template <int Stage>
512 {
513 public:
514 enum { DIM = 5 * 3 * STATE_MAX * 3 };
515 private:
517 template <Player Defense>
519 Square target);
520 template <Player Defense>
521 static int index(const NumEffectState &state, Square king,
522 Square target);
523 template <osl::Player Defense>
524 static int evalOne(const NumEffectState &state);
525 public:
526 static void setUp(const Weights &weigths);
527 static int eval(const NumEffectState &state);
528 };
529
531 {
532 };
534 {
535 };
537 {
538 };
539
541 {
542 public:
543 enum { DIM = 5 * 3 * STATE_MAX * 3 };
544 static void setUp(const Weights &weigths);
545 };
547 {
548 public:
549 enum { DIM = 5 * 3 * STATE_MAX * 3 };
550 static void setUp(const Weights &weigths);
551 };
553 {
554 public:
555 enum { DIM = 5 * 3 * STATE_MAX * 3 };
556 static void setUp(const Weights &weigths);
557 };
559 {
560 public:
561 enum { DIM = 5 * 3 * STATE_MAX * 3 };
562 static void setUp(const Weights &weigths);
563 };
564
566 {
583 friend class King25EffectEachXY;
585 private:
591 template <Player Defense>
592 static int effectStateIndex3(const NumEffectState &state,
593 Square target);
594 template <Player Defense>
595 static void index(const NumEffectState &state,
596 Square target,
597 int &index_xy,
598 int rel_y, int king_x, int king_y, int x_diff
599 );
600 template <osl::Player Defense>
601 static void evalOne(const NumEffectState &state,
602 MultiInt& out);
603 public:
604 static void eval(const NumEffectState &state,
605 MultiIntPair &out);
606 static void
607 evalWithUpdate(const NumEffectState &state, Move last_move,
608 MultiIntPair & values);
609 };
610
612 {
613 public:
614 enum { X_DIM = 3000, Y_DIM = 3240, DIM = (X_DIM + Y_DIM) * EvalStages};
615 static void setUp(const Weights &weigths);
616 };
617
619 {
620 public:
621 enum { ONE_DIM = 27000, DIM = ONE_DIM * EvalStages };
622 static void setUp(const Weights &weigths);
623 };
624
626 {
627 friend class King3PiecesXY;
628 public:
629 enum { ONE_DIM = 3072, DIM = ONE_DIM * EvalStages };
630 static void setUp(const Weights &weights);
631 static MultiInt eval(const NumEffectState &state);
632 static MultiInt evalWithUpdate(const NumEffectState &state,
633 Move last_move,
634 MultiInt &last_value);
635 private:
642 template <Player King, Direction Dir>
643 static int index(PtypeO p1, PtypeO p2)
644 {
645 if (King == WHITE)
646 {
647 p1 = altIfPiece(p1);
648 p2 = altIfPiece(p2);
649 }
650 return ptypeOIndex(p1) * 32 + ptypeOIndex(p2) + 1024 * Dir;
651 }
652 template <Player King, Direction Dir>
653 static int indexY(const Square king_position,
654 PtypeO p1, PtypeO p2)
655 {
656 if (King == WHITE)
657 {
658 p1 = altIfPiece(p1);
659 p2 = altIfPiece(p2);
660 }
661 const int king_y = (King == BLACK ? king_position.y() :
662 10 - king_position.y());
663 return ptypeOIndex(p1) * 32 + ptypeOIndex(p2) + 1024 * Dir
664 + (king_y - 1) * 32 * 32 * 3;
665 }
666 template <Player King, Direction Dir>
667 static int indexX(const Square king_position,
668 PtypeO p1, PtypeO p2)
669 {
670 if (King == WHITE)
671 {
672 p1 = altIfPiece(p1);
673 p2 = altIfPiece(p2);
674 }
675 const int king_x = (king_position.x() > 5 ? 10 - king_position.x() :
676 king_position.x());
677 if (Dir == HORIZONTAL &&
678 ((King == BLACK && king_position.x() >= 6) ||
679 (King == WHITE && king_position.x() <= 4)))
680 {
681 PtypeO tmp = p1;
682 p1 = p2; p2 = tmp;
683 }
684 return ptypeOIndex(p1) * 32 + ptypeOIndex(p2) + 1024 * Dir
685 + (king_x - 1) * 32 * 32 * 3;
686 }
687 static MultiInt value(int vertical_index, int horizontal_index,
688 int diagonal_index1, int diagonal_index2,
689 int vertical_index_x, int horizontal_index_x,
690 int diagonal_index1_x, int diagonal_index2_x,
691 int vertical_index_y , int horizontal_index_y,
692 int diagonal_index1_y, int diagonal_index2_y)
693 {
694 return table[vertical_index] + table[horizontal_index] +
695 table[diagonal_index1] + table[diagonal_index2] +
696 x_table[vertical_index_x] + x_table[horizontal_index_x] +
697 x_table[diagonal_index1_x] + x_table[diagonal_index2_x] +
698 y_table[vertical_index_y] + y_table[horizontal_index_y] +
699 y_table[diagonal_index1_y] + y_table[diagonal_index2_y];
700 }
701
702 template <Player King>
703 static void evalOne(const NumEffectState &state,
704 MultiInt &result);
708 };
709
711 {
712 public:
713 enum
714 {
715 X_DIM = 32 * 32 * 3 * 5,
716 Y_DIM = 32 * 32 * 3 * 9,
719 };
720 static void setUp(const Weights &weights);
721 };
722
724 {
727 public:
728 enum { ONE_DIM = 3240, DIM = ONE_DIM * EvalStages };
729 static void setUp(const Weights &weights);
730 static MultiInt eval(const NumEffectState &state);
731 private:
732 template <Player P>
733 static MultiInt evalOne(const NumEffectState &state);
734 template<Direction Dir>
735 static int mobilityDir(Square king,Square target)
736 {
737 if(Dir==L) return king.x()-target.x()-1;
738 else if(Dir==R) return target.x()-king.x()-1;
739 else if(Dir==UL || Dir==U || Dir==UR) return target.y()-king.y()-1;
740 else return king.y()-target.y()-1;
741 }
746 };
747
749 {
750 public:
751 enum { ONE_DIM = 3240, DIM = ONE_DIM * EvalStages };
752 static void setUp(const Weights &weights);
753 };
755 {
756 public:
757 enum { ONE_DIM = 3240, DIM = ONE_DIM * EvalStages };
758 static void setUp(const Weights &weights);
759 };
760
762 {
763 public:
764 enum { ONE_DIM = 2925, DIM = ONE_DIM * EvalStages };
765 static void setUp(const Weights &weights);
766 static MultiInt eval(const NumEffectState &state);
767 private:
768 template <Player P>
769 static MultiInt evalOne(const NumEffectState &state);
771 };
772
774 {
775 friend class King25BothSideX;
776 friend class King25BothSideY;
777 public:
778 enum { ONE_DIM = 8192, DIM = ONE_DIM * EvalStages };
779 static void setUp(const Weights &weights);
780 template<Player P>
781 static MultiInt evalOne(const NumEffectState &state,
782 const CArray<int, 5> &effects);
783 static MultiInt eval(const NumEffectState &state,
784 const CArray<int, 5> &black,
785 const CArray<int, 5> &white);
786 private:
787 static int index(int effect1, int effect2, int i)
788 {
789 assert(0 <= effect1 && effect1 < 32);
790 assert(0 <= effect2 && effect2 < 32);
791 return effect1 + 32 * (effect2 + 32 * i);
792 }
793 template <Player P>
794 static int indexX(Square king, int effect1, int effect2,
795 int i, int j)
796 {
797 const int king_x = (king.x() >= 6 ? 10 - king.x() : king.x());
798 if ((P == BLACK && king.x() > 5) ||
799 (P == WHITE && king.x() < 5))
800 {
801 const int tmp = effect1;
802 effect1 = effect2;
803 effect2 = tmp;
804 const int tmp2 = i;
805 i = 4 - j;
806 j = 4 - tmp2;
807 }
808 if (i == 2)
809 --j;
810 const int combination = (i * 3 + j - 2);
811 assert(0 <= effect1 && effect1 < 32);
812 assert(0 <= effect2 && effect2 < 32);
813 return king_x - 1 + 5 * (effect1 + 32 *
814 (effect2 + 32 * combination));
815 }
816 static int indexX(int king_x,int effect1,int effect2, int i){
817 return king_x - 1 + 5 * (effect1 + 32 *
818 (effect2 + 32 * i));
819 }
820 template <Player P>
821 static int indexY(Square king, int effect1, int effect2, int i)
822 {
823 const int king_y = (P == BLACK ? king.y() : 10 - king.y());
824 assert(0 <= effect1 && effect1 < 32);
825 assert(0 <= effect2 && effect2 < 32);
826 return king_y - 1 + 9 *(effect1 + 32 * (effect2 + 32 * i));
827 }
828 static int indexY(int king_y,int effect1,int effect2, int i){
829 return king_y - 1 + 9 *(effect1 + 32 * (effect2 + 32 * i));
830 }
834 };
836 {
837 public:
838 enum { ONE_DIM = 40960, DIM = ONE_DIM * EvalStages };
839 static void setUp(const Weights &weights);
840 };
842 {
843 public:
844 enum { ONE_DIM = 73728, DIM = ONE_DIM * EvalStages };
845 static void setUp(const Weights &weights);
846 };
847
849 {
850 friend class King25MobilityX;
851 friend class King25MobilityY;
852 public:
853 enum { ONE_DIM = 4096, DIM = ONE_DIM * EvalStages };
854 static void setUp(const Weights &weights);
855 static MultiInt eval(const NumEffectState &state,
856 const CArray<int, 5> &black,
857 const CArray<int, 5> &white);
858 private:
859 static int index(int effect1, int effect2, int i)
860 {
861 assert(0 <= effect1 && effect1 < 32);
862 assert(0 <= effect2 && effect2 < 32);
863 return effect1 + 32 * (effect2 + 32 * i);
864 }
865 template <Player Defense>
866 static int indexX(Square king, int effect1, int effect2, int i)
867 {
868 const int king_x = (king.x() > 5 ? 10 - king.x() : king.x());
869 if ((Defense == BLACK && king.x() > 5) ||
870 (Defense == WHITE && king.x() < 5))
871 {
872 const int tmp = effect1;
873 effect1 = effect2;
874 effect2 = tmp;
875 i = 3 - i;
876 }
877 assert(0 <= effect1 && effect1 < 32);
878 assert(0 <= effect2 && effect2 < 32);
879 return king_x - 1 + 5 * (effect1 + 32 * (effect2 + 32 * i));
880 }
881 template <Player Defense>
882 static int indexY(Square king, int effect1, int effect2, int i)
883 {
884 const int king_y = (Defense == BLACK ? king.y() : 10 - king.y());
885 assert(0 <= effect1 && effect1 < 32);
886 assert(0 <= effect2 && effect2 < 32);
887 return king_y - 1 + 9 * (effect1 + 32 * (effect2 + 32 * i));
888 }
892 };
894 {
895 public:
896 enum { ONE_DIM = 20480, DIM = ONE_DIM * EvalStages };
897 static void setUp(const Weights &weights);
898 };
900 {
901 public:
902 enum { ONE_DIM = 36864, DIM = ONE_DIM * EvalStages };
903 static void setUp(const Weights &weights);
904 };
905
907 {
908 friend class King25Effect3Y;
909 public:
910 enum { ONE_DIM = 2400, DIM = ONE_DIM * EvalStages };
911 static void setUp(const Weights &weights);
912 static MultiInt eval(const NumEffectState &state,
913 const CArray<PieceMask, 2> &king25_mask);
914 private:
915 static int index(int piece_count, bool with_knight,
916 int stand_count, bool with_knight_on_stand,
917 int attacked_count)
918 {
919 assert(piece_count >= 0 && piece_count <= 9);
920 assert(stand_count >= 0 && stand_count <= 9);
921 assert(attacked_count >= 0 && attacked_count <= 5);
922 return (piece_count + 10 *
923 ((with_knight ? 1 : 0) + 2 *
924 (stand_count + 10 * ((with_knight_on_stand ? 1 : 0) +
925 2 * attacked_count))));
926 }
927 static int indexY(int piece_count, bool with_knight,
928 int stand_count, bool with_knight_on_stand,
929 int attacked_count, int king_y)
930 {
931 assert(piece_count >= 0 && piece_count <= 9);
932 assert(stand_count >= 0 && stand_count <= 9);
933 assert(attacked_count >= 0 && attacked_count <= 5);
934 return ((piece_count + 10 *
935 ((with_knight ? 1 : 0) + 2 *
936 (stand_count + 10 * ((with_knight_on_stand ? 1 : 0) +
937 2 * attacked_count))))) * 9 +
938 king_y - 1;
939 }
940 template <osl::Player Attack>
941 static MultiInt evalOne(const NumEffectState &state,
942 PieceMask king25);
945 };
947 {
948 public:
949 enum { ONE_DIM = 21600, DIM = ONE_DIM * EvalStages };
950 static void setUp(const Weights &weights);
951 };
952
954 {
956 public:
957 enum { ONE_DIM = 100, DIM = ONE_DIM * EvalStages };
958 static void setUp(const Weights &weights);
959 static MultiInt eval(const NumEffectState &state,
960 const CArray<PieceMask, 2> &king25);
961 private:
962 template <osl::Player Attack>
963 static MultiInt evalOne(const NumEffectState &state,
964 PieceMask king25);
967 };
969 {
970 public:
971 enum { ONE_DIM = 900, DIM = ONE_DIM * EvalStages };
972 static void setUp(const Weights &weights);
973 };
974
976 {
977 static int indexKing(Square king)
978 {
979 const int y = king.y();
980 if (y >= 3)
981 return -1;
982 return (y-1)*9 + king.x()-1;
983 }
984 static int indexRook(Square rook)
985 {
986 assert(rook.isOnBoard());
987 const int y = rook.y();
988 if (y >= 6)
989 return -1;
990 return (y-1)*9 + rook.x()-1;
991 }
992 static int indexSilver(Square silver)
993 {
994 return (silver.y()-1)*9 + silver.x()-1;
995 }
996 public:
997 enum { BISHOP_ONE_DIM = 18 * 81 * (45*2), DIM = BISHOP_ONE_DIM*3 };
998 static void setUp(const Weights &weights);
999 static int eval(const NumEffectState& state);
1000 private:
1001 template <Player KingOwner>
1002 static int evalOne(const NumEffectState &state, int offset);
1004 };
1005
1007 {
1008 public:
1009 enum { DIM = (8+8+8+8)*3 };
1010 static void setUp(const Weights &weights);
1011 static int eval(const NumEffectState &state);
1012 private:
1013 template <Player KingOwner>
1014 static int evalOne(const NumEffectState &state);
1016 };
1017 }
1018 }
1019}
1020#endif // EVAL_ML_KINGTABLE_H
1021// ;;; Local Variables:
1022// ;;; mode:c++
1023// ;;; c-basic-offset:2
1024// ;;; End:
圧縮していない moveの表現 .
利きを持つ局面
駒番号のビットセット.
Definition pieceMask.h:21
PtypeO ptypeO() const
Definition basic_type.h:824
Ptype ptype() const
Definition basic_type.h:821
const Square square() const
Definition basic_type.h:832
Player owner() const
Definition basic_type.h:963
Square kingSquare() const
Definition simpleState.h:94
int y() const
将棋としてのY座標を返す.
Definition basic_type.h:567
bool isOnBoard() const
盤面上を表すかどうかの判定. 1<=x() && x()<=9 && 1<=y() && y()<=9 Squareの内部表現に依存する.
Definition basic_type.h:583
int x() const
将棋としてのX座標を返す.
Definition basic_type.h:563
static int indexSilver(Square silver)
Definition kingTable.h:992
static int evalOne(const NumEffectState &state, int offset)
static int indexRook(Square rook)
Definition kingTable.h:984
static void setUp(const Weights &weights)
static int indexKing(Square king)
Definition kingTable.h:977
static CArray< int, DIM > table
Definition kingTable.h:1003
static void setUp(const Weights &weights)
static int evalOne(const NumEffectState &state)
static CArray< int, DIM > table
Definition kingTable.h:1015
static void setUp(const Weights &weights)
static void setUp(const Weights &weights)
static int indexX(Square king, int effect1, int effect2, int i, int j)
Definition kingTable.h:794
static void setUp(const Weights &weights)
static int indexY(Square king, int effect1, int effect2, int i)
Definition kingTable.h:821
static int indexX(int king_x, int effect1, int effect2, int i)
Definition kingTable.h:816
static int indexY(int king_y, int effect1, int effect2, int i)
Definition kingTable.h:828
static MultiInt eval(const NumEffectState &state, const CArray< int, 5 > &black, const CArray< int, 5 > &white)
static CArray< MultiInt, 40960 > x_table
Definition kingTable.h:832
static CArray< MultiInt, 73728 > y_table
Definition kingTable.h:833
static CArray< MultiInt, 8192 > table
Definition kingTable.h:831
static MultiInt evalOne(const NumEffectState &state, const CArray< int, 5 > &effects)
static int index(int effect1, int effect2, int i)
Definition kingTable.h:787
static void setUp(const Weights &weights)
Definition kingTable.cc:452
static MultiInt eval(const NumEffectState &, int black_attack_effect, int black_attack_piece, int white_attack_effect, int white_attack_piece, int black_stand_count, int white_stand_count)
Definition kingTable.h:329
static CArray< MultiInt, ONE_DIM > table
Definition kingTable.h:326
static int index(int effect, int piece_count, int stand_count)
Definition kingTable.h:321
static void setUp(const Weights &weights)
static CArray< MultiInt, 21600 > y_table
Definition kingTable.h:944
static MultiInt evalOne(const NumEffectState &state, PieceMask king25)
static int index(int piece_count, bool with_knight, int stand_count, bool with_knight_on_stand, int attacked_count)
Definition kingTable.h:915
static int indexY(int piece_count, bool with_knight, int stand_count, bool with_knight_on_stand, int attacked_count, int king_y)
Definition kingTable.h:927
static CArray< MultiInt, 2400 > table
Definition kingTable.h:943
static void setUp(const Weights &weights)
static int eval(const NumEffectState &, int black_effect, int black_piece, int white_effect, int white_piece)
Definition kingTable.h:193
static void setUp(const Weights &weights)
Definition kingTable.h:186
static int index(int effect, int piece_count)
Definition kingTable.h:179
static CArray< int, 17 *128 > table
Definition kingTable.h:185
static void setUp(const Weights &weights)
Definition kingTable.cc:501
static void countEffectAndPiecesBoth(const NumEffectState &state, PieceMask &effect25, PieceMask &effect_supported, int &attack_effect, int &attack_piece, int &defense_effect, int &defence_piece, int &attack_piece_supported, CArray< int, 5 > &effect_vertical, CArray< int, 5 > &king_vertical)
Definition kingTable.cc:514
static int index(int effect, int piece_count)
Definition kingTable.h:142
static CArray< int, DIM/2 > attack_table
Definition kingTable.h:160
static CArray< int, DIM/2 > defense_table
Definition kingTable.h:161
static int eval(const NumEffectState &, int black_attack_effect, int black_attack_piece, int white_attack_effect, int white_attack_piece, int black_defense_effect, int black_defense_piece, int white_defense_effect, int white_defense_piece)
Definition kingTable.h:163
static void setUp(const Weights &weights)
static void setUp(const Weights &weights)
static CArray< MultiInt, 900 > y_table
Definition kingTable.h:966
static CArray< MultiInt, 100 > table
Definition kingTable.h:965
static MultiInt evalOne(const NumEffectState &state, PieceMask king25)
static void setUp(const Weights &weights, int stage)
Definition kingTable.h:212
static CArray< MultiInt, 17 *128 > table
Definition kingTable.h:211
static MultiInt eval(const NumEffectState &, int black_effect, int black_piece, int white_effect, int white_piece)
Definition kingTable.h:219
static int index(int effect, int piece_count)
Definition kingTable.h:205
static void setUp(const Weights &weigths)
Definition kingTable.cc:889
static void setUp(const Weights &weigths)
Definition kingTable.cc:880
static void setUp(const Weights &weigths)
Definition kingTable.cc:871
static void setUp(const Weights &weigths)
Definition kingTable.cc:862
static CArray< MultiInt, 3240 > y_table
Definition kingTable.h:588
static CArray< int, 256 > effect_state_table
Definition kingTable.h:590
static CArray< MultiInt, 3000 > x_table
Definition kingTable.h:587
static CArray< MultiInt, 5 *3 *8 *3 > table
Definition kingTable.h:586
static int effectStateIndex3(const NumEffectState &state, Square target)
Definition kingTable.cc:955
static void evalWithUpdate(const NumEffectState &state, Move last_move, MultiIntPair &values)
static void eval(const NumEffectState &state, MultiIntPair &out)
static CArray< MultiInt, 27000 > xy_table
Definition kingTable.h:589
static void evalOne(const NumEffectState &state, MultiInt &out)
Definition kingTable.cc:993
static void index(const NumEffectState &state, Square target, int &index_xy, int rel_y, int king_x, int king_y, int x_diff)
Definition kingTable.cc:965
static void setUp(const Weights &weigths)
Definition kingTable.cc:934
static void setUp(const Weights &weigths)
Definition kingTable.cc:897
static EffectState effectState(const NumEffectState &state, Square target)
static void setUp(const Weights &weigths)
Definition kingTable.cc:769
static CArray< int, 5 *3 *8 *3 > table
Definition kingTable.h:516
static int evalOne(const NumEffectState &state)
Definition kingTable.cc:820
static int eval(const NumEffectState &state)
Definition kingTable.cc:845
static int index(const NumEffectState &state, Square king, Square target)
Definition kingTable.cc:795
static int index(int piece_count, int supported, int y)
Definition kingTable.h:402
static MultiInt eval(int black_attack_piece, int white_attack_piece, int black_attack_supported_piece, int white_attack_supported_piece, int black_king_y, int white_king_y)
Definition kingTable.h:409
static CArray< MultiInt, ONE_DIM > table
Definition kingTable.h:406
static void setUp(const Weights &weights)
Definition kingTable.cc:485
static CArray< MultiInt, ONE_DIM > table
Definition kingTable.h:382
static MultiInt eval(int black_attack_piece, int white_attack_piece, int black_attack_supported_piece, int white_attack_supported_piece)
Definition kingTable.h:385
static int index(int piece_count, int supported)
Definition kingTable.h:378
static void setUp(const Weights &weights)
Definition kingTable.cc:476
static void setUp(const Weights &weights)
Definition kingTable.cc:461
static MultiInt eval(const NumEffectState &state, int black_attack_effect, int black_attack_piece, int white_attack_effect, int white_attack_piece, int black_stand_count, int white_stand_count)
Definition kingTable.h:358
static int index(int king_y, int effect, int piece_count, int stand_count)
Definition kingTable.h:349
static CArray< MultiInt, ONE_DIM > table
Definition kingTable.h:355
static CArray< int, 17 *128 *9 > table
Definition kingTable.h:238
static void setUp(const Weights &weights)
Definition kingTable.h:239
static int eval(const NumEffectState &state, int black_effect, int black_piece, int white_effect, int white_piece)
Definition kingTable.h:246
static int index(int king_y, int effect, int piece_count)
Definition kingTable.h:232
static void setUp(const Weights &weights, int stage)
Definition kingTable.h:268
static CArray< MultiInt, 17 *128 *9 > table
Definition kingTable.h:267
static MultiInt eval(const NumEffectState &state, int black_effect, int black_piece, int white_effect, int white_piece)
Definition kingTable.h:275
static int index(int king_y, int effect, int piece_count)
Definition kingTable.h:261
static void setUp(const Weights &weights)
Definition kingTable.cc:609
static CArray< int, DIM/2 > attack_table
Definition kingTable.h:295
static int index(int king_y, int effect, int piece_count)
Definition kingTable.h:291
static int eval(const NumEffectState &state, int black_attack_effect, int black_attack_piece, int white_attack_effect, int white_attack_piece, int black_defense_effect, int black_defense_piece, int white_defense_effect, int white_defense_piece)
Definition kingTable.h:299
static CArray< int, DIM/2 > defense_table
Definition kingTable.h:296
static void countEffectAndPieces(const NumEffectState &state, const Player attack, int &effect, int &piece)
Definition kingTable.cc:404
static void setUp(const Weights &weights)
Definition kingTable.cc:395
static CArray< int, DIM > table
Definition kingTable.h:134
static int index(int effect, int piece_count)
Definition kingTable.cc:432
static int eval(const NumEffectState &state)
Definition kingTable.cc:437
static void setUp(const Weights &weigths)
static int index(Square king, Square target)
static int index(Square king, Square target, Player player)
Definition kingTable.h:474
static CArray< int, 1125 > table
Definition kingTable.h:470
static int evalWithUpdate(const NumEffectState &state, osl::Move moved, int last_value)
static int evalOne(const NumEffectState &state)
static const CArray< int, 15 > & weights()
Definition kingTable.h:461
static void setUp(const Weights &weigths)
Definition kingTable.h:459
static const CArray< int, 15 > & weights()
Definition kingTable.h:451
static void setUp(const Weights &weigths)
Definition kingTable.h:449
static void setUp(const Weights &weights)
static void setUp(const Weights &weights)
static CArray< MultiInt, 20480 > x_table
Definition kingTable.h:890
static int indexX(Square king, int effect1, int effect2, int i)
Definition kingTable.h:866
static int indexY(Square king, int effect1, int effect2, int i)
Definition kingTable.h:882
static CArray< MultiInt, 36864 > y_table
Definition kingTable.h:891
static void setUp(const Weights &weights)
static int index(int effect1, int effect2, int i)
Definition kingTable.h:859
static CArray< MultiInt, 4096 > table
Definition kingTable.h:889
static void setUp(const Weights &weights)
static MultiInt evalWithUpdate(const NumEffectState &state, Move last_move, MultiInt &last_value)
static MultiInt value(int vertical_index, int horizontal_index, int diagonal_index1, int diagonal_index2, int vertical_index_x, int horizontal_index_x, int diagonal_index1_x, int diagonal_index2_x, int vertical_index_y, int horizontal_index_y, int diagonal_index1_y, int diagonal_index2_y)
Definition kingTable.h:687
static int indexY(const Square king_position, PtypeO p1, PtypeO p2)
Definition kingTable.h:653
static CArray< MultiInt, 3072 > table
Definition kingTable.h:705
static void evalOne(const NumEffectState &state, MultiInt &result)
static int indexX(const Square king_position, PtypeO p1, PtypeO p2)
Definition kingTable.h:667
static int index(PtypeO p1, PtypeO p2)
Definition kingTable.h:643
static CArray< MultiInt, 27648 > y_table
Definition kingTable.h:707
static CArray< MultiInt, 15360 > x_table
Definition kingTable.h:706
static void setUp(const Weights &weights)
static void setUp(const Weights &weights)
static CArray< MultiInt, 45 *33 > table
Definition kingTable.h:770
static MultiInt evalOne(const NumEffectState &state)
static void setUp(const Weights &weights)
static void setUp(const Weights &weights)
static int mobilityDir(Square king, Square target)
Definition kingTable.h:735
static MultiInt evalOne(const NumEffectState &state)
static CArray< MultiInt, 3240 > rook_bishop_table
Definition kingTable.h:745
static CArray< MultiInt, 3240 > table
Definition kingTable.h:742
static void setUp(const Weights &weights)
static CArray< MultiInt, 3240 > rook_table
Definition kingTable.h:743
static CArray< MultiInt, 3240 > bishop_table
Definition kingTable.h:744
static void setUp(const Weights &weights)
Definition kingTable.cc:126
static MultiInt evalWithUpdate(const NumEffectState &state, Move moved, const CArray< PieceMask, 2 > &effected_mask, const MultiInt &last_values)
Definition kingTable.cc:179
static CArray< MultiInt, ONE_DIM > table
Definition kingTable.h:90
static int index(const Player player, const Square king, const Ptype ptype, const Square pos)
Definition kingTable.h:77
static int index(const Player player, const Square king, const Piece piece)
Definition kingTable.h:85
static void adjust(int attack, int defense, MultiInt &out)
Definition kingTable.cc:137
Ptype
駒の種類を4ビットでコード化する
Definition basic_type.h:84
@ PTYPE_PIECE_MIN
Definition basic_type.h:104
@ PTYPE_MAX
Definition basic_type.h:105
Player getOwner(PtypeO ptypeO)
Definition basic_type.h:256
unsigned int ptypeOIndex(PtypeO ptypeo)
Definition basic_type.h:205
Player
Definition basic_type.h:8
@ WHITE
Definition basic_type.h:10
@ BLACK
Definition basic_type.h:9
PtypeO
Player + Ptype [-15, 15] PtypeO の O は Owner の O.
Definition basic_type.h:199
@ PTYPEO_MIN
Definition basic_type.h:200
const int EvalStages
Definition midgame.h:12
constexpr Player alt(Player player)
Definition basic_type.h:13
PtypeO altIfPiece(PtypeO ptypeO)
Pieceの時にはowner を反転する
Definition basic_type.h:281
static std::pair< CArray< int, 2 >, CArray< int, 2 > > evalWithUpdate(const NumEffectState &state, Move last_move, const CArray< int, 15 > &opening, const CArray< int, 15 > &ending, const CArray< int, 2 > &last_opening_value, const CArray< int, 2 > &last_ending_value)
Definition kingTable.cc:719
static int evalOne(const NumEffectState &state, const CArray< int, 15 > &table)
Definition kingTable.cc:634
static void setUpBase(const Weights &weigths, CArray< int, 15 > &table)
Definition kingTable.cc:623
static int index(int rel_x, int rel_y)
Definition kingTable.h:437
static MultiInt evalWithUpdate(const NumEffectState &state, Move moved, const MultiInt &last_values)
Definition kingTable.cc:59
CArray2d< MultiInt, PTYPE_SIZE, 17 *9 > table_t
Definition kingTable.h:19
static void setUp(const Weights &weights, int stage)
Definition kingTable.cc:8
static int index(const NumEffectState &state, Player owner, const Square position, bool same_king)
Definition kingTable.h:30
static int index(const NumEffectState &state, PtypeO ptypeo, const Square position, bool same_king)
Definition kingTable.h:39
static int index(const NumEffectState &state, const Piece piece, bool same_king)
Definition kingTable.h:46
static int index(const NumEffectState &, Player owner, const Square position, Square king)
Definition kingTable.h:21
static int index(const PtypeO ptypeO, const Square position, const Square king)
Definition kingTable.h:113
static CArray< MultiInt, 2592 > table
Definition kingTable.h:102
static void setUp(const Weights &weights)
Definition kingTable.cc:310
static MultiInt evalWithUpdate(const NumEffectState &state, Move moved, const MultiInt &last_values)
Definition kingTable.cc:351
static void adjust(int black, int white, MultiInt &out)
Definition kingTable.cc:322
static int index(const Piece p, const Square king)
Definition kingTable.h:107
size_t dimension() const
Definition weights.h:29
int value(size_t index) const
Definition weights.h:27