4#ifndef EVAL_ML_MAJORPIECE_H
5#define EVAL_ML_MAJORPIECE_H
18 template <
bool Opening, Ptype MajorBasic>
35 i < PtypeTraits<MajorBasic>::indexLimit;
64 template <
bool Opening>
94 return (rook_y - 1) * 10 + pawn_y + (rook.
isPromoted() ? 90 : 0);
97 const Piece rook,
int pawn_y)
99 const int x_diff = std::abs(rook.
square().
x() - king.
x());
102 return x_diff * 10 * 9 + (rook_y - 1) * 10 + pawn_y + (rook.
isPromoted() ? 810 : 0);
123 if (black_major_count == 4)
125 else if (black_major_count == 0)
134 template <
bool Opening>
142 template <Ptype PTYPE>
177 static int index(
int abs_x_diff,
int y_diff,
bool horizontal,
bool is_promoted)
179 return y_diff + 8 + abs_x_diff * 17 + (horizontal ? 153 : 0) +
180 (is_promoted ? 306 : 0);
190 static int index0(
int abs_x_diff,
int y_diff,
192 bool horizontal,
bool promoted){
193 return y_diff+8+abs_x_diff*17+(ptypeO -
PTYPEO_MIN) * 17 * 9 +
194 (horizontal ? 4896 : 0) + (promoted ? 9792 : 0);
207 int y_diff=from.
y()-king.
y();
208 int x_diff=from.
x()-king.
x();
209 return index1(x_diff,y_diff,ptypeO,isP);
220 assert(-9 <= y_diff && y_diff <= 9);
221 assert(-9 <= x_diff && x_diff <= 9);
223 int index=(ptypeO-
PTYPEO_MIN)+32*((y_diff+9)+19*(x_diff+9+19*(isP ? 1 : 0)));
236 int y_diff=from.
y()-king.
y();
237 int x_diff=from.
x()-king.
x();
238 return index2(x_diff,y_diff,isP);
246 static int index2(
int x_diff,
int y_diff,
bool isP){
247 assert(-9 <= y_diff && y_diff <= 9);
248 assert(-9 <= x_diff && x_diff <= 9);
249 int index=(y_diff+9)+19*(x_diff+9+19*(isP ? 1 : 0));
323 static int index(
int x_diff,
int y_diff,
bool ur,
bool promoted)
327 return y_diff + 8 + std::abs(x_diff) * 17 + (ur ? 153 : 0) + (promoted ? 306 : 0);
329 static int index0(
int x_diff,
int y_diff,
PtypeO ptypeO,
bool ur,
bool promoted)
333 return -y_diff + 8 + std::abs(x_diff) * 17 + (ptypeO -
PTYPEO_MIN) * 17 * 9 +
334 (ur ? 4896 : 0) + (promoted ? 9792 : 0);
347 int y_diff=from.
y()-king.
y();
348 int x_diff=from.
x()-king.
x();
349 return index1(x_diff,y_diff,ptypeO,isP);
360 assert(-9 <= y_diff && y_diff <= 9);
361 assert(-9 <= x_diff && x_diff <= 9);
363 int index=(ptypeO-
PTYPEO_MIN)+32*((y_diff+9)+19*(x_diff+9+19*(isP ? 1 : 0)));
376 int y_diff=from.
y()-king.
y();
377 int x_diff=from.
x()-king.
x();
378 return index2(x_diff,y_diff,isP);
386 static int index2(
int x_diff,
int y_diff,
bool isP){
387 assert(-9 <= y_diff && y_diff <= 9);
388 assert(-9 <= x_diff && x_diff <= 9);
389 int index=(y_diff+9)+19*(x_diff+9+19*(isP ? 1 : 0));
439 ptypeO=(
PtypeO)(
static_cast<int>(ptypeO)^(~15));
445 return (
ptypeOIndex(ptypeO) * 9 + x_diff) * 17 + y_diff + 8;
482 template<Player King>
487 template <Player King>
490 const int rook_x = std::abs(king.
x() - rook.
square().
x());
491 const int bishop_x = std::abs(king.
x() - bishop.
square().
x());
493 const int bishop_y = (King ==
BLACK ? bishop.
square().
y() - king.
y() : king.
y() - bishop.
square().
y());
494 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)))))));
508 int &self_count,
int &opp_count,
540 bool opp_with_support)
542 return ptype +
PTYPE_SIZE * ((self_with_support ? 1 : 0) +
543 2 * (opp_with_support ? 1 : 0));
555 template <
bool SamePlayer, Player P>
565 (y2 + 10 * ((rook1.
isPromoted() ? 1 : 0) + 2 *
567 (SamePlayer ? 1 : 0))));
571 if (y1 == 0 || y2 == 0 || y1 == y2)
573 return (10 - y1) % 10 + 10 *
574 ((10 - y2) % 10 + 10 * ((rook1.
isPromoted() ? 1 : 0) + 2 *
576 (SamePlayer ? 1 : 0))));
580 return (10 - y2) % 10 + 10 *
581 ((10 - y1) % 10 + 10 * ((rook2.
isPromoted() ? 1 : 0) + 2 *
583 (SamePlayer ? 1 : 0))));
590 (y2 + 10 * ((rook1.
isPromoted() ? 1 : 0) + 2 *
592 (SamePlayer ? 1 : 0))));
595 static int index(
bool same_player,
bool promoted1,
596 bool promoted2,
int y1,
int y2)
599 (y2 + 10 * ((promoted1 ? 1 : 0) + 2 *
600 ((promoted2 ? 1 : 0) + 2 *
601 (same_player ? 1 : 0))));
614 bool opp_with_support,
bool vertical)
616 return ptype +
PTYPE_SIZE * ((self_with_support ? 1 : 0) +
617 2 * (opp_with_support ? 1 : 0)) +
644 template <Player Owner>
646 static size_t index(
Ptype ptype,
bool is_rook,
bool can_promote)
648 return ptype * 4 + is_rook * 2 + can_promote;
663 static size_t index(
int rook_x,
int rook_y,
int silver_x,
int silver_y,
664 int knight_x,
int knight_y)
666 return knight_y + 9 * (knight_x + 9 * (silver_y + 9 * (silver_x + 9 * (rook_y + 9 * rook_x))));
681 static size_t index(
int bishop_x,
int bishop_y,
int silver_x,
int silver_y,
682 int knight_x,
int knight_y)
684 return knight_y + 9 * (knight_x + 9 * (silver_y + 9 * (silver_x + 9 * (bishop_y + 9 * bishop_x))));
701 bool rook_support,
bool bishop_support)
704 +rook_support*2+bishop_support;
706 template <Player Owner>
bool isPromoted() const
promoteした駒かどうかをチェックする
const Square square() const
const Piece pieceOf(int num) const
int y() const
将棋としてのY座標を返す.
int x() const
将棋としてのX座標を返す.
static MultiInt eval(int black_major_count)
static void setUp(const Weights &weights, int stage)
static int index(Ptype support, Ptype attack, bool has_gold, bool rook_support, bool bishop_support)
static void addOne(const NumEffectState &state, Piece rook, MultiInt &)
static CArray< MultiInt, ONE_DIM > table
static void setUp(const Weights &weights)
static int index(Ptype ptype, bool self_with_support, bool opp_with_support)
static CArray< MultiInt, 64 > table
static void setUp(const Weights &weights)
static CArray< MultiInt, 612 > defense_table
static int index2(int x_diff, int y_diff, bool isP)
黒の角(馬)がある場所は空マスでないのでその分を補正するテーブル {attack,defense}_nospace へのアクセス (x_diff, y_diff) - 玉を基準にしてみた角(馬)の相対位...
static CArray< MultiInt, 23104 > defense_ur
static CArray< MultiInt, 23104 > attack_ur
static CArray< MultiInt, 23104 > defense_dr
static CArray< MultiInt, 612 > attack_table
static int index0(int x_diff, int y_diff, PtypeO ptypeO, bool ur, bool promoted)
static CArray< MultiInt, 23104 > attack_dr
static int index(int x_diff, int y_diff, bool ur, bool promoted)
static int index1(int x_diff, int y_diff, PtypeO ptypeO, bool isP)
黒の角(馬)からの利きのある駒のindex {attack,defense}_{ul,ur,dl,dr} へのアクセスに使う (x_diff, y_diff) - 玉を基準に見た駒の相対位置 ptype...
static CArray< MultiInt, 722 > attack_nospace
static int index1(Square king, Square from, PtypeO ptypeO, bool isP)
黒の角(馬)からの利きのある駒のindex {attack,defense}_{ul,ur,dl,dr} へのアクセスに使う from - 駒の位置 king - 玉の位置 ptypeO - 駒の種類,...
static CArray< MultiInt, 722 > defense_nospace
static CArray< MultiInt, 32 > piece_table
static int index2(Square king, Square from, bool isP)
黒の角(馬)がある場所は空マスでないのでその分を補正するテーブル {attack,defense}_nospace へのアクセス king - 玉の位置 from - 角(馬)の位置 isP - 馬の場...
static CArray< MultiInt, 23104 > defense_dl
static CArray< MultiInt, 23104 > attack_ul
static CArray< MultiInt, 23104 > defense_ul
static CArray< MultiInt, 23104 > attack_dl
static MultiInt evalOne(const NumEffectState &state, Square bishop, Square myKing, Square opKing, Square ulp, Square urp, Square dlp, Square drp, bool isP)
static void setUp(const Weights &weights)
static void setUp(const Weights &weights)
static void setUp(const Weights &weights, int stage)
static void setUp(const Weights &weights)
static void setUp(const Weights &weights)
static CArray< MultiInt, 32 > table
static int indexK(Player player, PtypeO ptypeO, int x_diff, int y_diff)
static int indexX(PtypeO ptypeO, int x)
static void setUp(const Weights &weights)
static CArray< MultiInt, 4896 > king_table
static CArray< MultiInt, 160 > x_table
static size_t index(int bishop_x, int bishop_y, int silver_x, int silver_y, int knight_x, int knight_y)
static CArray< MultiInt, ONE_DIM > table
static void setUp(const Weights &weights)
static void setUp(const Weights &weights)
static CArray< MultiInt, 32 > table
static CArray< MultiInt, 374544 > table
static int index(const Square king, const Piece rook, const Piece bishop)
static void setUp(const Weights &weights)
static MultiInt evalOne(const NumEffectState &state)
static size_t index(Ptype ptype, bool is_rook, bool can_promote)
static CArray< MultiInt, ONE_DIM > table
static void setUp(const Weights &weights)
static MultiInt addOne(const NumEffectState &state)
static int evalOne(const NumEffectState &state)
static int index(const NumEffectState &state, Piece piece)
static CArray< int, 32 > table
static void setUp(const Weights &weights)
static CArray< int, 18 > table
static void setUp(const Weights &weights)
static int index(Piece piece)
static int eval(const NumEffectState &state)
static void setUp(const Weights &weights)
static void setUp(const Weights &weights)
static void setUp(const Weights &weights)
static CArray< MultiInt, 9 > opp_table
static CArray< MultiInt, 9 > all_table
static CArray< MultiInt, 9 > self_table
static MultiInt eval(const NumEffectState &state)
static void countBetween(const NumEffectState &state, Square king, Piece bishop, int &self_count, int &opp_count, int &total_count)
static CArray< MultiInt, 23104 > attack_d
static MultiInt evalOne(const NumEffectState &state, Square rook, Square myKing, Square opKing, Square up, Square dp, Square rp, Square lp, bool isP)
static int index1(int x_diff, int y_diff, PtypeO ptypeO, bool isP)
黒の飛車(竜)からの利きのある駒のindex {attack,defense}_{u,r,l,d} へのアクセスに使う (x_diff, y_diff) - 玉を基準に見た駒の相対位置 ptypeO -...
static CArray< MultiInt, 23104 > defense_d
static CArray< MultiInt, 23104 > defense_u
static CArray< MultiInt, 612 > attack_table
static int index0(int abs_x_diff, int y_diff, PtypeO ptypeO, bool horizontal, bool promoted)
黒の飛車(竜)から利きのある駒 (abs_x_diff, y_diff) - 駒を基準にした玉の相対位置 abs_x_diffは絶対値 ptypeO - 駒のptypeO,...
static CArray< MultiInt, 23104 > attack_u
static CArray< MultiInt, 23104 > attack_l
static CArray< MultiInt, 23104 > attack_r
static CArray< MultiInt, 722 > attack_nospace
static CArray< MultiInt, 722 > defense_nospace
static CArray< MultiInt, 23104 > defense_r
static CArray< MultiInt, 612 > defense_table
static int index2(int x_diff, int y_diff, bool isP)
黒の飛車(竜)がある場所は空マスでないのでその分を補正するテーブル {attack,defense}_nospace へのアクセス (x_diff, y_diff) - 玉を基準にしてみた飛車(竜)の相...
static int index2(Square king, Square from, bool isP)
黒の飛車(竜)がある場所は空マスでないのでその分を補正するテーブル {attack,defense}_nospace へのアクセス king - 玉の位置 from - 飛車(竜)の位置 isP - 竜...
static int index1(Square king, Square from, PtypeO ptypeO, bool isP)
黒の飛車(竜)からの利きのある駒のindex {attack,defense}_{u,r,l,d} へのアクセスに使う from - 駒の位置 king - 玉の位置 ptypeO - 駒の種類,白から...
static int index(int abs_x_diff, int y_diff, bool horizontal, bool is_promoted)
(abs_x_diff, y_diff) - 玉を原点とした時の空マスの相対位置 horizontal - 飛車の横利きがある場合 is_promoted - 竜の場合
static CArray< MultiInt, 32 > piece_table
static CArray< MultiInt, 23104 > defense_l
static void setUp(const Weights &weights)
static void setUp(const Weights &weights)
static void setUp(const Weights &weights, int stage)
static void setUp(const Weights &weights)
static CArray< MultiInt, 180 > table
static void setUp(const Weights &weights)
static int indexY(const Square king, const Piece rook, int pawn_y)
static CArray< MultiInt, 1620 > y_attack_table
static CArray< MultiInt, 1620 > y_defense_table
static int index(const Piece rook, const int pawn_y)
static void setUp(const Weights &weights)
static CArray< MultiInt, 128 > table
static int index(Ptype ptype, bool self_with_support, bool opp_with_support, bool vertical)
static void setUp(const Weights &weights)
static int index(bool same_player, bool promoted1, bool promoted2, int y1, int y2)
static void setUp(const Weights &weights)
static int index(Piece rook1, Piece rook2)
static CArray< MultiInt, 800 > table
static void setUp(const Weights &weights)
static CArray< MultiInt, ONE_DIM > table
static size_t index(int rook_x, int rook_y, int silver_x, int silver_y, int knight_x, int knight_y)
Ptype getPtype(PtypeO ptypeO)
constexpr Ptype unpromoteSafe(Ptype ptype)
unsigned int ptypeOIndex(PtypeO ptypeo)
PtypeO
Player + Ptype [-15, 15] PtypeO の O は Owner の O.
PtypeO altIfPiece(PtypeO ptypeO)
Pieceの時にはowner を反転する