6template <
bool Opening, osl::Ptype MajorBasic>
10template <
bool Opening, osl::Ptype MajorBasic>
14 for (
size_t i = 0; i < weights.
dimension(); ++i)
21template <
bool Opening>
24template <
bool Opening>
31template <
bool Opening>
36 i < PtypeTraits<ROOK>::indexLimit;
62 for (
int i = 0; i <
ONE_DIM; ++i)
76 for (
int i = 0; i <
ONE_DIM; ++i)
93 i < PtypeTraits<ROOK>::indexLimit;
133template <
bool Opening>
136template <
bool Opening>
146template <
bool Opening>
154template <
bool Opening>
155template <osl::Ptype PTYPE>
161 i < PtypeTraits<PTYPE>::indexLimit;
168 const int weight =
table[
index(state, piece)];
178template <
bool Opening>
207template<osl::Player P>
226 uPtypeO=(
PtypeO)(
static_cast<int>(uPtypeO)^(~15));
227 dPtypeO=(
PtypeO)(
static_cast<int>(dPtypeO)^(~15));
228 rPtypeO=(
PtypeO)(
static_cast<int>(rPtypeO)^(~15));
229 lPtypeO=(
PtypeO)(
static_cast<int>(lPtypeO)^(~15));
238 assert((myKing.
y()-dp.
y())<(myKing.
y()-up.
y()));
239 assert((myKing.
x()-lp.
x())<(myKing.
x()-rp.
x()));
273 result+=
evalOne<BLACK>(state,pos,kings[0],kings[1],up,dp,rp,lp,isP);
275 result-=
evalOne<WHITE>(state,pos,kings[1],kings[0],dp,up,lp,rp,isP);
282 for (
size_t i = 0; i <
ONE_DIM; ++i)
291 for (
size_t i = 0; i < 32; ++i)
303 for (
size_t i = 0; i <
ONE_DIM; ++i)
307 piece_attack_table[i][s] = weights.
value(i +
ONE_DIM*2*s);
311 for(
int isP=0;isP<2;isP++)
312 for(
int y_diff=-9;y_diff<=9;y_diff++)
313 for(
int x_diff= -9;x_diff<=9;x_diff++){
314 int i2=
index2(x_diff,y_diff,isP);
315 if(abs(x_diff)<9 && abs(y_diff)<9){
326 int indexPieceH,indexPieceV;
327 int table_ptypeo=ptypeo;
330 indexPieceH= 0+0+(PTYPEO_EDGE-
PTYPEO_MIN)*17*9+4896+isP*9792;
331 indexPieceV= 0+0+(PTYPEO_EDGE-
PTYPEO_MIN)*17*9+ isP*9792;
334 indexPieceH=
index0(abs(x_diff),-y_diff,(
PtypeO)ptypeo,
true,isP);
335 indexPieceV=
index0(abs(x_diff),-y_diff,(
PtypeO)ptypeo,
false,isP);
338 defense_u[i1]=piece_defense_table[indexPieceV];
340 defense_d[i1]=piece_defense_table[indexPieceV];
342 for(
int y_diff_1=y_diff+1;y_diff_1<=8;y_diff_1++){
343 int i=
index(abs(x_diff),y_diff_1,
false,isP);
347 for(
int y_diff_1=std::max(-8,y_diff);y_diff_1<=8;y_diff_1++){
348 int i=
index(abs(x_diff),y_diff_1,
false,isP);
354 defense_l[i1]=piece_defense_table[indexPieceH];
356 defense_r[i1]=piece_defense_table[indexPieceH];
358 for(
int x_diff_1=x_diff+1;x_diff_1<=8;x_diff_1++){
359 int i=
index(abs(x_diff_1),y_diff,
true,isP);
363 for(
int x_diff_1=std::max(-8,x_diff);x_diff_1<=8;x_diff_1++){
364 int i=
index(abs(x_diff_1),y_diff,
true,isP);
380 for (
size_t i = 0; i <
ONE_DIM; ++i)
389 for (
size_t i = 0; i <
ONE_DIM; ++i)
402 i < PtypeTraits<ROOK>::indexLimit;
419 effect_piece.
square().
x() != rookPos.
x())
423 attacked.
ptype() * 9 +
444 effect_piece.
square().
x() != rookPos.
x())
448 attacked.
ptype() * 9 +
478template<osl::Player P>
497 ulPtypeO=(
PtypeO)(
static_cast<int>(ulPtypeO)^(~15));
498 urPtypeO=(
PtypeO)(
static_cast<int>(urPtypeO)^(~15));
499 dlPtypeO=(
PtypeO)(
static_cast<int>(dlPtypeO)^(~15));
500 drPtypeO=(
PtypeO)(
static_cast<int>(drPtypeO)^(~15));
543 result+=
evalOne<BLACK>(state,pos,kings[0],kings[1],ulp,urp,dlp,drp,isP);
545 result-=
evalOne<WHITE>(state,pos,kings[1],kings[0],drp,dlp,urp,ulp,isP);
552 for (
size_t i = 0; i <
ONE_DIM; ++i)
561 for (
size_t i = 0; i < 32; ++i)
574 for (
size_t i = 0; i <
ONE_DIM; ++i)
578 piece_attack_table[i][s] = weights.
value(i +
ONE_DIM * 2 * s);
582 for(
int isP=0;isP<2;isP++)
583 for(
int y_diff=-9;y_diff<=9;y_diff++)
584 for(
int x_diff= -9;x_diff<=9;x_diff++){
585 int i2=
index2(x_diff,y_diff,isP);
586 if(abs(x_diff)<9 && abs(y_diff)<9){
597 int indexPieceUR,indexPieceUL;
598 int table_ptypeo=ptypeo;
601 indexPieceUR= 0+0+(PTYPEO_EDGE-
PTYPEO_MIN)*17*9+4896+isP*9792;
602 indexPieceUL= 0+0+(PTYPEO_EDGE-
PTYPEO_MIN)*17*9+ isP*9792;
605 indexPieceUR=
index0(x_diff,y_diff,(
PtypeO)ptypeo,
true,isP);
606 indexPieceUL=
index0(x_diff,y_diff,(
PtypeO)ptypeo,
false,isP);
609 defense_ul[i1]=piece_defense_table[indexPieceUL];
611 defense_dr[i1]=piece_defense_table[indexPieceUL];
613 int y_diff_1=y_diff+1, x_diff_1=x_diff-1;
614 for(;y_diff_1<=8 && x_diff_1>=-8;y_diff_1++,x_diff_1--){
615 if(std::abs(x_diff_1)<=8 && std::abs(y_diff_1)<=8){
616 int i=
index(x_diff_1,y_diff_1,
false,isP);
623 int y_diff_1=y_diff, x_diff_1=x_diff;
624 for(;y_diff_1<=8 && x_diff_1>=-8;y_diff_1++,x_diff_1--){
625 if(std::abs(x_diff_1)<=8 && std::abs(y_diff_1)<=8){
626 int i=
index(x_diff_1,y_diff_1,
false,isP);
633 defense_ur[i1]=piece_defense_table[indexPieceUR];
635 defense_dl[i1]=piece_defense_table[indexPieceUR];
637 int y_diff_1=y_diff+1, x_diff_1=x_diff+1;
638 for(;y_diff_1<=8 && x_diff_1<=8;y_diff_1++,x_diff_1++){
639 if(std::abs(x_diff_1)<=8 && std::abs(y_diff_1)<=8){
640 int i=
index(x_diff_1,y_diff_1,
true,isP);
647 int y_diff_1=y_diff, x_diff_1=x_diff;
648 for(;y_diff_1<=8 && x_diff_1<=8;y_diff_1++,x_diff_1++){
649 if(std::abs(x_diff_1)<=8 && std::abs(y_diff_1)<=8){
650 int i=
index(x_diff_1,y_diff_1,
true,isP);
666 for (
size_t i = 0; i <
ONE_DIM; ++i)
676 for (
size_t i = 0; i <
ONE_DIM; ++i)
681 for(
int x_diff=0;x_diff<=8;x_diff++)
682 for(
int y_diff=-8;y_diff<=8;y_diff++){
683 for(
int i=0;i<32;i++)
688 for(
int x_diff=0;x_diff<=8;x_diff++)
689 for(
int y_diff=-8;y_diff<=8;y_diff++){
699 for (
size_t i = 0; i <
ONE_DIM; ++i)
711 i < PtypeTraits<BISHOP>::indexLimit;
723 std::abs(pos.
x() - king.
x()),
730 else if(pos.
y()<=8) {
736 std::abs(pos.
x() - king.
x()),
752 for (
size_t i = 0; i <
ONE_DIM; ++i)
759template<osl::Player P>
766 i < PtypeTraits<ROOK>::indexLimit;
775 j < PtypeTraits<BISHOP>::indexLimit;
803 for (
size_t i = 0; i <
ONE_DIM; ++i)
814 for (
size_t i = 0; i <
ONE_DIM; ++i)
825 for (
size_t i = 0; i <
ONE_DIM; ++i)
838 i < PtypeTraits<BISHOP>::indexLimit;
849 bishop, self, opp, all);
865 int &self_count,
int &opp_count,
int &total_count)
871 self_count = opp_count = total_count = 8;
875 assert(king.
x() != bishop.
square().
x());
876 assert(king.
y() != bishop.
square().
y());
901 self_count = opp_count = total_count = 0;
903 pos != king; pos =
Board_Table.nextSquare(player, pos, move_dir))
905 assert(pos.isOnBoard());
910 if (piece.
owner() == player)
925 for (
size_t i = 0; i <
ONE_DIM; ++i)
978 const bool black_with_support =
981 const bool white_with_support =
987 white_with_support)];
992 black_with_support)];
1005 for (
size_t i = 0; i <
ONE_DIM; ++i)
1010 for (
int owner = 0; owner < 2; ++owner)
1012 const bool same_player = (owner == 0);
1013 for (
int y1 = 0; y1 < 10; ++y1)
1015 for (
int y2 = 0; y2 < 10; ++y2)
1017 for (
int promoted1 = 0; promoted1 < 2; ++promoted1)
1019 for (
int promoted2 = 0; promoted2 < 2; ++promoted2)
1025 int promoted1p = promoted1;
1026 int promoted2p = promoted2;
1027 if (y1 > y2 || (y1 == y2 && !promoted1 && promoted2))
1029 std::swap(y1p, y2p);
1030 std::swap(promoted1p, promoted2p);
1032 table[
index(same_player, promoted1, promoted2,
1034 orig_table[
index(same_player, promoted1p, promoted2p,
1039 if (y1 + y2 > 10 || y1 == 0 ||
1040 (y1 + y2 == 10 && promoted1))
1042 const int idx =
index(same_player, promoted1, promoted2,
1044 table[idx] = orig_table[idx];
1048 table[
index(same_player, promoted1, promoted2,
1050 -orig_table[
index(same_player, promoted2, promoted1,
1051 (10 - y2) % 10, (10 - y1) % 10)];
1082 std::swap(rook1, rook2);
1096 for (
size_t i = 0; i <
ONE_DIM; ++i)
1117 bool vertical =
false;
1152 const bool black_with_support =
1155 const bool white_with_support =
1161 white_with_support, vertical)];
1166 black_with_support, vertical)];
1179 for (
size_t i = 0; i <
ONE_DIM; ++i)
1211 for (
size_t i = 0; i <
ONE_DIM; ++i)
1218template <osl::Player Owner>
1225 pieces &= ~state.effectedMask(Owner);
1227 while (pieces.
any()) {
1261 for (
size_t i = 0; i <
ONE_DIM; ++i)
1273 i < PtypeTraits<ROOK>::indexLimit;
1282 i < PtypeTraits<SILVER>::indexLimit;
1292 i < PtypeTraits<KNIGHT>::indexLimit;
1345 for (
size_t i = 0; i <
ONE_DIM; ++i)
1357 i < PtypeTraits<BISHOP>::indexLimit;
1366 i < PtypeTraits<SILVER>::indexLimit;
1376 i < PtypeTraits<KNIGHT>::indexLimit;
1429 for (
size_t i = 0; i <
ONE_DIM; ++i) {
1437template <osl::Player P>
1445 typedef std::pair<Offset,Square> pair_t;
1457 const bool rook_support = state.
hasEffectAt(P, sq);
1458 for (pair_t pair: bishop_attack) {
1459 const Square attack_square = pair.second;
1460 if (! state[attack_square].isEmpty()
1463 const Square bishop_square = attack_square + pair.first;
1464 Piece p = state[bishop_square];
1473 has_gold, rook_support,
const NumBitmapEffect effectSetAt(Square sq) const
const PieceMask effectedMask(Player pl) const
pl からの利きが(1つ以上)ある駒一覧
bool hasEffectNotBy(Player player, Piece piece, Square target) const
対象とするマスにあるプレイヤーの(ただしある駒以外)利きがあるかどうか.
int countEffect(Player player, Square target) const
利きの数を数える.
bool hasEffectAt(Square target) const
対象とするマスにあるプレイヤーの利きがあるかどうか.
bool hasLongEffectAt(Player P, Square to) const
あるマスにPTYPEの長い利きがあるかどうか.
const Piece findCheapAttack(Player P, Square square) const
Square mobilityOf(Direction d, int num) const
bool hasEffectIf(PtypeO ptypeo, Square attacker, Square target) const
attackerにptypeoの駒がいると仮定した場合にtargetに利きがあるかどうか を stateをupdateしないで確かめる.
const PieceMask & piecesOnBoard(Player p) const
bool hasEffectByPtype(Player attack, Square target) const
target に ptype の利きがあるか?
bool isPromoted() const
promoteした駒かどうかをチェックする
const Square square() const
bool isPlayerPtype(Player pl, Ptype ptype) const
あるpieceがPlayer pの持ち物でPtype ptypeであるかどうかをチェックする. TはEMPTY, EDGEではない.
bool canMoveOn() const
Player Pの駒が,thisの上に移動できるか?
bool isOnBoardNotPromoted() const
promoteしていないOnBoardの駒であることのチェック Lance位しか使い道がない?
bool hasPieceOnStand(Player player, Ptype ptype) const
const Piece nth(int n) const
unpromote(PTYPE)のn番目の駒を帰す.
const Piece pieceOf(int num) const
Square kingSquare() const
bool isPawnMaskSet(Player player, int x) const
const Piece pieceAt(Square sq) const
const Square rotate180EdgeOK() const
int y() const
将棋としてのY座標を返す.
const Square neighbor() const
const Square rotate180() const
const Square squareForBlack(Player player) const
bool isOnBoard() const
盤面上を表すかどうかの判定. 1<=x() && x()<=9 && 1<=y() && y()<=9 Squareの内部表現に依存する.
int x() const
将棋としてのX座標を返す.
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 MultiInt eval(const NumEffectState &state)
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 MultiInt eval(const NumEffectState &state)
static CArray< MultiInt, 612 > defense_table
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 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 MultiInt eval(const NumEffectState &state)
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 MultiInt eval(const NumEffectState &state)
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 MultiInt eval(const NumEffectState &state)
static void setUp(const Weights &weights)
static void setUp(const Weights &weights)
static CArray< MultiInt, 32 > table
static MultiInt eval(const NumEffectState &state)
static MultiInt eval(const NumEffectState &state)
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 MultiInt eval(const NumEffectState &state)
static int eval(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 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 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 MultiInt eval(const NumEffectState &state)
static CArray< MultiInt, 612 > defense_table
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 MultiInt eval(const NumEffectState &state, const CArray2d< int, 2, 9 > &pawns)
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 int eval(const NumEffectState &state)
static void setUp(const Weights &weights)
static CArray< MultiInt, 128 > table
static MultiInt eval(const NumEffectState &state)
static int index(Ptype ptype, bool self_with_support, bool opp_with_support, bool vertical)
static void setUp(const Weights &weights)
static void setUp(const Weights &weights)
static int index(Piece rook1, Piece rook2)
static MultiInt eval(const NumEffectState &state)
static CArray< MultiInt, 800 > table
static void setUp(const Weights &weights)
static CArray< MultiInt, ONE_DIM > table
static MultiInt eval(const NumEffectState &state)
static size_t index(int rook_x, int rook_y, int silver_x, int silver_y, int knight_x, int knight_y)
const PtypeO PTYPEO_EMPTY
CArray< CArray< T, Capacity2 >, Capacity1 > CArray2d
Ptype getPtype(PtypeO ptypeO)
const BoardTable Board_Table
unsigned int ptypeOIndex(PtypeO ptypeo)
PtypeO
Player + Ptype [-15, 15] PtypeO の O は Owner の O.
constexpr Player alt(Player player)
PtypeO newPtypeO(Player player, Ptype ptype)
PtypeO altIfPiece(PtypeO ptypeO)
Pieceの時にはowner を反転する
constexpr Direction inverse(Direction d)
int value(size_t index) const
static int countHorizontalAll(const NumEffectState &state, int num)