4 #ifndef EVAL_ML_MAJORPIECE_H
5 #define EVAL_ML_MAJORPIECE_H
20 template <
bool Opening, Ptype MajorBasic>
33 static int eval(
const NumEffectState &state)
37 i < PtypeTraits<MajorBasic>::indexLimit;
40 const Piece piece = state.pieceOf(i);
66 template <
bool Opening>
72 static int eval(
const NumEffectState &state);
90 const CArray2d<int, 2, 9> &pawns);
96 return (rook_y - 1) * 10 + pawn_y + (rook.
isPromoted() ? 90 : 0);
99 const Piece rook,
int pawn_y)
101 const int x_diff = std::abs(rook.
square().
x() - king.
x());
104 return x_diff * 10 * 9 + (rook_y - 1) * 10 + pawn_y + (rook.
isPromoted() ? 810 : 0);
125 if (black_major_count == 4)
127 else if (black_major_count == 0)
136 template <
bool Opening>
142 static int eval(
const NumEffectState &state);
143 static int index(
const NumEffectState &state,
Piece piece);
144 template <Ptype PTYPE>
145 static int evalOne(
const NumEffectState &state);
179 static int index(
int abs_x_diff,
int y_diff,
bool horizontal,
bool is_promoted)
181 return y_diff + 8 + abs_x_diff * 17 + (horizontal ? 153 : 0) +
182 (is_promoted ? 306 : 0);
192 static int index0(
int abs_x_diff,
int y_diff,
194 bool horizontal,
bool promoted){
195 return y_diff+8+abs_x_diff*17+(ptypeO -
PTYPEO_MIN) * 17 * 9 +
196 (horizontal ? 4896 : 0) + (promoted ? 9792 : 0);
209 int y_diff=from.
y()-king.
y();
210 int x_diff=from.
x()-king.
x();
211 return index1(x_diff,y_diff,ptypeO,isP);
222 assert(-9 <= y_diff && y_diff <= 9);
223 assert(-9 <= x_diff && x_diff <= 9);
225 int index=(ptypeO-
PTYPEO_MIN)+32*((y_diff+9)+19*(x_diff+9+19*(isP ? 1 : 0)));
226 assert(0<=index && index<32*19*19*2);
238 int y_diff=from.
y()-king.
y();
239 int x_diff=from.
x()-king.
x();
240 return index2(x_diff,y_diff,isP);
248 static int index2(
int x_diff,
int y_diff,
bool isP){
249 assert(-9 <= y_diff && y_diff <= 9);
250 assert(-9 <= x_diff && x_diff <= 9);
251 int index=(y_diff+9)+19*(x_diff+9+19*(isP ? 1 : 0));
252 assert(0<=index && index<19*19*2);
325 static int index(
int x_diff,
int y_diff,
bool ur,
bool promoted)
329 return y_diff + 8 + std::abs(x_diff) * 17 + (ur ? 153 : 0) + (promoted ? 306 : 0);
331 static int index0(
int x_diff,
int y_diff,
PtypeO ptypeO,
bool ur,
bool promoted)
335 return -y_diff + 8 + std::abs(x_diff) * 17 + (ptypeO -
PTYPEO_MIN) * 17 * 9 +
336 (ur ? 4896 : 0) + (promoted ? 9792 : 0);
349 int y_diff=from.
y()-king.
y();
350 int x_diff=from.
x()-king.
x();
351 return index1(x_diff,y_diff,ptypeO,isP);
362 assert(-9 <= y_diff && y_diff <= 9);
363 assert(-9 <= x_diff && x_diff <= 9);
365 int index=(ptypeO-
PTYPEO_MIN)+32*((y_diff+9)+19*(x_diff+9+19*(isP ? 1 : 0)));
366 assert(0<=index && index<32*19*19*2);
378 int y_diff=from.
y()-king.
y();
379 int x_diff=from.
x()-king.
x();
380 return index2(x_diff,y_diff,isP);
388 static int index2(
int x_diff,
int y_diff,
bool isP){
389 assert(-9 <= y_diff && y_diff <= 9);
390 assert(-9 <= x_diff && x_diff <= 9);
391 int index=(y_diff+9)+19*(x_diff+9+19*(isP ? 1 : 0));
392 assert(0<=index && index<19*19*2);
441 ptypeO=(
PtypeO)(static_cast<int>(ptypeO)^(~15));
447 return (
ptypeOIndex(ptypeO) * 9 + x_diff) * 17 + y_diff + 8;
484 template<Player King>
488 static CArray<MultiInt, 374544>
table;
489 template <Player King>
492 const int rook_x = std::abs(king.
x() - rook.
square().
x());
493 const int bishop_x = std::abs(king.
x() - bishop.
square().
x());
495 const int bishop_y = (King ==
BLACK ? bishop.
square().
y() - king.
y() : king.
y() - bishop.
square().
y());
496 return bishop_y + 8 + 17 * (bishop_x + 9 * (rook_y + 8 + 17 * (rook_x + 9 * ((bishop.
owner() == King ? 1 : 0) + 2 * ((rook.
owner() == King ? 1 : 0) + 2 * (2 * (bishop.
isPromoted() ? 1 : 0) + (rook.
isPromoted() ? 1 : 0)))))));
510 int &self_count,
int &opp_count,
542 bool opp_with_support)
544 return ptype +
PTYPE_SIZE * ((self_with_support ? 1 : 0) +
545 2 * (opp_with_support ? 1 : 0));
557 template <
bool SamePlayer, Player P>
567 (y2 + 10 * ((rook1.
isPromoted() ? 1 : 0) + 2 *
569 (SamePlayer ? 1 : 0))));
573 if (y1 == 0 || y2 == 0 || y1 == y2)
575 return (10 - y1) % 10 + 10 *
576 ((10 - y2) % 10 + 10 * ((rook1.
isPromoted() ? 1 : 0) + 2 *
578 (SamePlayer ? 1 : 0))));
582 return (10 - y2) % 10 + 10 *
583 ((10 - y1) % 10 + 10 * ((rook2.
isPromoted() ? 1 : 0) + 2 *
585 (SamePlayer ? 1 : 0))));
592 (y2 + 10 * ((rook1.
isPromoted() ? 1 : 0) + 2 *
594 (SamePlayer ? 1 : 0))));
597 static int index(
bool same_player,
bool promoted1,
598 bool promoted2,
int y1,
int y2)
601 (y2 + 10 * ((promoted1 ? 1 : 0) + 2 *
602 ((promoted2 ? 1 : 0) + 2 *
603 (same_player ? 1 : 0))));
616 bool opp_with_support,
bool vertical)
618 return ptype +
PTYPE_SIZE * ((self_with_support ? 1 : 0) +
619 2 * (opp_with_support ? 1 : 0)) +
645 static CArray<MultiInt, ONE_DIM>
table;
646 template <Player Owner>
648 static size_t index(
Ptype ptype,
bool is_rook,
bool can_promote)
650 return ptype * 4 + is_rook * 2 + can_promote;
664 static CArray<MultiInt, ONE_DIM>
table;
665 static size_t index(
int rook_x,
int rook_y,
int silver_x,
int silver_y,
666 int knight_x,
int knight_y)
668 return knight_y + 9 * (knight_x + 9 * (silver_y + 9 * (silver_x + 9 * (rook_y + 9 * rook_x))));
682 static CArray<MultiInt, ONE_DIM>
table;
683 static size_t index(
int bishop_x,
int bishop_y,
int silver_x,
int silver_y,
684 int knight_x,
int knight_y)
686 return knight_y + 9 * (knight_x + 9 * (silver_y + 9 * (silver_x + 9 * (bishop_y + 9 * bishop_x))));
700 static CArray<MultiInt, ONE_DIM>
table;
703 bool rook_support,
bool bishop_support)
706 +rook_support*2+bishop_support;
708 template <Player Owner>
715 #endif // EVAL_ML_MAJORPIECE_H