4#ifndef EVAL_ML_KINGTABLE_H
5#define EVAL_ML_KINGTABLE_H
26 return std::abs(position.
x() - king.
x()) * 17 +
27 (owner ==
BLACK ? (king.
y() - position.
y()) :
28 (position.
y() - king.
y())) + 8;
36 same_king ? owner :
alt(owner));
37 return index(state, owner, position, king);
80 const int x = std::abs(pos.
x() - king.
x());
81 const int y = (king.
y() - pos.
y()) *
106 template <Player KingPlayer>
112 template <Player KingPlayer>
116 const int king_y = (KingPlayer ==
BLACK ? king.
y() : 10 - king.
y());
117 const int piece_y = (KingPlayer ==
BLACK ? position.
y() :
119 return (king_y - 1) * 9 * 32 + (piece_y - 1) * 32 +
131 static int index(
int effect,
int piece_count);
142 static int index(
int effect,
int piece_count)
144 return effect + 128 * piece_count;
147 template <Player Attack>
156 int &attack_piece_supported,
159 enum {
DIM = 17 * 128 * 2};
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)
179 static int index(
int effect,
int piece_count)
181 return effect + 128 * piece_count;
188 for (
size_t i = 0; i < weights.
dimension(); ++i)
194 int black_effect,
int black_piece,
195 int white_effect,
int white_piece)
197 return table[
index(black_effect, black_piece)] -
205 static int index(
int effect,
int piece_count)
207 return effect + 128 * piece_count;
214 for (
size_t i = 0; i < weights.
dimension(); ++i)
220 int black_effect,
int black_piece,
221 int white_effect,
int white_piece)
223 return table[
index(black_effect, black_piece)] -
232 static int index(
int king_y,
int effect,
int piece_count)
234 return effect + 128 * piece_count + (king_y - 1) * 128 * 17;
237 enum {
DIM = 17 * 128 * 9};
241 for (
size_t i = 0; i < weights.
dimension(); ++i)
247 int black_effect,
int black_piece,
248 int white_effect,
int white_piece)
252 black_effect, black_piece)] -
254 white_effect, white_piece)];
261 static int index(
int king_y,
int effect,
int piece_count)
263 return effect + 128 * piece_count + (king_y - 1) * 128 * 17;
266 enum {
DIM = 17 * 128 * 9};
270 for (
size_t i = 0; i < weights.
dimension(); ++i)
276 int black_effect,
int black_piece,
277 int white_effect,
int white_piece)
280 black_effect, black_piece)] -
282 white_effect, white_piece)];
289 enum {
DIM = 17 * 128 * 2 * 9};
291 static int index(
int king_y,
int effect,
int piece_count)
293 return effect + 128 * piece_count + (king_y - 1) * 128 * 17;
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)
306 black_attack_effect, black_attack_piece)] -
308 white_attack_effect, white_attack_piece)] +
310 black_defense_effect, black_defense_piece)] -
312 white_defense_effect, white_defense_piece)];
321 static int index(
int effect,
int piece_count,
324 return (effect + 64 * piece_count) * 13 + stand_count;
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)
335 const int black_index =
index(black_attack_effect,
338 const int white_index =
index(white_attack_effect,
341 return table[black_index] -
table[white_index];
349 static int index(
int king_y,
int effect,
int piece_count,
352 return ((effect + 64 * piece_count) * 13 + stand_count) * 9 +
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)
365 black_attack_effect, black_attack_piece,
368 white_attack_effect, white_attack_piece,
370 return table[black_index] -
table[white_index];
378 static int index(
int piece_count,
int supported)
380 return supported * 17 + piece_count;
386 int black_attack_piece,
387 int white_attack_piece,
388 int black_attack_supported_piece,
int white_attack_supported_piece)
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];
402 static int index(
int piece_count,
int supported,
int y)
404 return (supported * 17 + piece_count) * 9 + y - 1;
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)
415 const int black_index =
index(black_attack_piece,
416 black_attack_supported_piece,
418 const int white_index =
index(white_attack_piece,
419 white_attack_supported_piece,
421 return table[black_index] -
table[white_index];
427 template <Player defense>
429 template <Player defense>
437 static int index(
int rel_x,
int rel_y)
439 return (rel_y + 2) * 3 + std::abs(rel_x);
464 template <
bool Opening>
468 enum {
DIM = 5 * 5 * 5 * 9 };
471 template <Player player>
477 return index<BLACK>(king, target);
479 return index<WHITE>(king, target);
481 template <Player Defense>
517 template <Player Defense>
520 template <Player Defense>
523 template <osl::Player Defense>
591 template <Player Defense>
594 template <Player Defense>
598 int rel_y,
int king_x,
int king_y,
int x_diff
600 template <osl::Player Defense>
642 template <Player King, Direction Dir>
652 template <Player King, Direction Dir>
661 const int king_y = (King ==
BLACK ? king_position.
y() :
662 10 - king_position.
y());
664 + (king_y - 1) * 32 * 32 * 3;
666 template <Player King, Direction Dir>
675 const int king_x = (king_position.
x() > 5 ? 10 - king_position.
x() :
678 ((King ==
BLACK && king_position.
x() >= 6) ||
679 (King ==
WHITE && king_position.
x() <= 4)))
685 + (king_x - 1) * 32 * 32 * 3;
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)
694 return table[vertical_index] +
table[horizontal_index] +
695 table[diagonal_index1] +
table[diagonal_index2] +
702 template <Player King>
734 template<Direction Dir>
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;
787 static int index(
int effect1,
int effect2,
int i)
789 assert(0 <= effect1 && effect1 < 32);
790 assert(0 <= effect2 && effect2 < 32);
791 return effect1 + 32 * (effect2 + 32 * i);
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))
801 const int tmp = effect1;
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));
816 static int indexX(
int king_x,
int effect1,
int effect2,
int i){
817 return king_x - 1 + 5 * (effect1 + 32 *
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));
828 static int indexY(
int king_y,
int effect1,
int effect2,
int i){
829 return king_y - 1 + 9 *(effect1 + 32 * (effect2 + 32 * i));
859 static int index(
int effect1,
int effect2,
int i)
861 assert(0 <= effect1 && effect1 < 32);
862 assert(0 <= effect2 && effect2 < 32);
863 return effect1 + 32 * (effect2 + 32 * i);
865 template <Player Defense>
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))
872 const int tmp = effect1;
877 assert(0 <= effect1 && effect1 < 32);
878 assert(0 <= effect2 && effect2 < 32);
879 return king_x - 1 + 5 * (effect1 + 32 * (effect2 + 32 * i));
881 template <Player Defense>
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));
915 static int index(
int piece_count,
bool with_knight,
916 int stand_count,
bool with_knight_on_stand,
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))));
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)
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 +
940 template <osl::Player Attack>
962 template <osl::Player Attack>
979 const int y = king.
y();
982 return (y-1)*9 + king.
x()-1;
987 const int y = rook.
y();
990 return (y-1)*9 + rook.
x()-1;
994 return (silver.
y()-1)*9 + silver.
x()-1;
1001 template <Player KingOwner>
1013 template <Player KingOwner>
const Square square() const
Square kingSquare() const
int y() const
将棋としてのY座標を返す.
bool isOnBoard() const
盤面上を表すかどうかの判定. 1<=x() && x()<=9 && 1<=y() && y()<=9 Squareの内部表現に依存する.
int x() const
将棋としてのX座標を返す.
static int indexSilver(Square silver)
static int evalOne(const NumEffectState &state, int offset)
static int indexRook(Square rook)
static void setUp(const Weights &weights)
static int indexKing(Square king)
static CArray< int, DIM > table
static void setUp(const Weights &weights)
static int evalOne(const NumEffectState &state)
static CArray< int, DIM > table
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)
static void setUp(const Weights &weights)
static int indexY(Square king, int effect1, int effect2, int i)
static int indexX(int king_x, int effect1, int effect2, int i)
static int indexY(int king_y, int effect1, int effect2, int i)
static MultiInt eval(const NumEffectState &state, const CArray< int, 5 > &black, const CArray< int, 5 > &white)
static CArray< MultiInt, 40960 > x_table
static CArray< MultiInt, 73728 > y_table
static CArray< MultiInt, 8192 > table
static MultiInt evalOne(const NumEffectState &state, const CArray< int, 5 > &effects)
static int index(int effect1, int effect2, int i)
static void setUp(const Weights &weights)
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)
static CArray< MultiInt, ONE_DIM > table
static int index(int effect, int piece_count, int stand_count)
static void setUp(const Weights &weights)
static CArray< MultiInt, 21600 > y_table
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)
static int indexY(int piece_count, bool with_knight, int stand_count, bool with_knight_on_stand, int attacked_count, int king_y)
static CArray< MultiInt, 2400 > table
static void setUp(const Weights &weights)
static int eval(const NumEffectState &, int black_effect, int black_piece, int white_effect, int white_piece)
static void setUp(const Weights &weights)
static int index(int effect, int piece_count)
static CArray< int, 17 *128 > table
static void setUp(const Weights &weights)
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)
static int index(int effect, int piece_count)
static CArray< int, DIM/2 > attack_table
static CArray< int, DIM/2 > defense_table
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)
static void setUp(const Weights &weights)
static void setUp(const Weights &weights)
static CArray< MultiInt, 900 > y_table
static CArray< MultiInt, 100 > table
static MultiInt evalOne(const NumEffectState &state, PieceMask king25)
static void setUp(const Weights &weights, int stage)
static CArray< MultiInt, 17 *128 > table
static MultiInt eval(const NumEffectState &, int black_effect, int black_piece, int white_effect, int white_piece)
static int index(int effect, int piece_count)
static void setUp(const Weights &weigths)
static void setUp(const Weights &weigths)
static void setUp(const Weights &weigths)
static void setUp(const Weights &weigths)
static CArray< MultiInt, 3240 > y_table
static CArray< int, 256 > effect_state_table
static CArray< MultiInt, 3000 > x_table
static CArray< MultiInt, 5 *3 *8 *3 > table
static int effectStateIndex3(const NumEffectState &state, Square target)
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
static void evalOne(const NumEffectState &state, MultiInt &out)
static void index(const NumEffectState &state, Square target, int &index_xy, int rel_y, int king_x, int king_y, int x_diff)
static void setUp(const Weights &weigths)
static void setUp(const Weights &weigths)
static EffectState effectState(const NumEffectState &state, Square target)
static void setUp(const Weights &weigths)
static CArray< int, 5 *3 *8 *3 > table
static int evalOne(const NumEffectState &state)
static int eval(const NumEffectState &state)
static int index(const NumEffectState &state, Square king, Square target)
static int index(int piece_count, int supported, int y)
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)
static CArray< MultiInt, ONE_DIM > table
static void setUp(const Weights &weights)
static CArray< MultiInt, ONE_DIM > table
static MultiInt eval(int black_attack_piece, int white_attack_piece, int black_attack_supported_piece, int white_attack_supported_piece)
static int index(int piece_count, int supported)
static void setUp(const Weights &weights)
static void setUp(const Weights &weights)
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)
static int index(int king_y, int effect, int piece_count, int stand_count)
static CArray< MultiInt, ONE_DIM > table
static CArray< int, 17 *128 *9 > table
static void setUp(const Weights &weights)
static int eval(const NumEffectState &state, int black_effect, int black_piece, int white_effect, int white_piece)
static int index(int king_y, int effect, int piece_count)
static void setUp(const Weights &weights, int stage)
static CArray< MultiInt, 17 *128 *9 > table
static MultiInt eval(const NumEffectState &state, int black_effect, int black_piece, int white_effect, int white_piece)
static int index(int king_y, int effect, int piece_count)
static void setUp(const Weights &weights)
static CArray< int, DIM/2 > attack_table
static int index(int king_y, int effect, int piece_count)
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)
static CArray< int, DIM/2 > defense_table
static void countEffectAndPieces(const NumEffectState &state, const Player attack, int &effect, int &piece)
static void setUp(const Weights &weights)
static CArray< int, DIM > table
static int index(int effect, int piece_count)
static int eval(const NumEffectState &state)
static void setUp(const Weights &weigths)
static int index(Square king, Square target)
static int index(Square king, Square target, Player player)
static CArray< int, 1125 > table
static int evalWithUpdate(const NumEffectState &state, osl::Move moved, int last_value)
static int evalOne(const NumEffectState &state)
static const CArray< int, 15 > & weights()
static CArray< int, 15 > table
static void setUp(const Weights &weigths)
static const CArray< int, 15 > & weights()
static CArray< int, 15 > table
static void setUp(const Weights &weigths)
static void setUp(const Weights &weights)
static void setUp(const Weights &weights)
static CArray< MultiInt, 20480 > x_table
static int indexX(Square king, int effect1, int effect2, int i)
static int indexY(Square king, int effect1, int effect2, int i)
static CArray< MultiInt, 36864 > y_table
static void setUp(const Weights &weights)
static int index(int effect1, int effect2, int i)
static CArray< MultiInt, 4096 > table
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)
static int indexY(const Square king_position, PtypeO p1, PtypeO p2)
static CArray< MultiInt, 3072 > table
static void evalOne(const NumEffectState &state, MultiInt &result)
static int indexX(const Square king_position, PtypeO p1, PtypeO p2)
static int index(PtypeO p1, PtypeO p2)
static CArray< MultiInt, 27648 > y_table
static CArray< MultiInt, 15360 > x_table
static void setUp(const Weights &weights)
static void setUp(const Weights &weights)
static CArray< MultiInt, 45 *33 > table
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)
static MultiInt evalOne(const NumEffectState &state)
static CArray< MultiInt, 3240 > rook_bishop_table
static CArray< MultiInt, 3240 > table
static void setUp(const Weights &weights)
static CArray< MultiInt, 3240 > rook_table
static CArray< MultiInt, 3240 > bishop_table
static void setUp(const Weights &weights)
static MultiInt evalWithUpdate(const NumEffectState &state, Move moved, const CArray< PieceMask, 2 > &effected_mask, const MultiInt &last_values)
static CArray< MultiInt, ONE_DIM > table
static int index(const Player player, const Square king, const Ptype ptype, const Square pos)
static int index(const Player player, const Square king, const Piece piece)
static void adjust(int attack, int defense, MultiInt &out)
Player getOwner(PtypeO ptypeO)
unsigned int ptypeOIndex(PtypeO ptypeo)
PtypeO
Player + Ptype [-15, 15] PtypeO の O は Owner の O.
constexpr Player alt(Player player)
PtypeO altIfPiece(PtypeO ptypeO)
Pieceの時にはowner を反転する
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)
static int evalOne(const NumEffectState &state, const CArray< int, 15 > &table)
static void setUpBase(const Weights &weigths, CArray< int, 15 > &table)
static int index(int rel_x, int rel_y)
static MultiInt evalWithUpdate(const NumEffectState &state, Move moved, const MultiInt &last_values)
static table_t attack_table
CArray2d< MultiInt, PTYPE_SIZE, 17 *9 > table_t
static void setUp(const Weights &weights, int stage)
static int index(const NumEffectState &state, Player owner, const Square position, bool same_king)
static int index(const NumEffectState &state, PtypeO ptypeo, const Square position, bool same_king)
static int index(const NumEffectState &state, const Piece piece, bool same_king)
static table_t defense_table
static int index(const NumEffectState &, Player owner, const Square position, Square king)
static int index(const PtypeO ptypeO, const Square position, const Square king)
static CArray< MultiInt, 2592 > table
static void setUp(const Weights &weights)
static MultiInt evalWithUpdate(const NumEffectState &state, Move moved, const MultiInt &last_values)
static void adjust(int black, int white, MultiInt &out)
static int index(const Piece p, const Square king)
int value(size_t index) const