4 #ifndef EVAL_ML_MINORPIECE_H 5 #define EVAL_ML_MINORPIECE_H 52 template <Player Owner>
55 assert(Owner == king.
owner());
56 const int king_y = (Owner ==
BLACK ?
58 return std::abs(x - king.
square().
x()) * 9 + king_y - 1;
62 return std::abs(x - king.
x());
64 template <
bool Attack>
67 const int king_x = king.
square().
x();
68 const int target_x = (king_x > 5 ? 10 - king_x : king_x);
69 if (king_x >= 6 || (king.
owner() ==
WHITE && king_x == 5))
71 return (x - 1) * 5 + target_x - 1 + (Attack ? 0 : 45);
75 int attack_index,
int defense_index,
76 int attack_index_y,
int defense_index_y,
77 int attack_index_x,
int defense_index_x)
79 return (attack_table[attack_index] +
80 defense_table[defense_index] +
81 attack_y_table[attack_index_y] +
82 defense_y_table[defense_index_y] +
83 x_table[attack_index_x] +
84 x_table[defense_index_x]);
87 int attack_index,
int defense_index,
88 int attack_index_y,
int defense_index_y,
89 int attack_index_x,
int defense_index_x)
91 return (stand_table[attack_index] +
92 stand_table[defense_index + 9] +
93 y_stand_table[attack_index_y] +
94 y_stand_table[defense_index_y + 81] +
95 x_stand_table[attack_index_x] +
96 x_stand_table[defense_index_x]);
125 const int attack_index = index(kings[1], moved.
to().
x());
126 const int defense_index = index(kings[0], moved.
to().
x());
127 const int attack_index_x =
128 indexX<true>(king_piece[1], moved.
to().
x());
129 const int defense_index_x =
130 indexX<false>(king_piece[0], moved.
to().
x());
132 const int attack_index_y = indexY<altP>(king_piece[1], moved.
to().
x());
133 const int defense_index_y = indexY<P>(king_piece[0], moved.
to().
x());
134 const int index_x = (moved.
to().
x() > 5 ? 10 -
135 moved.
to().
x() : moved.
to().
x());
140 result -= drop_non_drop_table[index_x - 1 + 5];
141 result += drop_non_drop_table[index_x - 1];
143 state_king_relative_table[std::abs(king_bw[
BLACK].x() - moved.
to().
x()) +
146 state_king_relative_table[std::abs(king_bw[
WHITE].x() - moved.
to().
x()) +
151 result -= drop_non_drop_table[index_x - 1];
152 result += drop_non_drop_table[index_x - 1 + 5];
154 state_king_relative_table[std::abs(king_bw[
BLACK].x() - moved.
to().
x()) +
157 state_king_relative_table[std::abs(king_bw[
WHITE].x() - moved.
to().
x()) +
161 state_king_relative_table[std::abs(king_bw[
BLACK].x() -
165 state_king_relative_table[std::abs(king_bw[
WHITE].x() -
172 state_king_relative_table[std::abs(king_bw[
BLACK].x() -
176 state_king_relative_table[std::abs(king_bw[
WHITE].x() -
181 result += drop_non_drop_table[index_x - 1];
182 result -= drop_non_drop_table[index_x - 1 + 5];
184 state_king_relative_table[std::abs(king_bw[
BLACK].x() - moved.
to().
x()) +
187 state_king_relative_table[std::abs(king_bw[
WHITE].x() - moved.
to().
x()) +
192 result += drop_non_drop_table[index_x - 1 + 5];
193 result -= drop_non_drop_table[index_x - 1];
195 state_king_relative_table[std::abs(king_bw[
BLACK].x() - moved.
to().
x()) +
198 state_king_relative_table[std::abs(king_bw[
WHITE].x() - moved.
to().
x()) +
204 result -= value(attack_index, defense_index, attack_index_y,
205 defense_index_y, attack_index_x, defense_index_x);
208 result -= standValue(attack_index, defense_index, attack_index_y,
209 defense_index_y, attack_index_x, defense_index_x);
214 result += value(attack_index, defense_index, attack_index_y,
215 defense_index_y, attack_index_x, defense_index_x);
218 result += standValue(attack_index, defense_index, attack_index_y,
219 defense_index_y, attack_index_x, defense_index_x);
225 const int attack_index = index(kings[1], moved.
to().
x());
226 const int defense_index = index(kings[0], moved.
to().
x());
227 const int attack_index_x =
228 indexX<true>(king_piece[1], moved.
to().
x());
229 const int defense_index_x =
230 indexX<false>(king_piece[0], moved.
to().
x());
231 const int attack_index_y = indexY<altP>(king_piece[1], moved.
to().
x());
232 const int defense_index_y = indexY<P>(king_piece[0], moved.
to().
x());
235 result += value(attack_index, defense_index, attack_index_y,
236 defense_index_y, attack_index_x, defense_index_x);
239 result += standValue(attack_index, defense_index, attack_index_y,
240 defense_index_y, attack_index_x, defense_index_x);
245 result -= value(attack_index, defense_index, attack_index_y,
246 defense_index_y, attack_index_x, defense_index_x);
249 result -= standValue(attack_index, defense_index, attack_index_y,
250 defense_index_y, attack_index_x, defense_index_x);
253 const int index_x = (moved.
to().
x() > 5 ? 10 -
254 moved.
to().
x() : moved.
to().
x());
258 state_king_relative_table[std::abs(king_bw[
BLACK].x() - moved.
to().
x()) +
261 state_king_relative_table[std::abs(king_bw[
WHITE].x() - moved.
to().
x()) +
265 result += drop_non_drop_table[index_x - 1 + 5];
266 result -= drop_non_drop_table[index_x - 1];
268 state_king_relative_table[std::abs(king_bw[
BLACK].x() - moved.
to().
x()) +
271 state_king_relative_table[std::abs(king_bw[
WHITE].x() - moved.
to().
x()) +
276 result += drop_non_drop_table[index_x - 1];
277 result -= drop_non_drop_table[index_x - 1 + 5];
279 state_king_relative_table[std::abs(king_bw[
BLACK].x() - moved.
to().
x()) +
282 state_king_relative_table[std::abs(king_bw[
WHITE].x() - moved.
to().
x()) +
289 state_king_relative_table[std::abs(king_bw[
BLACK].x() - moved.
to().
x()) +
292 state_king_relative_table[std::abs(king_bw[
WHITE].x() - moved.
to().
x()) +
294 if (captured ==
PAWN)
297 state_king_relative_table[std::abs(king_bw[
BLACK].x() - moved.
to().
x()) +
300 state_king_relative_table[std::abs(king_bw[
WHITE].x() - moved.
to().
x()) +
307 result -= drop_non_drop_table[index_x - 1];
308 result += drop_non_drop_table[index_x - 1 + 5];
310 state_king_relative_table[std::abs(king_bw[
BLACK].x() - moved.
to().
x()) +
313 state_king_relative_table[std::abs(king_bw[
WHITE].x() - moved.
to().
x()) +
318 result -= drop_non_drop_table[index_x - 1 + 5];
319 result += drop_non_drop_table[index_x - 1];
321 state_king_relative_table[std::abs(king_bw[
BLACK].x() - moved.
to().
x()) +
324 state_king_relative_table[std::abs(king_bw[
WHITE].x() - moved.
to().
x()) +
332 if (captured ==
PAWN)
334 const int attack_index = index(kings[0], moved.
to().
x());
335 const int defense_index = index(kings[1], moved.
to().
x());
336 const int attack_index_x =
337 indexX<true>(king_piece[0], moved.
to().
x());
338 const int defense_index_x =
339 indexX<false>(king_piece[1], moved.
to().
x());
340 const int attack_index_y = indexY<P>(king_piece[0], moved.
to().
x());
341 const int defense_index_y = indexY<altP>(king_piece[1], moved.
to().
x());
344 result -= value(attack_index, defense_index, attack_index_y,
345 defense_index_y, attack_index_x, defense_index_x);
348 result -= standValue(attack_index, defense_index, attack_index_y,
349 defense_index_y, attack_index_x, defense_index_x);
354 result += value(attack_index, defense_index, attack_index_y,
355 defense_index_y, attack_index_x, defense_index_x);
358 result += standValue(attack_index, defense_index, attack_index_y,
359 defense_index_y, attack_index_x, defense_index_x);
365 (moved.
to().
x() > 5 ? 10 - moved.
to().
x() : moved.
to().
x());
369 state_king_relative_table[std::abs(king_bw[
BLACK].x() -
373 state_king_relative_table[std::abs(king_bw[
WHITE].x() -
378 result += drop_non_drop_table[index_x - 1];
379 result -= drop_non_drop_table[index_x - 1 + 5];
381 state_king_relative_table[std::abs(king_bw[
BLACK].x() -
385 state_king_relative_table[std::abs(king_bw[
WHITE].x() -
391 result += drop_non_drop_table[index_x - 1 + 5];
392 result -= drop_non_drop_table[index_x - 1];
394 state_king_relative_table[std::abs(king_bw[
BLACK].x() -
398 state_king_relative_table[std::abs(king_bw[
WHITE].x() -
407 result -= drop_non_drop_table[index_x - 1 + 5];
408 result += drop_non_drop_table[index_x - 1];
410 state_king_relative_table[std::abs(king_bw[
BLACK].x() - moved.
to().
x()) +
413 state_king_relative_table[std::abs(king_bw[
WHITE].x() - moved.
to().
x()) +
418 result -= drop_non_drop_table[index_x - 1];
419 result += drop_non_drop_table[index_x - 1 + 5];
421 state_king_relative_table[std::abs(king_bw[
BLACK].x() - moved.
to().
x()) +
424 state_king_relative_table[std::abs(king_bw[
WHITE].x() - moved.
to().
x()) +
428 state_king_relative_table[std::abs(king_bw[
BLACK].x() - moved.
to().
x()) +
431 state_king_relative_table[std::abs(king_bw[
WHITE].x() - moved.
to().
x()) +
503 return (P ==
BLACK ? (pos.
y() - 1) : (9 - pos.
y()));
507 return cantAdvance(state, pawn.
ptypeO(), pawn.
square());
520 template <osl::Player P>
521 static void adjust(
int index,
MultiInt& values);
547 return (P ==
BLACK ? (pos.
y() - 1) : (9 - pos.
y()));
558 if (!canRetreat<P>(state,silver))
560 result += retreat_table[indexRetreat<P>(silver.
square())];
572 std::abs(kings[P].x() - silver.
square().
x());
573 const int y_diff = (P ==
BLACK ?
574 silver.
square().
y() - kings[P].y() :
575 kings[P].y() - silver.
square().
y());
576 result += head_table[x_diff + 9 * (y_diff + 8)];
607 return (P ==
BLACK ? (pos.
y() - 1) : (9 - pos.
y()));
611 return (pos.
x() > 5 ? 9 - pos.
x() : pos.
x() - 1);
616 return (P ==
BLACK ? (pos.
y() - 1) : (9 - pos.
y())) + 5;
644 assert(P==gold.
owner());
646 if (!canRetreat<P>(state, gold))
648 result += retreat_table[indexRetreat<P>(gold.
square())];
650 if (!canMoveToSide<P>(state, gold))
652 result += side_table[indexSideX(gold.
square())] +
653 side_table[indexSideY<P>(gold.
square())];
661 const Square king = kings[P];
662 const int x_diff = std::abs(king.x() - gold.
square().
x());
663 const int y_diff = (P ==
BLACK ?
666 result += knight_table[x_diff + 9 * (y_diff + 8)];
704 return (P ==
BLACK ? (pos.
y() - 1) : (9 - pos.
y()));
721 if (black_major_count == 4)
723 else if (black_major_count == 0)
749 const int y = (player ==
BLACK ? pos.
y() : 10 - pos.
y()) - 1;
750 return ptype * 9 + y;
771 const int x = (pos.
x() > 5 ? 10 - pos.
x() : pos.
x()) - 1;
772 return ptype * 5 + x;
783 template <Player Defense>
815 template <Player King>
818 return (King ==
BLACK ? y - 1 : 9 - y) ;
874 const int y_index = (P ==
BLACK ? y - 1 : 9 - y);
875 return index(P, up, up_up) + 1024 * y_index;
893 static void adjust(
int index,
int index_attack,
int index_defense,
900 template <
bool attack, Player owner>
903 const int y = (owner ==
BLACK ? king.
y() : 10 - king.
y());
904 return x_diff + (y - 1) * 9 + (attack ? 0 : 81);
917 static void evalWithUpdateBang(
923 static void adjust(
int black_turn_king_attack,
924 int black_turn_king_defense,
925 int white_turn_king_attack,
926 int white_turn_king_defense,
929 static int index(
bool same_turn,
bool has_support,
Ptype ptype)
934 template <
bool Attack>
938 const int x_diff = std::abs(position.
x() - king.
x());
939 const int y_diff = (owner ==
BLACK ?
940 position.
y() - king.
y() :
941 king.
y() - position.
y());
942 return ((ptype + (same_turn ? 0 :
PTYPE_SIZE) +
943 (has_support ? 0 : PTYPE_SIZE * 2)) * 9 + x_diff) * 17 +
944 y_diff + 8 + (Attack ? 0 : 9792);
946 template <
bool Attack>
950 return indexK<Attack>(king, same_turn, has_support,
955 template <Player Attacked>
960 int moved_piece_number,
967 black_old.
reset(moved_piece_number);
968 while (black_old.
any())
971 const bool has_support =
972 new_mask[Attacked].test(piece.
number());
973 const int index_king_black_turn_attack =
974 indexK<true>(kings[
alt(Attacked)], Attacked ==
BLACK, has_support, piece);
975 const int index_king_white_turn_attack =
976 indexK<true>(kings[
alt(Attacked)], Attacked ==
WHITE, has_support, piece);
977 const int index_king_black_turn_defense =
978 indexK<false>(kings[Attacked], Attacked ==
BLACK, has_support, piece);
979 const int index_king_white_turn_defense =
980 indexK<false>(kings[Attacked], Attacked ==
WHITE, has_support, piece);
981 adjust<Attacked ==
BLACK ? 1 : -1>(
982 index_king_black_turn_attack, index_king_black_turn_defense,
983 index_king_white_turn_attack, index_king_white_turn_defense,
989 black_new.
reset(moved_piece_number);
990 while (black_new.
any())
993 const bool has_support =
994 effected_mask[Attacked].test(piece.
number());
995 const int index_king_black_turn_attack =
996 indexK<true>(kings[
alt(Attacked)], Attacked ==
BLACK, has_support, piece);
997 const int index_king_white_turn_attack =
998 indexK<true>(kings[
alt(Attacked)], Attacked ==
WHITE, has_support, piece);
999 const int index_king_black_turn_defense =
1000 indexK<false>(kings[Attacked], Attacked ==
BLACK, has_support, piece);
1001 const int index_king_white_turn_defense =
1002 indexK<false>(kings[Attacked], Attacked ==
WHITE, has_support, piece);
1003 adjust<Attacked ==
BLACK ? -1 : 1>(
1004 index_king_black_turn_attack, index_king_black_turn_defense,
1005 index_king_white_turn_attack, index_king_white_turn_defense,
1009 PieceMask black_self_old = effected_mask[
alt(Attacked)] & new_mask[
alt(Attacked)] &
1010 effected_mask[Attacked] & (~new_mask[Attacked]) & state.
piecesOnBoard(Attacked);
1011 black_self_old.
reset(moved_piece_number);
1012 while (black_self_old.
any())
1015 const int index_king_black_turn_attack =
1016 indexK<true>(kings[
alt(Attacked)], Attacked ==
BLACK,
false, piece);
1017 const int index_king_white_turn_attack =
1018 indexK<true>(kings[
alt(Attacked)], Attacked ==
WHITE,
false, piece);
1019 const int index_king_black_turn_defense =
1020 indexK<false>(kings[Attacked], Attacked ==
BLACK,
false, piece);
1021 const int index_king_white_turn_defense =
1022 indexK<false>(kings[Attacked], Attacked ==
WHITE,
false, piece);
1023 const int index_king_black_turn_attack_old =
1024 indexK<true>(kings[
alt(Attacked)], Attacked ==
BLACK,
true, piece);
1025 const int index_king_white_turn_attack_old =
1026 indexK<true>(kings[
alt(Attacked)], Attacked ==
WHITE,
true, piece);
1027 const int index_king_black_turn_defense_old =
1028 indexK<false>(kings[Attacked], Attacked ==
BLACK,
true, piece);
1029 const int index_king_white_turn_defense_old =
1030 indexK<false>(kings[Attacked], Attacked ==
WHITE,
true, piece);
1031 adjust<Attacked ==
BLACK ? -1 : 1>(
1032 index_king_black_turn_attack_old, index_king_black_turn_defense_old,
1033 index_king_white_turn_attack_old, index_king_white_turn_defense_old,
1035 adjust<Attacked ==
BLACK ? 1 : -1>(
1036 index_king_black_turn_attack, index_king_black_turn_defense,
1037 index_king_white_turn_attack, index_king_white_turn_defense,
1041 PieceMask black_self_new = effected_mask[
alt(Attacked)] & new_mask[
alt(Attacked)] &
1042 (~effected_mask[Attacked]) & new_mask[Attacked] & state.
piecesOnBoard(Attacked);
1043 black_self_new.
reset(moved_piece_number);
1044 while (black_self_new.
any())
1047 const int index_king_black_turn_attack =
1048 indexK<true>(kings[
alt(Attacked)], Attacked ==
BLACK,
true, piece);
1049 const int index_king_white_turn_attack =
1050 indexK<true>(kings[
alt(Attacked)], Attacked ==
WHITE,
true, piece);
1051 const int index_king_black_turn_defense =
1052 indexK<false>(kings[Attacked], Attacked ==
BLACK,
true, piece);
1053 const int index_king_white_turn_defense =
1054 indexK<false>(kings[Attacked], Attacked ==
WHITE,
true, piece);
1055 const int index_king_black_turn_attack_old =
1056 indexK<true>(kings[
alt(Attacked)], Attacked ==
BLACK,
false, piece);
1057 const int index_king_white_turn_attack_old =
1058 indexK<true>(kings[
alt(Attacked)], Attacked ==
WHITE,
false, piece);
1059 const int index_king_black_turn_defense_old =
1060 indexK<false>(kings[Attacked], Attacked ==
BLACK,
false, piece);
1061 const int index_king_white_turn_defense_old =
1062 indexK<false>(kings[Attacked], Attacked ==
WHITE,
false, piece);
1064 adjust<Attacked ==
BLACK ? -1 : 1>(
1065 index_king_black_turn_attack_old, index_king_black_turn_defense_old,
1066 index_king_white_turn_attack_old, index_king_white_turn_defense_old,
1068 adjust<Attacked ==
BLACK ? 1 : -1>(
1069 index_king_black_turn_attack, index_king_black_turn_defense,
1070 index_king_white_turn_attack, index_king_white_turn_defense,
1108 static void evalWithUpdateBang(
1118 return (ptype + (same_turn ? 0 :
PTYPE_SIZE) +
1119 (has_support ? 0 : PTYPE_SIZE * 2)) * 16 + attack_ptype;
1125 result[
BLACK] += table[black];
1126 result[
WHITE] += table[white];
1129 result[
BLACK] -= table[black];
1130 result[
WHITE] -= table[white];
1133 template <
bool Plus>
1136 const Ptype attack_ptype,
1140 const int index_black_turn = index(
BLACK == player, with_support,
1141 ptype, attack_ptype);
1142 const int index_white_turn = index(
WHITE == player, with_support,
1143 ptype, attack_ptype);
1145 adjust<1>(index_black_turn, index_white_turn, result);
1147 adjust<-1>(index_black_turn, index_white_turn, result);
1153 int captured_number,
1165 const bool has_support =
1166 new_mask[P].test(piece.
number());
1170 attacked_mask[piece.
number()] = attacking;
1171 while (attacking.
any())
1174 evalOnePiece<P == BLACK>(P, piece.
ptype(), attack.
ptype(),
1175 has_support, result);
1181 while (new_without.any())
1183 const Piece piece = state.
pieceOf(new_without.takeOneBit());
1184 const bool has_support =
1185 effected_mask[P].test(piece.
number());
1189 evalOnePiece<P != BLACK>(P, piece.
ptype(), moved.
oldPtype(),
1190 has_support, result);
1193 if (captured_number != -1 && attacking.
test(captured_number))
1196 has_support, result);
1197 attacking.
reset(captured_number);
1199 while (attacking.
any())
1202 evalOnePiece<P != BLACK>(P, piece.
ptype(), attack.
ptype(),
1203 has_support, result);
1211 while (self_old.any())
1213 const Piece piece = state.
pieceOf(self_old.takeOneBit());
1217 evalOnePiece<P != BLACK>(P, piece.
ptype(), moved.
oldPtype(),
1221 if (captured_number != -1 && old_attacking.
test(captured_number))
1225 old_attacking.
reset(captured_number);
1227 while (old_attacking.
any())
1230 evalOnePiece<P != BLACK>(P, piece.
ptype(), attack.
ptype(),
1235 attacked_mask[piece.
number()] = new_attacking;
1236 while (new_attacking.any())
1238 const Piece attack = state.
pieceOf(new_attacking.takeOneBit());
1239 evalOnePiece<P == BLACK>(P, piece.
ptype(), attack.
ptype(),
1248 while (self_new_with.any())
1250 const Piece piece = state.
pieceOf(self_new_with.takeOneBit());
1254 evalOnePiece<P != BLACK>(P, piece.
ptype(), moved.
oldPtype(),
1258 if (captured_number != -1 && old_attacking.
test(captured_number))
1262 old_attacking.
reset(captured_number);
1264 while (old_attacking.
any())
1267 evalOnePiece<P != BLACK>(P, piece.
ptype(), attack.
ptype(),
1272 attacked_mask[piece.
number()] = new_attacking;
1273 while (new_attacking.any())
1275 const Piece attack = state.
pieceOf(new_attacking.takeOneBit());
1276 evalOnePiece<P == BLACK>(P, piece.
ptype(), attack.
ptype(),
1282 effected ^= new_mask[P];
1283 effected = ~effected;
1289 while (attack_changed.
any())
1294 if (captured_number != -1 &&
1295 attack_old_mask.
test(captured_number))
1297 evalOnePiece<P != BLACK>(P, attacked.
ptype(),
1299 new_mask[P].test(attacked.
number()),
1301 attack_old_mask.
reset(captured_number);
1306 evalOnePiece<P != BLACK>(P, attacked.
ptype(),
1308 new_mask[P].test(attacked.
number()),
1315 evalOnePiece<P == BLACK>(P, attacked.
ptype(),
1317 new_mask[P].test(attacked.
number()),
1321 PieceMask gone = attack_old_mask & (~attack_new_mask);
1325 evalOnePiece<P != BLACK>(P, attacked.
ptype(),
1327 effected_mask[P].test(attacked.
number()),
1330 PieceMask added = (~attack_old_mask) & attack_new_mask;
1334 evalOnePiece<P == BLACK>(P, attacked.
ptype(),
1336 new_mask[P].test(attacked.
number()),
1355 template <Player Owner>
1360 const Ptype attack_ptype
1364 return (piece.
ptype() +
1381 template<osl::Player P,osl::Ptype T>
1391 static void evalWithUpdateBang(
1396 MultiInt &last_value_and_out,
unsigned int &ptypeo_mask);
1436 count - 1) + 720 + 800;
1476 count - 1) + 720 + 800;
1482 xy_table_diff[indexCountX(ptype, count, my_king_x)]+
1483 xy_table_diff[indexCountY(ptype, count, my_king_y)]+
1484 xy_attack_table_diff[indexCountX(ptype,count, op_king_x)]+
1485 xy_attack_table_diff[indexCountY(ptype, count, op_king_y)];
1491 xy_table_diff[indexBoardCountX(ptype, count, my_king_x)]+
1492 xy_table_diff[indexBoardCountY(ptype, count, my_king_y)]+
1493 xy_attack_table_diff[indexBoardCountX(ptype,count, op_king_x)]+
1494 xy_attack_table_diff[indexBoardCountY(ptype, count, op_king_y)];
1524 PtypeO ptypeO,
bool attack)
1526 const int y_diff = (p ==
BLACK ? king.
y() - pos.
y() : pos.
y() - king.
y());
1527 const int x_diff = std::abs(king.
x() - pos.
x());
1530 ptypeO =
alt(ptypeO);
1532 return y_diff + 8 + x_diff * 17 + (ptypeO -
PTYPEO_MIN) * 17 * 9 +
1533 (attack ? 0 : 4896);
1553 if (player ==
WHITE)
1556 pawn_y = (10 - pawn_y) % 10;
1558 return pawn_y + 10 * (y - 1 + 9 * ptype);
1572 template <Player Defense>
1575 int king_x = (king.
x() > 5 ? 10 - king.
x() : king.
x());
1576 int king_y = (Defense ==
WHITE ? 10 - king.
y() : king.
y());
1577 return king_x - 1 + 5 * (king_y - 1+ 9 * (distance0 + 3 * count));
1582 template <Player Defense>
1584 int count1,
int count2)
1586 int king_x = (king.
x() > 5 ? 10 - king.
x() : king.
x());
1587 int king_y = (Defense ==
WHITE ? 10 - king.
y() : king.
y());
1588 return king_x + 5 * (king_y + 9 * (
std::min(5,count0) + 6 *
1614 if (P==
BLACK) index=((ptypeo_mask>>19)&0x1fc0)|((ptypeo_mask>>18)&0x3f);
1615 else index=((ptypeo_mask>>3)&0x1fc0)|((ptypeo_mask>>2)&0x3f);
1617 return table[index];
1619 return -table[index];
1635 CArray<std::pair<Square,int>,2>& silver_drop);
1650 template <Player Defense>
1652 std::pair<Square,int>& bishop_drop,
1653 std::pair<Square,int>& rook_drop);
1655 CArray<std::pair<Square,int>,2>& bishop_drop,
1656 CArray<std::pair<Square,int>,2>& rook_drop);
1659 static const Square findDropInLine
1664 Square center,
bool maybe_empty=
false);
1675 template <Player Defense>
1679 std::pair<Square,int>& knight_drop);
1682 CArray<std::pair<Square,int>,2>& knight_drop);
1687 CArray<std::pair<Square,int>,2>& knight_drop);
1691 int y,
int x0,
int x1);
1702 template <Player P, Player Defense>
1703 static void updateSquares
1706 template <osl::Player Defense>
1709 bool has_knight,
const BoardMask& knight_fork_squares,
1710 std::pair<Square,int>& knight_drop);
1741 #endif // EVAL_ML_MINORPIECE_H
static int rookIndex(Ptype a, Ptype b)
Ptype unpromote(Ptype ptype)
ptypeがpromote後の型の時に,promote前の型を返す. promoteしていない型の時はそのまま返す ...
CArray< PiecePair::IndexTable, 10 > & y_table
static MultiInt standValue(int attack_index, int defense_index, int attack_index_y, int defense_index_y, int attack_index_x, int defense_index_x)
bool isOnBoardByOwner() const
piece がプレイヤーPの持ち物でかつボード上にある駒の場合は true.
static int indexCountY(Ptype ptype, int count, int y)
static bool canMoveToSide(const NumEffectState &state, const Piece gold)
bool hasEffectAt(Square target) const
対象とするマスにあるプレイヤーの利きがあるかどうか.
static MultiInt evalOne(const NumEffectState &state, const Piece silver, const CArray< Square, 2 > &kings)
PtypeO altIfPiece(PtypeO ptypeO)
Pieceの時にはowner を反転する
static int indexBoardCountX(Ptype ptype, int count, int x)
constexpr Player alt(Player player)
static void setUp(const Weights &weights, int stage)
static void updateChanged(const NumEffectState &state, const Piece p, Move moved, int captured_number, const CArray< PieceMask, 2 > &effected_mask, const CArray< PieceMask, 2 > &new_mask, CArray< PieceMask, 40 > &attacked_mask, MultiIntPair &result)
static CArray< MultiInt, 9 > y_table
static CArray< MultiInt, 90 > x_stand_table
static int index(Player p, Square pos, Square king, PtypeO ptypeO, bool attack)
static CArray< MultiInt, 1440 > table
int min(Player p, int v1, int v2)
static int indexY(Player P, PtypeO up, PtypeO up_up, int y)
Ptype getPtype(PtypeO ptypeO)
int countPiecesOnStand(Player pl, Ptype ptype) const
持駒の枚数を数える
static bool cantAdvance(const NumEffectState &state, const PtypeO ptypeO, const Square position)
const Piece pieceAt(Square sq) const
static CArray< MultiInt, 19584 > king_table
int y() const
将棋としてのY座標を返す.
static int indexCount(int count)
static CArray< MultiInt, 81 > defense_y_table
static CArray< MultiInt, 2240 > xy_table
static CArray< MultiInt, 2240 > xy_table_diff
static MultiInt evalOne(const NumEffectState &state, const Piece gold, const CArray< Square, 2 > &kings)
static MultiInt eval(int black_major_count)
int x() const
将棋としてのX座標を返す.
static CArray< MultiInt, 9 > retreat_table
static int index(Ptype a, Ptype b)
static MultiInt value(int attack_index, int defense_index, int attack_index_y, int defense_index_y, int attack_index_x, int defense_index_x)
static int indexBoardCount(Ptype ptype, int count)
static int indexCountY(int count, int y)
static CArray< MultiInt, 9216 > y_table
static CArray< MultiInt, 9 > table
const Piece pieceOf(int num) const
Square kingSquare() const
const PtypeTable Ptype_Table
static bool canCheck(const NumEffectState &state)
static CArray< MultiInt, 8192 > table
static int indexSideX(Square pos)
static CArray< MultiInt, ONE_DIM > table
static CArray< MultiInt, 153 > knight_table
static int indexCountX(Ptype ptype, int count, int x)
bool isOnBoard() const
盤面上を表すかどうかの判定. 1<=x() && x()<=9 && 1<=y() && y()<=9 Squareの内部表現に依存する. ...
static int index(Player P, Square pos)
static int indexK(Square king, bool same_turn, bool has_support, Square position, Player owner, Ptype ptype)
static int indexBoardCount(int count)
static MultiInt valueBoardAll(Ptype ptype, int count, int my_king_x, int my_king_y, int op_king_x, int op_king_y)
Player getOwner(PtypeO ptypeO)
static CArray< MultiInt, 9792 > table
Ptype oldPtype() const
移動前のPtype, i.e., 成る手だった場合成る前
static CArray< MultiInt, ONE_DIM > table
static int index2(int i0, int i1)
const PieceMask effectedChanged(Player pl) const
前の指手でeffectedMask(pl)が変化したか.
static CArray< MultiInt, 153 > head_table
static CArray< MultiInt, 144 > opp_table
bool hasPieceOnStand(Player player, Ptype ptype) const
const NumBitmapEffect effectSetAt(Square sq) const
static CArray< MultiInt, 18 > stand_table
static int index(const Player, const Ptype ptype, const Square pos)
static MultiInt value(int index_y)
static CArray< MultiInt, 1024 > table
static int index(const Piece piece)
constexpr int playerToIndex(Player player)
static MultiInt valueAll(Ptype ptype, int count, int my_king_x, int my_king_y, int op_king_x, int op_king_y)
static CArray< MultiInt, 10 > drop_non_drop_table
const Square neighbor() const
static int indexBoardCountY(int count, int y)
static int index(bool same_turn, bool has_support, Ptype ptype)
static CArray< MultiInt, 2240 > xy_attack_table_diff
static int indexCountX(int count, int x)
static int index(Player player, Ptype ptype, int y, int pawn_y)
static CArray< MultiInt, 9 > defense_table
static MultiInt evalOne(unsigned int ptypeo_mask)
static int index(bool same_turn, bool has_support, Ptype ptype, Ptype attack_ptype)
static int index(Player P, PtypeO up, PtypeO up_up)
static CArray< MultiInt, 162 > y_stand_table
static CArray< MultiInt, ONE_DIM > table
static CArray< MultiInt, 144 > table
static int index(const Player player, const Ptype ptype, const Square pos)
const Square square() const
Ptype capturePtype() const
static CArray< MultiInt, 9 > retreat_table
static CArray< MultiInt, 80 > table
PtypeO
Player + Ptype [-15, 15] PtypeO の O は Owner の O.
static MultiInt eval(const NumEffectState &state, int black_pawn_count)
static CArray< MultiInt, ONE_DIM > table
static void evalOnePiece(const Player player, const Ptype ptype, const Ptype attack_ptype, bool with_support, MultiIntPair &result)
static int index1(const NumEffectState &state, Piece piece)
bool isPawnMaskSet(Player player, int x) const
static int indexBoardCountX(int count, int x)
static CArray< MultiInt, 14 > side_table
const PieceMask & piecesOnBoard(Player p) const
static int index(const Square king, int x)
bool hasEffectByPtypeStrict(Player attack, Square target) const
target に ptype の利きがあるか? 成不成を区別
const Piece findCheapAttack(Player P, Square square) const
static int index(const Square king, int distance0, int count)
bool isPromoted(Ptype ptype)
ptypeがpromote後の型かどうかのチェック
static CArray< MultiInt, 9 > table
PtypeO captured(PtypeO ptypeO)
unpromoteすると共に,ownerを反転する.
const Square nextSquare(Player P, Square pos, Direction dr) const
next position from pos for player P.
static CArray< MultiInt, 90 > x_table
static CArray< MultiInt, 64 > table
static CArray< MultiInt, 1215 > table
static int indexK(Square king, bool same_turn, bool has_support, Piece piece)
static CArray< MultiInt, 9720 > combination_table
static bool cantAdvance(const NumEffectState &state, const Piece pawn)
static int index(const Piece piece)
static int indexCount(Ptype ptype, int count)
static int indexSideY(Square pos)
static bool isTarget(Ptype ptype)
static CArray< MultiInt, 160 > table
const Piece kingPiece() const
static int indexRetreat(Square pos)
static int index(Player P, Square pos)
static int indexBoardCountY(Ptype ptype, int count, int y)
static int indexX(const Piece king, int x)
static CArray< MultiInt, 36 > state_king_relative_table
int getIndexMin(Ptype ptype) const
static CArray< MultiInt, ONE_DIM > table
static void updateEffectChanged(const NumEffectState &state, const CArray< PieceMask, 2 > &effected_mask, const CArray< PieceMask, 2 > &new_mask, int moved_piece_number, MultiIntPair &result)
static int indexCombination(const Square king, int count0, int count1, int count2)
static CArray< MultiInt, 9 > table
static int indexY(const Piece king, int x)
static int bishopIndex(Ptype a, Ptype b)
static CArray< MultiInt, 1024 > table
static int indexRetreat(Square pos)
static MultiInt evalWithUpdate(const NumEffectState &state, Move moved, MultiInt &last_value)
static CArray< MultiInt, 2240 > xy_attack_table
static void adjust(int black, int white, MultiIntPair &result)
const BoardTable Board_Table