10 DirectionPlayerTraits<UUL, BLACK>::offset(),
11 DirectionPlayerTraits<UL, BLACK>::offset(),
12 DirectionPlayerTraits<L, BLACK>::offset(),
13 DirectionPlayerTraits<DL, BLACK>::offset(),
14 DirectionPlayerTraits<UUR, WHITE>::offset(),
15 DirectionPlayerTraits<D, BLACK>::offset(),
17 DirectionPlayerTraits<UUL, WHITE>::offset(),
18 DirectionPlayerTraits<DR, BLACK>::offset(),
19 DirectionPlayerTraits<R, BLACK>::offset(),
20 DirectionPlayerTraits<UR, BLACK>::offset(),
21 DirectionPlayerTraits<UUR, BLACK>::offset(),
22 DirectionPlayerTraits<U, BLACK>::offset(),
40 offset_index.
fill(-1);
45 inline int inv(
int offset_id)
47 assert(offset_id >= 0 && offset_id < 12);
48 return (offset_id + 6) % 12;
52 assert(offset_id >= 0 && offset_id < 12);
55 return 10 - offset_id;
59 assert(offset_id >= 0 && offset_id < 12);
67 for (
int ip1=ip0; ip1<=
PTYPE_MAX; ++ip1) {
68 const Ptype p0 =
static_cast<Ptype>(ip0), p1 = static_cast<Ptype>(ip1);
73 assert(plain_table[0][pi0][pi1] == 0);
76 plain_table.
fillSame(index, 0, p0, p1);
77 plain_table.
fillSame(index, 10, p0, p1);
80 plain_table.
fillSame(index, 0, p1, p0);
81 plain_table.
fillSame(index, 10, p1, p0);
85 plain_table.
fillSame(index, 1, p0, p1);
86 plain_table.
fillSame(index, 9, p0, p1);
89 plain_table.
fillSame(index, 1, p1, p0);
90 plain_table.
fillSame(index, 9, p1, p0);
94 plain_table.
fillSame(index, 2, p0, p1);
95 plain_table.
fillSame(index, 8, p0, p1);
97 plain_table.
fillSame(index, 2, p1, p0);
98 plain_table.
fillSame(index, 8, p1, p0);
102 plain_table.
fillSame(index, 11, p0, p1);
104 plain_table.
fillSame(index, 11, p1, p0);
149 const Ptype p0 =
static_cast<Ptype>(ip0), p1 = static_cast<Ptype>(ip1);
151 for (
int x=1; x<=5; ++x) {
153 for (
int d=0; d<2; ++d) {
155 x_table[x][d][pi0][pi1] = index;
156 x_table[x][
swapud(d)][pi0][pi1] = index;
160 x_table[x][2][pi0][pi1] = index;
163 x_table[x][11][pi0][pi1] = index;
164 x_table[x][
inv(11)][pi1][pi0] = index;
166 x_table[x][5][pi0][pi1] = index;
167 x_table[x][
inv(5)][pi1][pi0] = index;
174 const Ptype p0 =
static_cast<Ptype>(ip0), p1 = static_cast<Ptype>(ip1);
176 for (
int x=2; x<=5; ++x) {
178 for (
int d=0; d<2; ++d) {
179 x_table[x-1][
inv(d)][pi1][pi0] = x_table[x][d][pi0][pi1];
180 x_table[x-1][
inv(
swapud(d))][pi1][pi0] = x_table[x][
swapud(d)][pi0][pi1];
183 x_table[x-1][
swaplr(2)][pi1][pi0] = x_table[x][2][pi0][pi1];
187 if (
swaplr(d) == (int)d || x_table[5][d][pi0][pi1] == 0)
189 x_table[5][
swaplr(d)][pi0][pi1] = x_table[5][d][pi0][pi1];
196 const Ptype p0 =
static_cast<Ptype>(ip0), p1 = static_cast<Ptype>(ip1);
198 for (
int x=6; x<=9; ++x) {
200 x_table[x][d][pi0][pi1] = x_table[10-x][
swaplr(d)][pi0][pi1];
206 for (
int x=1; x<=9; ++x) {
209 const Ptype p0 =
static_cast<Ptype>(ip0), p1 = static_cast<Ptype>(ip1);
213 assert(x_table[x][d][pi0][pi1]);
214 x_table[10-x][
inv(d)][pi0w][pi1w] = -x_table[x][d][pi0][pi1];
220 for (
int x=1; x<=9; ++x)
234 const Ptype p0 =
static_cast<Ptype>(ip0), p1 = static_cast<Ptype>(ip1);
237 for (
int y=1; y<=9; ++y) {
238 for (
int d=0; d<2; ++d) {
240 y_table[y][d][pi0][pi1] = index;
241 y_table[y][
swaplr(d)][pi0][pi1] = index;
245 y_table[y][2][pi0][pi1] = index;
246 y_table[y][2][pi1][pi0] = index;
247 y_table[y][
swaplr(2)][pi0][pi1] = index;
248 y_table[y][
swaplr(2)][pi1][pi0] = index;
251 y_table[y][11][pi0][pi1] = index;
258 const Ptype p0 =
static_cast<Ptype>(ip0), p1 = static_cast<Ptype>(ip1);
260 for (
int y=1; y<=9; ++y) {
262 y_table[
wrap9(y+2)][
inv(0)][pi1][pi0] = y_table[y][0][pi0][pi1];
265 y_table[
wrap9(y+1)][
inv(1)][pi1][pi0] = y_table[y][1][pi0][pi1];
268 y_table[
wrap9(y+1)][
inv(11)][pi1][pi0] = y_table[y][11][pi0][pi1];
275 const Ptype p0 =
static_cast<Ptype>(ip0), p1 = static_cast<Ptype>(ip1);
278 for (
int y=1; y<=9; ++y) {
280 y_table[10-y][
inv(d)][pi0w][pi1w] = -y_table[y][d][pi0][pi1];
286 for (
int y=1; y<=9; ++y)
292 using namespace ppair;
307 for (
size_t d=0; d<offsets.size(); ++d) {
310 signed short& target = (*this)[d][ip0][ip1];
328 (*this)[dir][pi0][pi1] = index;
329 (*this)[
inv(dir)][pi0w][pi1w] = -index;
334 fillBW(index, dir, p0, p1);
335 fillBW(index,
inv(dir), p1, p0);
343 (*this)[
inv(dir)][pi0][pi1w] = index;
344 (*this)[dir][pi1w][pi0] = index;
345 (*this)[
inv(dir)][pi1][pi0w] = -index;
346 (*this)[dir][pi0w][pi1] = -index;
354 static bool initialized =
false;
367 for (
int i=1; i<=9; ++i) {
371 for (
size_t d=0; d<offsets.size(); ++d) {
379 for (
int i=1; i<=9; ++i) {
381 if (
x_table[i][d][ip0][ip1] > 0)
383 else if (
x_table[i][d][ip0][ip1] < 0)
385 if (
y_table[i][d][ip0][ip1] > 0)
387 else if (
y_table[i][d][ip0][ip1] < 0)
399 for (
int x=1; x<=9; ++x) {
400 for (
int y=1; y<=9; ++y) {
402 for (
size_t i=0; i<offsets.size(); ++i) {
403 const Square pos0 = pos1+offsets[i];
422 assert(pos0 != pos1);
425 assert(pos0 - pos1 == offsets[offset_id]);
431 assert(abs(ret[0]) < plain_table_size);
432 assert(abs(ret[1]) < plain_table_size + x_table_size);
433 assert(abs(ret[2]) < plain_table_size + x_table_size + y_table_size);
434 assert(ret[1] == 0 || abs(ret[1]) > plain_table_size);
435 assert(ret[2] == 0 || abs(ret[2]) > plain_table_size + x_table_size);
455 ret += pieceValueDouble(state, p, values);
466 int ret = last_value;
472 for (
size_t i=0; i<offsets.size(); ++i) {
473 const Square target = from + offsets[i];
478 ret -= value(i, p, from, moved.
oldPtypeO(), values);
485 for (
size_t i=0; i<offsets.size(); ++i) {
486 const Square target = to + offsets[i];
491 ret += value(i, p, to, moved.
ptypeO(), values);
497 for (
size_t i=0; i<offsets.size(); ++i) {
498 const Square target = to + offsets[i];
503 ret += value(i, p, to, moved.
ptypeO(), values);
508 const Offset diff = to - from;
519 assert(pos0 != pos1);
521 assert(pos0 - pos1 == offsets[offset_id]);
527 template <
int Direction,
int Offset>
544 sum12One<4,18>(base_ptr,xbase,ybase)+
545 + sum12One<3,17>(base_ptr,xbase,ybase)
546 + sum12One<2,16>(base_ptr,xbase,ybase)
547 + sum12One<1,15>(base_ptr,xbase,ybase)
548 + sum12One<0,14>(base_ptr,xbase,ybase)
549 + sum12One<5,1>(base_ptr,xbase,ybase)
550 + sum12One<11,-1>(base_ptr,xbase,ybase)
551 + sum12One<6,-14>(base_ptr,xbase,ybase)
552 + sum12One<7,-15>(base_ptr,xbase,ybase)
553 + sum12One<8,-16>(base_ptr,xbase,ybase)
554 + sum12One<9,-17>(base_ptr,xbase,ybase)
555 + sum12One<10,-18>(base_ptr,xbase,ybase);
558 template<
int Direction,
int Offset>
580 adjust12One<4,18>(base_ptr,xbase1,ybase1,xbase2,ybase2)
581 + adjust12One<3,17>(base_ptr,xbase1,ybase1,xbase2,ybase2)
582 + adjust12One<2,16>(base_ptr,xbase1,ybase1,xbase2,ybase2)
583 + adjust12One<1,15>(base_ptr,xbase1,ybase1,xbase2,ybase2)
584 + adjust12One<0,14>(base_ptr,xbase1,ybase1,xbase2,ybase2)
585 + adjust12One<5,1>(base_ptr,xbase1,ybase1,xbase2,ybase2)
586 + adjust12One<11,-1>(base_ptr,xbase1,ybase1,xbase2,ybase2)
587 + adjust12One<6,-14>(base_ptr,xbase1,ybase1,xbase2,ybase2)
588 + adjust12One<7,-15>(base_ptr,xbase1,ybase1,xbase2,ybase2)
589 + adjust12One<8,-16>(base_ptr,xbase1,ybase1,xbase2,ybase2)
590 + adjust12One<9,-17>(base_ptr,xbase1,ybase1,xbase2,ybase2)
591 + adjust12One<10,-18>(base_ptr,xbase1,ybase1,xbase2,ybase2);
597 int ret = last_value;
603 ret+=sum12(state,to,moved.
ptypeO());
607 ret-=sum12(state,from,moved.
oldPtypeO());
610 ret+=sum12(state,to,moved.
ptypeO());
611 const Offset diff = to-from;
627 const Offset diff = to-from;
655 for (
size_t i=0; i<offsets.size(); ++i) {
662 int v = value(i, q, p, values);
671 return pieceValueDouble(state, p, values)/2;
void fillBW(int index, int dir, Ptype p0, Ptype p1)
CArray< PiecePair::IndexTable, 10 > & y_table
int swapud(int offset_id)
static int pieceValue(const NumEffectState &state, Piece p, const Weights &values)
static int sum12One(const Piece *basePtr, const int *xbase, const int *ybase)
PtypeO capturePtypeO() const
void fillSame(int index, int dir, Ptype p0, Ptype p1)
for same owner
const Piece pieceAt(Square sq) const
CArray3d< int, PTYPEO_SIZE, 12, PTYPEO_SIZE > x_values[10]
int y() const
将棋としてのY座標を返す.
static void compile(const Weights &values)
values を展開してクラス全体で使う
static int eval(const NumEffectState &, const Weights &)
PtypeO ptypeO() const
移動後のPtype, i.e., 成る手だった場合成った後
int value(size_t index) const
int x() const
将棋としてのX座標を返す.
CArray< int, 0x200 > offset_index
static int valueCompiled(int offset_id, Piece p, Square p1, PtypeO o1)
static int pindex(Player player, Ptype ptype)
PtypeO newPtypeO(Player player, Ptype ptype)
void setValue(size_t index, int value)
const Piece pieceOf(int num) const
bool isOnBoard() const
盤面上を表すかどうかの判定. 1<=x() && x()<=9 && 1<=y() && y()<=9 Squareの内部表現に依存する. ...
static IndexTable plain_table
const Square from() const
int swaplr(int offset_id)
static CArray< IndexTable, 10 > y_table
PiecePair::IndexTable & plain_table
CArray< PiecePair::IndexTable, 10 > & x_table
static int adjust12(NumEffectState const &state, Square base, PtypeO pos, PtypeO neg)
static int adjust12One(const Piece *basePtr, const int *xbase1, const int *ybase1, const int *xbase2, const int *ybase2)
const Square square() const
PtypeO
Player + Ptype [-15, 15] PtypeO の O は Owner の O.
static int pieceValueDouble(const NumEffectState &state, Piece p, const Weights &)
PtypeO oldPtypeO() const
移動前のPtypeO, i.e., 成る手だった場合成る前
void fill(const T_simple &value=T_simple())
constexpr bool isPiece(Ptype ptype)
ptypeが空白やEDGEでないかのチェック
CArray3d< int, PTYPEO_SIZE, 12, PTYPEO_SIZE > y_values[10]
static int evalWithUpdateCompiled(const NumEffectState &state, Move moved, int last_value)
static CArray< IndexTable, 10 > x_table
static void sanitize(Weights &values)
static int evalWithUpdate(const NumEffectState &state, Move moved, int last_value, const Weights &values)
const Piece * getPiecePtr(Square sq) const
static index_t index(int offset_id, Piece p, Piece q)
bool isPieceStand() const
void fillDiffer(int index, int dir, Ptype p0, Ptype p1)
for different owner
static int sum12(NumEffectState const &state, Square base, PtypeO ptypeO)
unsigned int ptypeOIndex(PtypeO ptypeo)
int pindex(Player player, Ptype ptype)
static const CArray< Offset, 12 > offsets