85 return (dir * 4 + state);
95 return (dir * 4 + state) * 9 + y - 1;
116 const int attack_count = state.
countEffect(
alt(defenseP), target);
117 const int defense_count = state.
countEffect(defenseP, target);
118 if (attack_count == 0)
123 else if (defense_count == 1)
127 else if (attack_count >= defense_count)
135 if (defense_count == 1 && attack_count > defense_count)
137 defense = MORE_EFFECT_KING_ONLY;
139 else if (attack_count > defense_count)
141 defense = MORE_EFFECT;
145 defense = LESS_EFFECT;
166 if (attack_count == 0)
168 const int defense_count = state.
countEffect(defense, target);
169 if (defense_count == 1)
171 else if (attack_count >= defense_count)
193 if (attack_count == 0)
196 const int defense_count = state.
countEffect(defense, target);
197 if (defense_count == 1 && attack_count > defense_count)
199 else if (attack_count > defense_count)
206template <
class MakeEffectState>
208#if (defined __GNUC__) && (! defined GPSONE) && (! defined GPSUSIONE)
222 result[0] -= table[
index(dir, black_effect_state)];
227 result[1] += table[
index(dir, white_effect_state)];
234template <
class MakeEffectState>
236#if (defined __GNUC__) && (! defined GPSONE) && (! defined GPSUSIONE)
247 for (
int z=0; z<2; ++z)
258 const EffectState effect_state = f(new_state, pl, dir);
261 result[z] -= table[
index(dir, effect_state)];
265 result[1] = -result[1];
270template <
class MakeEffectState>
277 CArray<int,2> result_o = last_value_o, result_e = last_value_e;
281 for (
int z=0; z<2; ++z)
288 result_o[z] = result_e[z] = 0;
292 const EffectState effect_state = f(new_state, pl, dir);
295 result_o[z] -= table_o[
index(dir, effect_state)];
296 result_e[z] -= table_e[
index(dir, effect_state)];
301 result_o[1] = -result_o[1];
302 result_e[1] = -result_e[1];
305 return std::make_pair(result_o, result_e);
308template <
bool Opening>
313 for (
size_t i = 0; i < weights.
dimension(); ++i)
319template <
bool Opening>
325template <
bool Opening>
331 (new_state, last_move, last_value,
table);
341 (new_state, last_move, last_value_opening, last_value_ending,
346template <
bool Opening>
351 for (
size_t i = 0; i < weights.
dimension(); ++i)
356template <
bool Opening>
362template <
bool Opening>
368 (new_state, last_move, last_value,
table);
379 (new_state, last_move, last_value_opening, last_value_ending,
420 for (
size_t i = 0; i <
ONE_DIM; ++i)
454 const int defense_count = state.
countEffect(defense, target);
458 if (attack_count == 0)
460 else if (defense_count == 1)
462 else if (attack_count >= defense_count)
469 if (attack_count == 0)
471 else if (defense_count == 1 && attack_count > defense_count)
473 else if (attack_count > defense_count)
483 return dir * 4 + state;
492 const int black_liberty = black_king.
liberty();
493 const bool black_u_blocked =
497 const bool black_d_blocked =
501 const bool black_l_blocked =
505 const bool black_r_blocked =
510 const int white_liberty = white_king.
liberty();
511 const bool white_u_blocked =
515 const bool white_d_blocked =
519 const bool white_l_blocked =
523 const bool white_r_blocked =
532 black_defense_effect_state;
534 black_empty_effect_state, black_defense_effect_state);
535 if (black_empty_effect_state !=
NOT_EMPTY)
537 const int idx =
index(dir, black_empty_effect_state);
548 if (black_defense_effect_state !=
NOT_EMPTY)
550 const int idx =
index(dir, black_defense_effect_state);
562 white_defense_effect_state;
564 white_empty_effect_state, white_defense_effect_state);
565 if (white_empty_effect_state !=
NOT_EMPTY)
567 const int idx =
index(dir, white_empty_effect_state);
578 if (white_defense_effect_state !=
NOT_EMPTY)
580 const int idx =
index(dir, white_defense_effect_state);
605 for (
int i = 0; i <
ONE_DIM; ++i)
615 for (
int i = 0; i <
ONE_DIM; ++i)
668template <osl::Player P>
672 const int king_x = king.
x();
675 const int target_x = (king_x > 5) ? 10 - king_x : king_x;
679 return target_x - 1 + ((x_diff == 1) ? 0 : 5);
683 const int target_x = (king_x > 5) ? 10 - king_x : king_x;
687 return target_x - 1 + ((x_diff == 1) ? 0 : 5);
691template <osl::Player P>
698 if ((diff == 1) ^ (P ==
BLACK))
702 assert((diff == 1 && P ==
BLACK) || (diff == -1 && P ==
WHITE));
708 const int target_x = pos.
x() + diff;
709 for (
int y = pos.
y() - 1; y <= pos.
y() + 1; ++y)
711 Square target(target_x, y);
772 const table_t& table_o,
const table_t& table_e)
779 mask.
set(last_move.
from()); mask.set(last_move.
to());
783 val_o[b] = val_e[b]= 0;
784 if (isBlocked<BLACK>(new_state, 1)) {
785 val_o[b] += table_o[index<BLACK>(black_king, 1)];
786 val_e[b] += table_e[index<BLACK>(black_king, 1)];
788 if (isBlocked<BLACK>(new_state, -1)) {
789 val_o[b] += table_o[index<BLACK>(black_king, -1)];
790 val_e[b] += table_e[index<BLACK>(black_king, -1)];
796 val_o[w] = val_e[w]= 0;
797 if (isBlocked<WHITE>(new_state, 1)) {
798 val_o[w] -= table_o[index<WHITE>(white_king, 1)];
799 val_e[w] -= table_e[index<WHITE>(white_king, 1)];
801 if (isBlocked<WHITE>(new_state, -1)) {
802 val_o[w] -= table_o[index<WHITE>(white_king, -1)];
803 val_e[w] -= table_e[index<WHITE>(white_king, -1)];
806 return std::make_pair(val_o, val_e);
831 mask.
set(last_move.
from()); mask.set(last_move.
to());
834 values[
BLACK].clear();
837 if (black_r_blocked) {
842 if (black_l_blocked) {
847 if (black_r_blocked && black_l_blocked)
856 values[
WHITE].clear();
859 if (white_r_blocked) {
864 if (white_l_blocked) {
869 if (white_r_blocked && white_l_blocked)
878template <osl::Player P>
inline
882 const int king_x = king.
x();
885 const int king_y = king.
y();
886 const int target_x = (king_x > 5) ? 10 - king_x : king_x;
890 return (target_x - 1 + ((x_diff == 1) ? 0 : 5)) * 9 + king_y - 1;
894 const int king_y = 10 - king.
y();
895 const int target_x = (king_x > 5) ? 10 - king_x : king_x;
899 return (target_x - 1 + ((x_diff == 1) ? 0 : 5)) * 9 + king_y - 1;
909 for (
size_t i = 0; i <
table.size(); ++i)
920 (new_state, last_move, last_values);
926 for (
size_t i = 0; i <
table.size(); ++i)
938 for (
int i = 0; i <
ONE_DIM; ++i)
947 for (
int i = 0; i <
ONE_DIM; ++i)
952 for(
int x=1;x<=5;x++)
953 for(
int y=1;y<=9;y++)
954 for(
int is_l=0;is_l<2;is_l++)
955 for(
int u_blocked=0;u_blocked<2;u_blocked++)
956 for(
int opp_u_blocked=0;opp_u_blocked<2;opp_u_blocked++)
957 for(
int opp_blocked=0;opp_blocked<2;opp_blocked++){
958 int indexY=x - 1 + 5 * (y - 1 + 9 * ((is_l ? 1 : 0) + 2 * ((u_blocked ? 1 : 0) + 2 * ((opp_u_blocked ? 1 : 0) + 2 * (opp_blocked ? 1 : 0)))));
959 int index0=x - 1 + 5 * ((is_l ? 1 : 0) + 2 * ((u_blocked ? 1 : 0) + 2 * ((opp_u_blocked ? 1 : 0) + 2 * (opp_blocked ? 1 : 0))));
1029 for (
size_t i = 0; i <
table.size(); ++i)
1039 return std::abs(king.
x() - target.
x()) + std::abs(king.
y() - target.
y()) * 2;
1042template <osl::Player Defense>
1047 if ((king.
x() == 1 || king.
x() == 9) &&
1048 ((Defense ==
BLACK && king.
y() == 9) ||
1049 (Defense ==
WHITE && king.
y() == 1))){
1050 const int x = (king.
x() == 1 ? 2 : 8);
1051 const int y = (Defense ==
BLACK ? 8 : 2);
const Square from() const
const BoardMask changedEffects(Player pl) const
int countEffect(Player player, Square target) const
利きの数を数える.
bool hasEffectAt(Square target) const
対象とするマスにあるプレイヤーの利きがあるかどうか.
uint64_t Iking8Info(Player king) const
const Square square() const
bool isOnBoardByOwner() const
piece がプレイヤーPの持ち物でかつボード上にある駒の場合は true.
const Piece kingPiece() const
Square kingSquare() const
const Piece pieceAt(Square sq) const
int y() const
将棋としてのY座標を返す.
bool isOnBoard() const
盤面上を表すかどうかの判定. 1<=x() && x()<=9 && 1<=y() && y()<=9 Squareの内部表現に依存する.
int x() const
将棋としてのX座標を返す.
unsigned int liberty() const
8-15 bit 目を 0-7bitにshiftして返す
bool anyInRange(const BoardMask &mask) const
static MultiInt evalOne(const NumEffectState &state)
static void setUp(const Weights &weights, int stage)
static CArray< MultiInt, 4 > table
static int index(Square king, Square target)
static MultiInt eval(const NumEffectState &state)
static CArray< int, ONE_DIM > l_defense_piece_table
static CArray< int, ONE_DIM > d_defense_piece_table
static CArray< int, ONE_DIM > d_table
static CArray< int, ONE_DIM > u_table
static CArray< int, ONE_DIM > r_table
static CArray< int, ONE_DIM > u_defense_piece_table
static CArray< int, ONE_DIM > base_defense_piece_table
static int eval(const NumEffectState &state, PieceMask black_mask, PieceMask white_mask)
static CArray< int, ONE_DIM > r_defense_piece_table
static void setUp(const Weights &weights)
static int index(const Direction dir, EffectState state)
static CArray< int, ONE_DIM > l_table
static CArray< int, ONE_DIM > base_table
static void effectState(const NumEffectState &state, const Player defense, const Direction dir, EffectState &empty, EffectState &)
static const CArray< int, 2 > evalCommon(const NumEffectState &state, const table_t &)
CArray< int, 32 > table_t
static int index(const Direction dir, EffectState state)
static const CArray< int, 2 > evalWithUpdateCommon(const NumEffectState &new_state, Move last_move, const CArray< int, 2 > &last_value, const table_t &)
static std::pair< CArray< int, 2 >, CArray< int, 2 > > evalWithUpdate(const NumEffectState &new_state, Move last_move, const CArray< int, 2 > &last_value_opening, const CArray< int, 2 > &last_value_ending)
static const CArray< int, 2 > evalWithUpdate(const NumEffectState &new_state, Move last_move, const CArray< int, 2 > &last_value)
static void setUp(const Weights &weights)
static CArray< int, 32 > table
static const CArray< int, 2 > eval(const NumEffectState &state)
static std::pair< CArray< int, 2 >, CArray< int, 2 > > evalWithUpdate(const NumEffectState &new_state, Move last_move, const CArray< int, 2 > &last_value_opening, const CArray< int, 2 > &last_value_ending)
static const CArray< int, 2 > eval(const NumEffectState &state)
static const CArray< int, 2 > evalWithUpdate(const NumEffectState &new_state, Move last_move, const CArray< int, 2 > &last_value)
static void setUp(const Weights &weights)
static CArray< int, 32 > defense_table
static int indexY(Piece king, const Direction dir, EffectState state)
static int eval(const NumEffectState &state)
static CArray< int, 288 > empty_y_table
static CArray< int, 32 > empty_table
static void setUp(const Weights &weights)
static int index(const Direction dir, EffectState state)
static void effectState(const NumEffectState &state, const Player defense, const Direction dir, EffectState &empty, EffectState &)
static CArray< int, 288 > defense_y_table
static void setUp(const Weights &weights)
static CArray< MultiInt, 80 > table
static CArray< MultiInt, 720 > y_table
static void setUp(const Weights &weights)
static void adjust(int index_y, MultiInt &result)
static MultiInt eval(const NumEffectState &state)
static int indexY(const Square king, bool is_l, bool u_blocked, bool opp_u_blocked, bool opp_blocked)
static void evalWithUpdateBang(const NumEffectState &new_state, Move last_move, MultiIntPair &last_values_and_out)
CArray< MultiInt, 90 > table_t
static void evalWithUpdateBang(const NumEffectState &state, Move laste_move, MultiIntPair &last_values_and_out)
static int index(Square king, int diff)
static const MultiIntPair eval(const NumEffectState &state, const table_t &table)
static void adjust(int index, int index_y, MultiInt &out)
static void setUp(const Weights &weights, int stage)
static void setUp(const Weights &weights, int stage)
static CArray< MultiInt, ONE_DIM > table
static void setUp(const Weights &weights)
static void adjust(int index, int index_y, MultiInt &out)
static int indexY(const Square king)
static MultiIntPair eval(const NumEffectState &state)
static CArray< MultiInt, ONE_DIM > table
static void setUp(const Weights &weights)
static int index(const Square king)
constexpr Player indexToPlayer(int n)
constexpr int playerToIndex(Player player)
const BoardTable Board_Table
const BoardMaskTable3x3 Board_Mask_Table3x3
const PtypeO PTYPEO_EDGE __attribute__((unused))
constexpr Player alt(Player player)
static const unsigned int mask
EffectState operator()(const NumEffectState &state, const Player defense, const Direction dir) const
EffectState operator()(const NumEffectState &state, const Player defense, const Direction dir) const
CArray< MultiInt, 10 > table_t
static bool isBlocked(const NumEffectState &state, int diff)
static int index(Square king, int diff)
static const MultiIntPair eval(const NumEffectState &state, const table_t &table)
int value(size_t index) const