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(),
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) {
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;
160 x_table[x][2][pi0][pi1] = index;
163 x_table[x][11][pi0][pi1] = index;
166 x_table[x][5][pi0][pi1] = 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) {
196 const Ptype p0 =
static_cast<Ptype>(ip0), p1 =
static_cast<Ptype>(ip1);
198 for (
int x=6; x<=9; ++x) {
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]);
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;
245 y_table[y][2][pi0][pi1] = index;
246 y_table[y][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) {
275 const Ptype p0 =
static_cast<Ptype>(ip0), p1 =
static_cast<Ptype>(ip1);
278 for (
int y=1; y<=9; ++y) {
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);
453 for (
int i=0; i<Piece::SIZE; i++) {
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]);
527template <
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);
558template<
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 fill(const T_simple &value=T_simple())
PtypeO ptypeO() const
移動後のPtype, i.e., 成る手だった場合成った後
PtypeO oldPtypeO() const
移動前のPtypeO, i.e., 成る手だった場合成る前
PtypeO capturePtypeO() const
const Square from() const
unsigned int index() const
const Square square() const
const Piece * getPiecePtr(Square sq) const
const Piece pieceOf(int num) const
const Piece pieceAt(Square sq) const
bool isPieceStand() const
int y() const
将棋としてのY座標を返す.
bool isOnBoard() const
盤面上を表すかどうかの判定. 1<=x() && x()<=9 && 1<=y() && y()<=9 Squareの内部表現に依存する.
int x() const
将棋としてのX座標を返す.
static int valueCompiled(int offset_id, Piece p, Square p1, PtypeO o1)
static int evalWithUpdate(const NumEffectState &state, Move moved, int last_value, const Weights &values)
static IndexTable plain_table
static int evalWithUpdateCompiled(const NumEffectState &state, Move moved, int last_value)
static index_t index(int offset_id, Piece p, Piece q)
static int sum12One(const Piece *basePtr, const int *xbase, const int *ybase)
static const CArray< Offset, 12 > offsets
static int sum12(NumEffectState const &state, Square base, PtypeO ptypeO)
static int pieceValue(const NumEffectState &state, Piece p, const Weights &values)
static int adjust12One(const Piece *basePtr, const int *xbase1, const int *ybase1, const int *xbase2, const int *ybase2)
static int adjust12(NumEffectState const &state, Square base, PtypeO pos, PtypeO neg)
static void compile(const Weights &values)
values を展開してクラス全体で使う
static CArray< IndexTable, 10 > y_table
static void sanitize(Weights &values)
static int pieceValueDouble(const NumEffectState &state, Piece p, const Weights &)
static CArray< IndexTable, 10 > x_table
static int eval(const NumEffectState &, const Weights &)
CArray< int, 0x200 > offset_index
CArray< PiecePair::IndexTable, 10 > & x_table
int swaplr(int offset_id)
CArray< PiecePair::IndexTable, 10 > & y_table
PiecePair::IndexTable & plain_table
CArray3d< int, PTYPEO_SIZE, 12, PTYPEO_SIZE > x_values[10]
CArray3d< int, PTYPEO_SIZE, 12, PTYPEO_SIZE > y_values[10]
int swapud(int offset_id)
int pindex(Player player, Ptype ptype)
unsigned int ptypeOIndex(PtypeO ptypeo)
constexpr bool isPiece(Ptype ptype)
ptypeが空白やEDGEでないかのチェック
PtypeO
Player + Ptype [-15, 15] PtypeO の O は Owner の O.
PtypeO newPtypeO(Player player, Ptype ptype)
static int pindex(Player player, Ptype ptype)
void fillSame(int index, int dir, Ptype p0, Ptype p1)
for same owner
void fillBW(int index, int dir, Ptype p0, Ptype p1)
void fillDiffer(int index, int dir, Ptype p0, Ptype p1)
for different owner
void setValue(size_t index, int value)
int value(size_t index) const