8 for (
size_t i = 0; i <
ONE_DIM; ++i)
40 for (
int i = 0; i <
ONE_DIM; ++i)
49 for (
int i = 0; i <
ONE_DIM; ++i)
58 for (
int i = 0; i <
ONE_DIM; ++i)
67 for (
int i = 0; i <
ONE_DIM; ++i)
75 for (
int i = 0; i <
ONE_DIM; ++i)
84 for (
int i = 0; i <
ONE_DIM; ++i)
93 for (
int i = 0; i <
ONE_DIM; ++i)
110 for (
int x = 1; x <= 9; ++x)
116 const int attack_index =
index(kings[
WHITE], x);
117 const int defense_index =
index(kings[
BLACK], x);
118 const int attack_index_x =
120 const int defense_index_x =
124 result +=
value(attack_index, defense_index,
125 attack_index_y, defense_index_y,
126 attack_index_x, defense_index_x);
129 result +=
standValue(attack_index, defense_index,
130 attack_index_y, defense_index_y,
131 attack_index_x, defense_index_x);
136 const int attack_index =
index(kings[
BLACK], x);
137 const int defense_index =
index(kings[
WHITE], x);
138 const int attack_index_x =
140 const int defense_index_x =
144 result -=
value(attack_index, defense_index,
145 attack_index_y, defense_index_y,
146 attack_index_x, defense_index_x);
149 result -=
standValue(attack_index, defense_index,
150 attack_index_y, defense_index_y,
151 attack_index_x, defense_index_x);
154 const int index_x = (x > 5 ? 10 - x : x);
155 if (black_on_board && white_on_board)
164 else if (black_on_board && !white_on_board)
175 else if (!black_on_board && white_on_board)
216 for (
size_t i = 0; i < weights.
dimension(); ++i) {
226 i < PtypeTraits<PAWN>::indexLimit; ++i)
241template <osl::Player P>
inline
251template <osl::Player P>
256 assert(moved.
player() == P);
304 for (
size_t i = 0; i <
ONE_DIM; ++i)
318 i < PtypeTraits<SILVER>::indexLimit; ++i)
332template<osl::Player P>
339 assert(silver.
owner()==P);
363 for (
size_t i = 0; i < weights.
dimension(); ++i) {
379 for (
size_t i = 0; i <
ONE_DIM; ++i)
389 for (
size_t i = 0; i <
ONE_DIM; ++i)
403 i < PtypeTraits<GOLD>::indexLimit; ++i)
420template<osl::Player P>
427 assert(P==gold.
owner());
445 for (
size_t i = 0; i < weights.
dimension(); ++i) {
454template<osl::Player P>
462 assert(P==knight.
owner());
478 for (
size_t i = 0; i < weights.
dimension(); ++i) {
488 i < PtypeTraits<KNIGHT>::indexLimit; ++i)
519 for (
size_t i = 0; i < weights.
dimension(); ++i)
541template<osl::Player P>
581 for (
size_t i = 0; i < weights.
dimension(); ++i)
603template<osl::Player P>
644 for (
size_t i = 0; i <
ONE_DIM; ++i)
658 result +=
value(index_y);
663 result -=
value(index_y);
674 for (
size_t i = 0; i <
ONE_DIM; ++i)
684 for (
size_t i = 0; i <
ONE_DIM; ++i)
696 i < PtypeTraits<PAWN>::indexLimit; ++i)
709 const int idx =
index(pawn.
owner(), up_p, up_up_p);
710 const int idx_y =
indexY(pawn.
owner(), up_p, up_up_p,
721template<osl::Player P>
723#if (defined __GNUC__ && ! defined __clang__)
731 assert(moved.
player()==P);
742 up_up_p, moved.
from().
y());
751 moved.
from().
y() + 1)
760 moved.
from().
y() + 1);
762 if (up_up != moved.
to())
766 moved.
from().
y() + 1);
771 moved.
from().
y() + 2)
779 moved.
from().
y() + 2);
781 if (moved.
to() != up)
785 moved.
from().
y() + 2);
793 moved.
from().
y() - 1)
802 moved.
from().
y() - 1);
804 if (moved.
to() != up_up)
808 moved.
from().
y() - 1);
813 moved.
from().
y() - 2)
821 moved.
from().
y() - 2);
823 if (moved.
to() != up)
827 moved.
from().
y() - 2);
844 const int i =
index(
alt(P), up_p, up_up_p);
845 const int i_y =
indexY(
alt(P), up_p, up_up_p,
866 const int i =
index(P, up_p, up_up_p);
867 const int i_y =
indexY(P, up_p, up_up_p, moved.
to().
y());
877 if (pawns[
BLACK][moved.
to().
x() - 1] != 0)
879 if (pawns[
BLACK][moved.
to().
x() - 1] ==
894 up_up_p, moved.
to().
y() + 1);
898 if (pawns[
BLACK][moved.
to().
x() - 1] ==
916 if (pawns[
WHITE][moved.
to().
x() - 1] != 0)
918 if (pawns[
WHITE][moved.
to().
x() - 1] ==
929 if (up_up != moved.
from())
937 if (pawns[
WHITE][moved.
to().
x() - 1] ==
966 for (
size_t i = 0; i <
ONE_DIM; ++i)
976 for (
size_t i = 0; i <
ONE_DIM; ++i)
993template <osl::Player P>
1004 while (attack.
any())
1007 const int x_diff = (P ==
BLACK ? p.
square().x() - king.
x() :
1011 if (x_diff > min_left)
1013 if (min_left != -10)
1038 if (x_diff < min_right)
1040 if (min_right != 10)
1053 else if (x_diff != 0)
1075 if (promoted_pieces.
none())
1104 for (
size_t i = 0; i <
ONE_DIM; ++i)
1114 for (
size_t i = 0; i <
ONE_DIM; ++i)
1119 for(
int x_diff=0;x_diff<9;x_diff++)
1120 for(
int y_diff= -8;y_diff<=8;y_diff++)
1121 for(
int has_support=0;has_support<2;has_support++)
1122 for(
int same_turn=0;same_turn<2;same_turn++)
1124 int index=((ptype + (same_turn ? 0 :
PTYPE_SIZE) +
1125 (has_support ? 0 :
PTYPE_SIZE*2))* 9 + x_diff) * 17 +
1127 int index0=ptype + (same_turn ? 0 :
PTYPE_SIZE) +
1136 int black_turn_king_defense,
1137 int white_turn_king_attack,
1138 int white_turn_king_defense,
1167 PieceMask black_without_support = (~state.effectedMask(
BLACK)) & black_attacked;
1168 while (black_with_support.
any())
1171 const int index_king_black_turn_attack =
1173 const int index_king_white_turn_attack =
1175 const int index_king_black_turn_defense =
1177 const int index_king_white_turn_defense =
1179 adjust<1>(index_king_black_turn_attack, index_king_black_turn_defense,
1180 index_king_white_turn_attack, index_king_white_turn_defense,
1183 while (black_without_support.
any())
1186 const int index_king_black_turn_attack =
1188 const int index_king_white_turn_attack =
1190 const int index_king_black_turn_defense =
1192 const int index_king_white_turn_defense =
1194 adjust<1>(index_king_black_turn_attack, index_king_black_turn_defense,
1195 index_king_white_turn_attack, index_king_white_turn_defense,
1205 PieceMask white_without_support = (~state.effectedMask(
WHITE)) & white_attacked;
1206 while (white_with_support.
any())
1209 const int index_king_black_turn_attack =
1211 const int index_king_white_turn_attack =
1213 const int index_king_black_turn_defense =
1215 const int index_king_white_turn_defense =
1217 adjust<-1>(index_king_black_turn_attack, index_king_black_turn_defense,
1218 index_king_white_turn_attack, index_king_white_turn_defense,
1221 while (white_without_support.
any())
1224 const int index_king_black_turn_attack =
1226 const int index_king_white_turn_attack =
1228 const int index_king_black_turn_defense =
1230 const int index_king_white_turn_defense =
1232 adjust<-1>(index_king_black_turn_attack, index_king_black_turn_defense,
1233 index_king_white_turn_attack, index_king_white_turn_defense,
1238template<osl::Player P>
1248 eval(state, result);
1253 effected_mask[0].clearBit<
KING>();
1254 effected_mask[1].clearBit<
KING>();
1263 new_mask[1].template selectBit<PAWN>() & state.
promotedPieces().template getMask<PAWN>();
1264 new_mask[0].clearBit<
PAWN>();
1265 new_mask[1].clearBit<
PAWN>();
1268 new_mask[0].clearBit<
KING>();
1269 new_mask[1].clearBit<
KING>();
1273 assert(p.
owner()==P);
1276 if (effected_mask[
alt(P)].test(p.
number()))
1278 const bool has_support = effected_mask[P].test(p.
number());
1279 const int index_king_black_turn_attack =
1282 const int index_king_white_turn_attack =
1285 const int index_king_black_turn_defense =
1288 const int index_king_white_turn_defense =
1292 adjust<-1>(index_king_black_turn_attack, index_king_black_turn_defense,
1293 index_king_white_turn_attack, index_king_white_turn_defense,
1296 adjust<1>(index_king_black_turn_attack, index_king_black_turn_defense,
1297 index_king_white_turn_attack, index_king_white_turn_defense,
1303 const bool has_support = new_mask[P].test(p.
number());
1304 const int index_king_black_turn_attack =
1307 const int index_king_white_turn_attack =
1310 const int index_king_black_turn_defense =
1313 const int index_king_white_turn_defense =
1317 adjust<1>(index_king_black_turn_attack, index_king_black_turn_defense,
1318 index_king_white_turn_attack, index_king_white_turn_defense,
1321 adjust<-1>(index_king_black_turn_attack, index_king_black_turn_defense,
1322 index_king_white_turn_attack, index_king_white_turn_defense,
1329 effected_mask[P] & (~state.piecesOnBoard(
BLACK)) &
1330 (~state.piecesOnBoard(
WHITE));
1332 const bool has_support = effected_mask[
alt(P)].test(captured_mask.
takeOneBit());
1333 const int index_king_black_turn_attack =
1336 const int index_king_white_turn_attack =
1339 const int index_king_black_turn_defense =
1342 const int index_king_white_turn_defense =
1346 adjust<1>(index_king_black_turn_attack, index_king_black_turn_defense,
1347 index_king_white_turn_attack, index_king_white_turn_defense,
1350 adjust<-1>(index_king_black_turn_attack, index_king_black_turn_defense,
1351 index_king_white_turn_attack, index_king_white_turn_defense,
1368 for (
size_t i = 0; i <
ONE_DIM; ++i)
1378 for (
size_t i = 0; i <
ONE_DIM; ++i)
1390 i < PtypeTraits<KNIGHT>::indexLimit;
1408 const int y = knight.
square().
y();
1411 result +=
table[y - 1];
1415 result -=
table[9 - y];
1423 const int index = up_piece.
ptype() * 9 + y - 1;
1444 for (
size_t i = 0; i <
ONE_DIM; ++i)
1462 while (black_attacked.
any())
1468 attacked_mask[piece.
number()] = attacking;
1470 while (attacking.
any())
1473 const int index_black_turn =
index(
true, with_support,
1475 const int index_white_turn =
index(
false, with_support,
1477 adjust<1>(index_black_turn, index_white_turn, result);
1485 while (white_attacked.
any())
1491 attacked_mask[piece.
number()] = attacking;
1492 while (attacking.
any())
1495 const int index_black_turn =
index(
false, with_support,
1497 const int index_white_turn =
index(
true, with_support,
1499 adjust<-1>(index_black_turn, index_white_turn, result);
1504template<osl::Player P>
1514 effected_mask[0].clearBit<
KING>();
1515 effected_mask[1].clearBit<
KING>();
1524 new_mask[0].clearBit<
PAWN>();
1525 new_mask[1].clearBit<
PAWN>();
1528 new_mask[0].clearBit<
KING>();
1529 new_mask[1].clearBit<
KING>();
1531 assert(p.owner()==P);
1532 assert(moved.
player()==P);
1534 int captured_number = -1;
1538 effected_mask[P] & (~state.piecesOnBoard(
BLACK)) &
1539 (~state.piecesOnBoard(
WHITE));
1540 captured_number = captured_mask.
takeOneBit();
1544 if (effected_mask[
alt(P)].test(p.number()))
1546 const bool has_support = effected_mask[P].test(p.number());
1547 PieceMask attacking = attacked_mask[p.number()];
1548 if (captured_number != -1)
1550 if (attacking.
test(captured_number))
1555 has_support, result);
1560 has_support, result);
1562 attacking.
reset(captured_number);
1565 while (attacking.
any())
1571 has_support, result);
1576 has_support, result);
1581 if (new_mask[
alt(P)].test(p.number()))
1583 const bool has_support = new_mask[P].test(p.number());
1586 attacked_mask[p.number()] = attacking;
1587 while (attacking.
any())
1593 has_support, result);
1598 has_support, result);
1602 if (captured_number != -1)
1604 const bool has_support = effected_mask[
alt(P)].test(captured_number);
1605 PieceMask attacking = attacked_mask[captured_number];
1606 if (attacking.
test(p.number()))
1611 has_support, result);
1616 has_support, result);
1618 attacking.
reset(p.number());
1620 while (attacking.
any())
1626 has_support, result);
1631 has_support, result);
1636 effected_mask, new_mask, attacked_mask, result);
1638 effected_mask, new_mask, attacked_mask, result);
1645 for (
int i = 0; i <
ONE_DIM; ++i)
1655template <osl::Player Owner>
1666 while (attacked.
any())
1671 for (
size_t i=0; i+1<pieces.
size(); ++i) {
1672 const int i0 =
index1(state, pieces[i]);
1673 for (
size_t j=i+1; j<pieces.
size(); ++j) {
1674 const int i1 =
index1(state, pieces[j]);
1703 for (
size_t i = 0; i <
ONE_DIM; ++i)
1712 for (
size_t i = 0; i <
ONE_DIM; ++i)
1720 int size=
Ptype_Table.getIndexLimit(ptype)-indexMin;
1721 for(
int x=0;x<5;x++){
1722 for(
int j=0;j<size;j++){
1723 for(
int k=0;k<160;k+=40){
1732 int size=
Ptype_Table.getIndexLimit(ptype)-indexMin;
1733 for(
int x=0;x<5;x++){
1734 for(
int k=0;k<160;k+=40)
1736 for(
int j=1;j<size;j++){
1737 for(
int k=0;k<160;k+=40)
1741 for(
int y=0;y<9;y++){
1742 for(
int k=0;k<160;k+=40)
1744 for(
int j=1;j<size;j++){
1745 for(
int k=0;k<160;k+=40)
1754 for (
size_t i = 0; i <
ONE_DIM; ++i)
1762 int size=
Ptype_Table.getIndexLimit(ptype)-indexMin;
1763 for(
int x=0;x<5;x++){
1764 for(
int k=0;k<160;k+=40)
1766 for(
int j=1;j<size;j++){
1767 for(
int k=0;k<160;k+=40)
1771 for(
int y=0;y<9;y++){
1772 for(
int k=0;k<160;k+=40)
1774 for(
int j=1;j<size;j++){
1775 for(
int k=0;k<160;k+=40)
1782template<osl::Player P,osl::Ptype T>
1791 int j=
static_cast<int>(T);
1792 if (ptype_count[i][j] != 0)
1794 const int index_x =
indexCountX<T>(ptype_count[i][j], kings_x[i]);
1795 const int index_y =
indexCountY<T>(ptype_count[i][j], kings_y[i]);
1796 const int index_x_attack =
1798 const int index_y_attack =
1812 if (ptype_board_count[i][j] != 0)
1818 const int index_x_attack =
1820 const int index_y_attack =
1840#if (defined __GNUC__ && ! defined __clang__)
1855 kings_x[0] = 10 - kings_x[0];
1857 kings_x[1] = 10 - kings_x[1];
1887template<osl::Player P>
1894 unsigned int &ptypeo_mask)
1896 assert(last_move.
player()==P);
1903 kings_x[0] = 10 - kings_x[0];
1905 kings_x[1] = 10 - kings_x[1];
1913 if(--ptype_count[altP][capturedPtype]==0)
1915 --ptype_board_count[altP][capturedPtype];
1917 ++ptype_count[P][base_captured];
1920 eval(state, ptype_count, ptype_board_count, last_value_and_out);
1927 const int count = ++ptype_board_count[P][last_move.
ptype()];
1928 sum =
valueBoardAll(last_move.
ptype(),count,kings_x[P],kings_y[P],kings_x[altP],kings_y[altP]);
1934 const int count = --ptype_count[altP][capturedPtype];
1937 const int board_count = --ptype_board_count[altP][capturedPtype];
1939 const int c_count = ++ptype_count[P][base_captured];
1941 sum=
valueAll(capturedPtype,count+1,kings_x[altP],kings_y[altP],kings_x[P],kings_y[P])+
1942 valueBoardAll(capturedPtype,board_count+1,kings_x[altP],kings_y[altP],kings_x[P],kings_y[P])+
1943 valueAll(base_captured,c_count,kings_x[P],kings_y[P],kings_x[altP],kings_y[altP]);
1949 const int base_count = --ptype_count[P][old_ptype];
1950 const int base_board_count = --ptype_board_count[P][old_ptype];
1951 const int count = ++ptype_count[P][new_ptype];
1952 const int board_count = ++ptype_board_count[P][new_ptype];
1956 sum+=
valueAll(new_ptype,count,kings_x[P],kings_y[P],kings_x[altP],kings_y[altP])+
1957 valueBoardAll(new_ptype,board_count,kings_x[P],kings_y[P],kings_x[altP],kings_y[altP])-
1958 valueAll(old_ptype,base_count+1,kings_x[P],kings_y[P],kings_x[altP],kings_y[altP])-
1959 valueBoardAll(old_ptype,base_board_count+1,kings_x[P],kings_y[P],kings_x[altP],kings_y[altP]);
1962 if(P==
BLACK) last_value_and_out+= sum;
1963 else last_value_and_out-= sum;
1969 for (
size_t i = 0; i <
ONE_DIM; ++i)
1984 i < PtypeTraits<LANCE>::indexLimit;
1996 const int index1 = 0 + 0 + (PTYPEO_EDGE -
PTYPEO_MIN) * 17 * 9;
1997 const int index2 = 0 + 0 + (PTYPEO_EDGE -
PTYPEO_MIN) * 17 * 9 + 4896;
2000 result +=
table[index1];
2001 result +=
table[index2];
2005 result -=
table[index1];
2006 result -=
table[index2];
2011 const int index1 =
index(lance.
owner(), p, opp_king,
2013 const int index2 =
index(lance.
owner(), p, self_king,
2017 result +=
table[index1];
2018 result +=
table[index2];
2022 result -=
table[index1];
2023 result -=
table[index2];
2036 for (
size_t i = 0; i <
ONE_DIM; ++i)
2038 for (
int s = 0; s <
NStages; ++s)
2063 result +=
table[idx];
2067 result -=
table[idx];
2074template<osl::Player P>
2082 assert(P==moved.
player());
2086 const int x = moved.
to().
x();
2087 const int old_pawn_y = (moved.
isDrop() ? 0 : moved.
from().
y());
2088 const int new_pawn_y = pawns[P][moved.
to().
x() - 1];
2089 for (
int y = 1; y <= 9; ++y)
2092 if (y == moved.
to().
y())
2096 const int idx_new =
index(P, p.
ptype(), y, new_pawn_y);
2099 last_value +=
table[idx_new];
2103 last_value -=
table[idx_new];
2109 const int idx_old =
index(P, p.
ptype(), y, old_pawn_y);
2110 const int idx_new =
index(P, p.
ptype(), y, new_pawn_y);
2113 last_value -=
table[idx_old];
2114 last_value +=
table[idx_new];
2118 last_value +=
table[idx_old];
2119 last_value -=
table[idx_new];
2128 const int pawn_y = pawns[P][moved.
from().
x() - 1];
2133 last_value -=
table[idx];
2137 last_value +=
table[idx];
2141 const int pawn_y = pawns[P][moved.
to().
x() - 1];
2146 last_value +=
table[idx];
2150 last_value -=
table[idx];
2159 const int old_pawn_y = moved.
to().
y();
2160 const int new_pawn_y = 0;
2161 const int x = moved.
to().
x();
2162 for (
int y = 1; y <= 9; ++y)
2173 last_value +=
table[idx_old];
2174 last_value -=
table[idx_new];
2178 last_value -=
table[idx_old];
2179 last_value +=
table[idx_new];
2186 const int pawn_y = pawns[
alt(P)][moved.
to().
x() - 1];
2191 last_value +=
table[idx];
2195 last_value -=
table[idx];
2209 for (
size_t i = 0; i <
ONE_DIM; ++i)
2219 for (
size_t i = 0; i <
ONE_DIM; ++i)
2227template <osl::Player P>
2235 for (
size_t i = 0; i < gs_count[0].
size(); ++i)
2237 total += gs_count[P][i];
2245 gs_count[P][1], gs_count[P][2])];
2246 return P ==
BLACK ? result : -result;
2264 for (
size_t i = 0; i <
ONE_DIM; ++i)
2266 for (
int s = 0; s <
NStages; ++s)
2271 for(
int i=0;i<8192;i++){
2274 int lance=(i>>11)&1;
2275 int plance=(i>>5)&1;
2276 int knight=(i>>10)&1;
2277 int pknight=(i>>4)&1;
2278 int silver=(i>>9)&1;
2279 int psilver=(i>>3)&1;
2280 int bishop=(i>>8)&1;
2281 int pbishop=(i>>2)&1;
2285 int newIndex=ppawn|(plance<<1)|(pknight<<2)|(psilver<<3)|(pbishop<<4)|
2286 (prook<<5)|(gold<<6)|(pawn<<7)|(lance<<8)|(knight<<9)|(silver<<10)|
2287 (bishop<<11)|(rook<<12);
2288 table[newIndex]=orig_table[i];
2309 return std::make_pair(0,0);
2312 return std::make_pair(0,0);
2316 for (
size_t i=0; i<offset.
size(); ++i) {
2317 const Square next = sq+offset[i], next2 = next+offset[i];
2325 return std::make_pair(
sign(owner), 0);
2327 return std::make_pair(
sign(owner), state.
hasEffectAt(owner, next2) ? 1 : 2);
2329 return std::make_pair(0,0);
2338 return std::make_pair(0,0);
2341 return std::make_pair(0,0);
2345 const bool guarded = state.
hasEffectAt(owner, sq);
2346 for (
size_t i=0; i<offset.
size(); ++i) {
2347 const Square next = sq+offset[i], next2 = next+offset[i];
2358 silver_drop = next_down;
2359 const bool recaputure = guarded
2362 return std::make_pair(
sign(owner), 3 + recaputure);
2365 return std::make_pair(0,0);
2371 silver_drop.fill(std::make_pair(
Square(),0));
2377 if (! has_silver[
BLACK] && ! has_silver[
WHITE])
2381 i < PtypeTraits<ROOK>::indexLimit; ++i)
2384 std::pair<int,int> match =
matchRook(state, rook, has_silver, drop);
2388 if (-value_attack[0] > silver_drop[attack].second) {
2389 silver_drop[attack].second = -value_attack[0];
2390 silver_drop[attack].first = drop;
2392 if (match.first > 0)
2395 result[
WHITE] += value_attack;
2397 else if (match.first < 0)
2399 result[
BLACK] -= value_attack;
2406 i < PtypeTraits<GOLD>::indexLimit; ++i)
2409 std::pair<int,int> match =
matchGold(state, gold, has_silver, drop);
2413 if (-value_attack[0] > silver_drop[attack].second) {
2414 silver_drop[attack].second = -value_attack[0];
2415 silver_drop[attack].first = drop;
2417 if (match.first > 0)
2420 result[
WHITE] += value_attack;
2422 else if (match.first < 0)
2424 result[
BLACK] -= value_attack;
2434 for (
int i = 0; i <
ONE_DIM; ++i)
2445 for (
int i = 0; i <
ONE_DIM; ++i)
2476 return (sq == b) ? drop_position :
Square();
2482 Square center,
bool maybe_empty)
2500 const int cx = b.
x() - a.
x(), cy = b.
y() - a.
y();
2503 const int p = (cx+cy)/2, q = (cx-cy)/2;
2504 if (p == 0 || q == 0)
2511 for (
size_t i=0; i<centers.
size(); ++i) {
2512 if (! centers[i].isOnBoardRegion())
2514 if (
testCenter(state, defense, a, b, king, centers[i], maybe_empty))
2529 if (centers[0] == a || centers[0] == b)
2531 for (
size_t i=0; i<centers.
size(); ++i)
2533 assert(centers[i].isOnBoardRegion());
2534 if (
testCenter(state, defense, a, b, king, centers[i]))
2540template <osl::Player Defense>
2543 std::pair<Square,int>& bishop_drop,
2544 std::pair<Square,int>& rook_drop)
2547 for (
size_t i=0; i<target.
size(); ++i)
2549 const Piece pi = target[i];
2551 for (
size_t j=i+1; j<target.
size(); ++j)
2553 const Piece pj = target[j];
2562 if (-value_attack[0] > bishop_drop.second) {
2563 bishop_drop.second = -value_attack[0];
2564 bishop_drop.first = center;
2566 if (Defense ==
BLACK)
2569 result[
WHITE] += value_attack;
2573 result[
BLACK] -= value_attack;
2585 if (-value_attack[0] > rook_drop.second) {
2586 rook_drop.second = -value_attack[0];
2587 rook_drop.first = center;
2589 if (Defense ==
BLACK)
2592 result[
WHITE] += value_attack;
2596 result[
BLACK] -= value_attack;
2603 assert(bishop_drop.second == 0 || ! bishop_drop.first.isPieceStand());
2609 CArray<std::pair<Square,int>,2>& bishop_drop,
2610 CArray<std::pair<Square,int>,2>& rook_drop)
2612 bishop_drop.fill(std::make_pair(
Square(),0));
2613 rook_drop.fill(std::make_pair(
Square(),0));
2627 notcovered &= ~state.effectedMask(
WHITE);
2633 while (target.
any())
2640 while (target.
any())
2653 for (
int i = 0; i <
ONE_DIM; ++i)
2667template <osl::Player Defense>
2671 std::pair<Square,int>& knight_drop)
2673 knight_fork_squares.
clear();
2675 const int y_min = 3-z*2, y_max = 9-z*2;
2682 while (target.
any()) {
2685 pieces[y].push_back(p);
2689 for (
int y=y_min; y<=y_max; ++y){
2690 if (pieces[y].size() < 2)
2692 const int y_drop = y -
sign(Defense)*2;
2693 for (
size_t i=0; i<pieces[y].
size(); ++i)
2695 const Piece pi = pieces[y][i];
2698 const int xi = pi.
square().
x();
2699 for (
size_t j=i+1; j<pieces[y].
size(); ++j)
2701 const Piece pj = pieces[y][j];
2704 const int xj = pj.
square().
x();
2705 if (abs(xi -xj) != 2)
2708 knight_fork_squares.
set(drop);
2709 if (! state[drop].isEmpty() || state.
hasEffectAt(Defense, drop))
2716 if (Defense ==
BLACK)
2719 result[
WHITE] += value_attack;
2723 result[
BLACK] -= value_attack;
2726 if (has_knight && -value_attack[0] > knight_drop.second) {
2727 knight_drop.second = -value_attack[0];
2739 CArray<std::pair<Square,int>,2>& knight_drop)
2741 knight_drop.fill(std::make_pair(
Square(),0));
2759 + may_have_knight[
BLACK] + may_have_knight[
WHITE] == 0) {
2760 knight_fork_squares[
BLACK].invalidate();
2761 knight_fork_squares[
WHITE].invalidate();
2766 if (has_knight[
alt(Defense)] + may_have_knight[
alt(Defense)] > 0)
2768 knight_fork_squares[
alt(Defense)],
2769 knight_drop[
alt(Defense)]);
2771 knight_fork_squares[
alt(Defense)].invalidate();
2775 if (has_knight[
alt(Defense)] + may_have_knight[
alt(Defense)] > 0)
2777 knight_fork_squares[
alt(Defense)],
2778 knight_drop[
alt(Defense)]);
2780 knight_fork_squares[
alt(Defense)].invalidate();
2785template <osl::Player P, osl::Player Defense>
2790 assert(! knight_fork_squares.
isInvalid());
2795 if ((Defense ==
BLACK && to.
y() >= 3)
2796 || (Defense ==
WHITE && to.
y() <= 7)) {
2810 || (P ==
BLACK && to.
y() < 3) || (P ==
WHITE && to.
y() > 7))
2815 if (state[l2].isOnBoardByOwner<P>()) {
2816 knight_fork_squares.
set(l.
neighbor<P,
U>().template neighbor<P,U>());
2822 if (state[r2].isOnBoardByOwner<P>()){
2823 knight_fork_squares.
set(r.
neighbor<P,
U>().template neighbor<P,U>());
2828template <osl::Player Defense>
2833 std::pair<Square,int>& knight_drop)
2837 while (mask.
any()) {
2839 if (! state[sq].isEmpty() || state.
hasEffectAt(Defense, sq))
2844 std::cerr << state << Defense <<
' ' << pi <<
' ' << pj <<
"\n";
2846 assert(pj.isOnBoardByOwner<Defense>());
2852 if (Defense ==
BLACK)
2855 result[
WHITE] += value_attack;
2859 result[
BLACK] -= value_attack;
2862 if (has_knight && -value_attack[0] > knight_drop.second) {
2863 knight_drop.second = -value_attack[0];
2864 knight_drop.first = sq;
2870template <osl::Player P>
2874 CArray<std::pair<Square,int>,2>& knight_drop)
2876 knight_drop.fill(std::make_pair(
Square(),0));
2893 + may_have_knight[
BLACK] + may_have_knight[
WHITE] == 0) {
2894 knight_fork_squares[
BLACK].invalidate();
2895 knight_fork_squares[
WHITE].invalidate();
2900 if (has_knight[
alt(Defense)] + may_have_knight[
alt(Defense)] > 0) {
2901 if (knight_fork_squares[
alt(Defense)].isInvalid())
2903 knight_fork_squares[
alt(Defense)],
2904 knight_drop[
alt(Defense)]);
2908 knight_fork_squares[
alt(Defense)],
2909 knight_drop[
alt(Defense)]);
2913 knight_fork_squares[
alt(Defense)].invalidate();
2917 if (has_knight[
alt(Defense)] + may_have_knight[
alt(Defense)] > 0) {
2918 if (knight_fork_squares[
alt(Defense)].isInvalid())
2920 knight_fork_squares[
alt(Defense)],
2921 knight_drop[
alt(Defense)]);
2925 knight_fork_squares[
alt(Defense)],
2926 knight_drop[
alt(Defense)]);
2930 knight_fork_squares[
alt(Defense)].invalidate();
2938 for (
size_t i = 0; i <
ONE_DIM; ++i)
2957 for (
size_t i=0; i<pattern.
size(); ++i) {
2969 for (
size_t i=0; i<pattern.
size(); ++i) {
2970 const Piece p = state.
pieceAt(pattern[i].first.rotate180());
2988 for (
size_t i = 0; i <
ONE_DIM; ++i)
2995template <osl::Player P>
3000 for (
int x=1; x<=9; ++x) {
3001 const Square target(x, rank);
3002 if (! state[target].isEmpty())
3006 if (a > 0 && a == d)
3019 ret +=
table[p-8]*(
sign(P)*(count[p]-1));
3030template <osl::Player P>
3104 unsigned int &ptypeo_mask);
3110 unsigned int &ptypeo_mask);
3114 CArray<std::pair<Square,int>,2>&);
3117 CArray<std::pair<Square,int>,2>&);
void push_back(const T &e)
PtypeO ptypeO() const
移動後のPtype, i.e., 成る手だった場合成った後
PtypeO oldPtypeO() const
移動前のPtypeO, i.e., 成る手だった場合成る前
Ptype capturePtype() const
PtypeO capturePtypeO() const
PtypeO capturePtypeOSafe() const
Ptype oldPtype() const
移動前のPtype, i.e., 成る手だった場合成る前
const Square from() const
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
対象とするマスにあるプレイヤーの利きがあるかどうか.
const Piece findCheapAttack(Player P, Square square) const
Square mobilityOf(Direction d, int num) const
const PieceMask promotedPieces() const
const PieceMask & piecesOnBoard(Player p) const
bool hasEffectByPtypeStrict(Player attack, Square target) const
target に ptype の利きがあるか?
const mask_t getMask(int num) const
void clearBit()
unpromote(PTYPE) の駒のbit を消す
void orMask(int index, mask_t val)
void setBit()
unpromote(PTYPE) の駒のbit を立てる
const mask_t selectBit() const
unpromote(PTYPE) の駒のbit だけ取り出す
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 isOnBoardByOwner() const
piece がプレイヤーPの持ち物でかつボード上にある駒の場合は true.
bool hasPieceOnStand(Player player, Ptype ptype) const
const Piece kingPiece() const
const Piece pieceOf(int num) const
bool isEmptyBetween(Square from, Square to, Offset offset, bool pieceExistsAtTo=false) const
Square kingSquare() const
bool isPawnMaskSet(Player player, int x) const
const Piece pieceAt(Square sq) const
bool isPieceStand() const
int y() const
将棋としてのY座標を返す.
const Square neighbor() const
const Square back() const
bool isOnBoard() const
盤面上を表すかどうかの判定. 1<=x() && x()<=9 && 1<=y() && y()<=9 Squareの内部表現に依存する.
int x() const
将棋としてのX座標を返す.
void reset(unsigned int i)
static void setUp(const Weights &weights, int stage)
static const Square isRookForkSquare(const NumEffectState &state, Player defense, const Square a, const Square b)
static int bishopIndex(Ptype a, Ptype b)
static int rookIndex(Ptype a, Ptype b)
static MultiIntPair eval(const NumEffectState &state, CArray< std::pair< Square, int >, 2 > &bishop_drop, CArray< std::pair< Square, int >, 2 > &rook_drop)
static MultiIntPair evalOne(const NumEffectState &state, const PieceVector &target, std::pair< Square, int > &bishop_drop, std::pair< Square, int > &rook_drop)
static bool testCenter(const NumEffectState &state, Player defense, const Square a, const Square b, Piece king, Square center, bool maybe_empty=false)
static void setUp(const Weights &weights)
static const Square isBishopForkSquare(const NumEffectState &state, Player defense, const Square a, const Square b, bool maybe_empty=false)
static const Square findDropInLine(const NumEffectState &state, Player defense, const Square a, const Square b, Piece king)
static CArray< MultiInt, ONE_DIM > table
static void setUp(const Weights &weights)
static void setUp(const Weights &weights)
static int index(const Square king, int distance0, int count)
static MultiInt eval(const NumEffectState &state, const CArray2d< int, 2, 3 > &gs_count)
static CArray< MultiInt, 9720 > combination_table
static CArray< MultiInt, 1215 > table
static MultiInt evalOne(const NumEffectState &state, const CArray2d< int, 2, 3 > &gs_count)
static int indexCombination(const Square king, int count0, int count1, int count2)
static CArray< MultiInt, 14 > side_table
static MultiInt evalOne(const NumEffectState &state, const Piece gold, const CArray< Square, 2 > &kings)
static MultiInt eval(const NumEffectState &state)
static CArray< MultiInt, 153 > knight_table
static bool canRetreat(const NumEffectState &state, const Piece gold)
static CArray< MultiInt, 9 > retreat_table
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, int stage)
static MultiInt eval(const NumEffectState &state)
static bool cantAdvance(const NumEffectState &state, const Piece knight)
static CArray< MultiInt, 9 > table
static int index(Player P, Square pos)
static void setUp(const Weights &weights)
static void setUp(const Weights &weights, int stage)
static bool canCheck(const NumEffectState &state)
static CArray< MultiInt, 9 > y_table
static MultiInt value(int index_y)
static MultiInt eval(const NumEffectState &state)
static CArray< MultiInt, ONE_DIM > table
static MultiIntPair eval(const NumEffectState &state, CArray< BoardMask, 2 > &knight_fork_squares, CArray< std::pair< Square, int >, 2 > &knight_drop)
static MultiIntPair evalWithUpdate(const NumEffectState &state, Move moved, CArray< BoardMask, 2 > &knight_fork_squares, CArray< std::pair< Square, int >, 2 > &knight_drop)
static void updateSquares(const NumEffectState &state, Move moved, BoardMask &knight_fork_squares)
static MultiIntPair evalOne(const NumEffectState &state, bool has_knight, BoardMask &knight_fork_squares, std::pair< Square, int > &knight_drop)
static int index(Ptype a, Ptype b)
static MultiIntPair accumulate(const NumEffectState &state, bool has_knight, const BoardMask &knight_fork_squares, std::pair< Square, int > &knight_drop)
static void setUp(const Weights &weights)
static bool isTarget(Ptype ptype)
static void setUp(const Weights &weights)
static CArray< MultiInt, 144 > opp_table
static CArray< MultiInt, 9 > table
static MultiInt eval(const NumEffectState &state)
static void setUp(const Weights &weights)
static int index(Player p, Square pos, Square king, PtypeO ptypeO, bool attack)
static void setUp(const Weights &weights)
static MultiInt eval(const NumEffectState &state)
static CArray< MultiInt, 9792 > table
static void setUp(const Weights &weights, int stage)
static void setUp(const Weights &weights)
static int index2(int i0, int i1)
static CArray< MultiInt, ONE_DIM > table
static int index1(const NumEffectState &state, Piece piece)
static void setUp(const Weights &weights)
static MultiInt eval(const NumEffectState &state)
static MultiInt evalOne(const NumEffectState &state)
static void evalWithUpdateBang(const NumEffectState &state, Move moved, const CArray< PieceMask, 2 > &effected_mask, CArray< PieceMask, 40 > &attacked_mask, MultiIntPair &last_value_and_out)
static void evalOnePiece(const Player player, const Ptype ptype, const Ptype attack_ptype, bool with_support, MultiIntPair &result)
static CArray< MultiInt, 1024 > table
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 void setUp(const Weights &weights)
static void eval(const NumEffectState &state, CArray< PieceMask, 40 > &attacked_mask, MultiIntPair &out)
static int index(bool same_turn, bool has_support, Ptype ptype, Ptype attack_ptype)
static void adjust(int black, int white, MultiIntPair &result)
static CArray< MultiInt, 19584 > king_table
static void eval(const NumEffectState &state, MultiIntPair &out)
static void adjust(int black_turn_king_attack, int black_turn_king_defense, int white_turn_king_attack, int white_turn_king_defense, MultiIntPair &result)
static int indexK(Square king, bool same_turn, bool has_support, Square position, Player owner, Ptype ptype)
static CArray< MultiInt, 64 > table
static void setUp(const Weights &weights)
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 void evalWithUpdateBang(const NumEffectState &state, Move moved, const CArray< PieceMask, 2 > &effected_mask, MultiIntPair &last_value_and_out)
static MultiInt eval(const NumEffectState &state)
static CArray< MultiInt, 9 > table
static void setUp(const Weights &weights, int stage)
static int indexY(const Piece king, int x)
static CArray< MultiInt, 81 > defense_y_table
static int index(const Square king, int x)
static CArray< MultiInt, 90 > x_stand_table
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 CArray< MultiInt, 90 > x_table
static CArray< MultiInt, 162 > y_stand_table
static CArray< MultiInt, 81 > attack_y_table
static CArray< MultiInt, 9 > attack_table
static CArray< MultiInt, 36 > state_king_relative_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)
static MultiInt eval(const NumEffectState &state)
static CArray< MultiInt, 10 > drop_non_drop_table
static CArray< MultiInt, 9 > defense_table
static CArray< MultiInt, 18 > stand_table
static int indexX(const Piece king, int x)
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 void setUp(const Weights &weights)
static void setUp(const Weights &weights, int stage)
static void setUp(const Weights &weights, int stage)
static void setUp(const Weights &weights)
static int index(Player P, PtypeO up, PtypeO up_up)
static int indexY(Player P, PtypeO up, PtypeO up_up, int y)
static void setUp(const Weights &weights)
static CArray< MultiInt, 9216 > y_table
static MultiInt evalWithUpdate(const NumEffectState &state, Move moved, const CArray2d< int, 2, 9 > &pawns, const MultiInt &last_value)
static CArray< MultiInt, 1024 > table
static MultiInt eval(const NumEffectState &state)
static void setUp(const Weights &weights)
static MultiInt eval(unsigned int ptypeo_mask)
static MultiInt evalOne(unsigned int ptypeo_mask)
static void setUp(const Weights &weights)
static CArray< MultiInt, 8192 > table
static void setUp(const Weights &weights)
static void setUp(const Weights &weights)
static int indexCountX(Ptype ptype, int count, int x)
static int indexBoardCountX(Ptype ptype, int count, int x)
static CArray< MultiInt, 2240 > xy_attack_table
static MultiInt evalPlayerPtype(const CArray2d< int, 2, PTYPE_SIZE > &ptype_count, const CArray2d< int, 2, PTYPE_SIZE > &ptype_board_count, const osl::CArray< int, 2 > &kings_x, const osl::CArray< int, 2 > &kings_y)
static void setUp(const Weights &weights)
static CArray< MultiInt, 2240 > xy_table_diff
static MultiInt valueBoardAll(Ptype ptype, int count, int my_king_x, int my_king_y, int op_king_x, int op_king_y)
static int indexBoardCountY(Ptype ptype, int count, int y)
static void eval(const NumEffectState &state, const CArray2d< int, 2, PTYPE_SIZE > &ptype_count, const CArray2d< int, 2, PTYPE_SIZE > &ptype_board_count, MultiInt &out)
static CArray< MultiInt, 160 > table
static int indexCountY(Ptype ptype, int count, int y)
static CArray< MultiInt, 2240 > xy_table
static void evalWithUpdateBang(const NumEffectState &state, Move last_move, CArray2d< int, 2, PTYPE_SIZE > &ptype_count, CArray2d< int, 2, PTYPE_SIZE > &ptype_board_count, MultiInt &last_value_and_out, unsigned int &ptypeo_mask)
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, 2240 > xy_attack_table_diff
static int index(const Piece piece)
static MultiInt evalWithUpdate(const NumEffectState &, Move moved, MultiInt const &last_value)
static void setUp(const Weights &weights, int stage)
static MultiInt eval(const NumEffectState &state)
static CArray< MultiInt, 80 > table
static void setUp(const Weights &weights)
static void evalWithUpdateBang(const NumEffectState &state, Move moved, const CArray2d< int, 2, 9 > &pawns, MultiInt &last_value)
static int index(Player player, Ptype ptype, int y, int pawn_y)
static CArray< MultiInt, 1440 > table
static MultiInt eval(const NumEffectState &state, const CArray2d< int, 2, 9 > &pawns)
static void setUp(const Weights &weights, int stage)
static MultiInt eval(const NumEffectState &state)
static int index(const Piece piece)
static MultiInt evalWithUpdate(const NumEffectState &, Move moved, MultiInt const &last_value)
static CArray< MultiInt, 144 > table
static MultiInt eval(const NumEffectState &state)
static void setUp(const Weights &weights)
static CArray< MultiInt, ONE_DIM > table
static MultiInt eval(const NumEffectState &state)
static CArray< MultiInt, 9 > retreat_table
static CArray< MultiInt, 153 > head_table
static MultiInt evalOne(const NumEffectState &state, const Piece silver, const CArray< Square, 2 > &kings)
static bool canRetreat(const NumEffectState &state, const Piece silver)
static std::pair< int, int > matchGold(const NumEffectState &state, Piece gold, const CArray< bool, 2 > &has_silver, Square &silver_drop)
static std::pair< int, int > matchRook(const NumEffectState &state, Piece rook, const CArray< bool, 2 > &has_silver, Square &silver_drop)
static CArray< MultiInt, ONE_DIM > table
static void setUp(const Weights &weights)
static MultiIntPair eval(const NumEffectState &state, CArray< std::pair< Square, int >, 2 > &silver_drop)
static void setUp(const Weights &weights)
static void setUp(const Weights &weights, int stage)
GeneralMask< mask_int_t > mask_t
const PtypeO PTYPEO_EMPTY
const PtypeTable Ptype_Table
CArray< CArray< T, Capacity2 >, Capacity1 > CArray2d
Ptype unpromote(Ptype ptype)
ptypeがpromote後の型の時に,promote前の型を返す. promoteしていない型の時はそのまま返す
constexpr int playerToIndex(Player player)
const BoardTable Board_Table
bool isPromoted(Ptype ptype)
ptypeがpromote後の型かどうかのチェック
Offset32Base< 8, 9 > Offset32
constexpr int sign(Player player)
constexpr bool isPiece(Ptype ptype)
ptypeが空白やEDGEでないかのチェック
const PtypeO PTYPEO_EDGE __attribute__((unused))
bool isMajor(Ptype ptype)
PtypeO
Player + Ptype [-15, 15] PtypeO の O は Owner の O.
constexpr Player alt(Player player)
PtypeO captured(PtypeO ptypeO)
unpromoteすると共に,ownerを反転する.
static bool hasEffect(const NumEffectState &, Square target, Player attack)
target に attack の追加利きが一つでもあるか. 相手の影利きが先にある場合は対象としない.
static void evalWithUpdateBang(const NumEffectState &state, Move moved, MultiInt &last_value)
static void adjust(int index, MultiInt &values)
static bool cantAdvance(const NumEffectState &state, const Piece pawn)
static int index(Player P, Square pos)
int value(size_t index) const