12 for (
size_t i=0; i<weights.
dimension(); ++i)
13 table[i] = weights.
value(i);
15 for (
int x=1; x<=5; ++x)
17 for (
int y=1; y<=3; ++y)
20 const int king = indexKing(
WHITE,
Square(x,y), flipx);
21 for (
int i=0; i<45*7; ++i)
22 for (
int j=i+1; j<45*7; ++j)
23 table[composeIndex(king, j, i)] = table[composeIndex(king, i, j)];
32 ret[
BLACK] = evalOne<BLACK>(state);
33 ret[
WHITE] = evalOne<WHITE>(state);
37template <osl::Player King>
42 if (state.template kingSquare<King>().template squareForBlack<King>().y() < 7)
47 while (! bitset.
none())
55 const int index_king = indexKing(King, state.
kingSquare(King), flipx);
58 for (
size_t i=0; i<pieces.
size(); ++i)
60 const unsigned int i0 = indexPiece<true>(King, pieces[i].square(), pieces[i].ptype());
61 for (
size_t j=i+1; j<pieces.
size(); ++j)
63 const unsigned int i1 = indexPiece<true>(King, pieces[j].square(), pieces[j].ptype());
64 const unsigned int index = composeIndex(index_king, i0, i1);
71 for (
size_t i=0; i<pieces.
size(); ++i)
73 const unsigned int i0 = indexPiece<false>(King, pieces[i].square(), pieces[i].ptype());
74 for (
size_t j=i+1; j<pieces.
size(); ++j)
76 const unsigned int i1 = indexPiece<false>(King, pieces[j].square(), pieces[j].ptype());
77 const unsigned int index = composeIndex(index_king, i0, i1);
82 return (King ==
BLACK) ? sum : -sum;
85template <osl::Player King>
91 const int index_king = indexKing(King, king, flipx);
98 i0 = indexPiece<true>(King, to, ptype);
99 while (! bitset.
none())
104 const unsigned int i1 = indexPiece<true>(King, p.
square(), p.
ptype());
105 const unsigned int index = composeIndex(index_king, i0, i1);
111 i0 = indexPiece<false>(King, to, ptype);
112 while (! bitset.
none())
117 const unsigned int i1 = indexPiece<false>(King, p.
square(), p.
ptype());
118 const unsigned int index = composeIndex(index_king, i0, i1);
122 sum -= table[composeIndex(index_king, i0, i0)];
123 return (King ==
BLACK) ? sum : -sum;
125template <osl::Player King>
131 const int index_king = indexKing(King, king, flipx);
137 const unsigned int i0 = indexPiece<true>(King, from, ptype);
138 while (! bitset.
none())
143 const unsigned int i1 = indexPiece<true>(King, p.
square(), p.
ptype());
144 const unsigned int index = composeIndex(index_king, i0, i1);
150 const unsigned int i0 = indexPiece<false>(King, from, ptype);
151 while (! bitset.
none())
156 const unsigned int i1 = indexPiece<false>(King, p.
square(), p.
ptype());
157 const unsigned int index = composeIndex(index_king, i0, i1);
161 return (King ==
BLACK) ? sum : -sum;
163template <osl::Player King>
169 const int index_king = indexKing(King, king, flipx);
177 i0 = indexPiece<true>(King, to, ptype);
178 s0 = indexPiece<true>(King, from, ptype);
179 while (! bitset.
none())
184 const unsigned int i1 = indexPiece<true>(King, p.
square(), p.
ptype());
185 const unsigned int index = composeIndex(index_king, i0, i1);
187 const unsigned int sub_index = composeIndex(index_king, s0, i1);
188 sum -= table[sub_index];
193 i0 = indexPiece<false>(King, to, ptype);
194 s0 = indexPiece<false>(King, from, ptype);
195 while (! bitset.
none())
200 const unsigned int i1 = indexPiece<false>(King, p.
square(), p.
ptype());
201 const unsigned int index = composeIndex(index_king, i0, i1);
203 const unsigned int sub_index = composeIndex(index_king, s0, i1);
204 sum -= table[sub_index];
207 sum -= table[composeIndex(index_king, i0, i0)];
208 sum += table[composeIndex(index_king, s0, i0)];
209 return (King ==
BLACK) ? sum : -sum;
212template <osl::Player P>
216 assert(P == moved.
player());
227 adjust_capture = roking.
y() >= 7;
231 last_value[P] = evalOne<P>(state);
233 last_value[
alt(P)] += sub<Opponent>(state, moved.
to(),
captured);
240 last_value[
alt(P)] += sub<Opponent>(state, moved.
to(),
captured);
247 last_value[P] += add<P>(state, moved.
to(), moved.
ptype());
252 last_value[
alt(P)] += sub<Opponent>(state, moved.
to(),
captured);
259 last_value[P] += add<P>(state, moved.
to(), moved.
ptype());
263 last_value[P] += sub<P>(state, moved.
from(), moved.
oldPtype());
265 last_value[P] += addSub<P>(state, moved.
to(), moved.
ptype(), moved.
from());
void push_back(const T &e)
Ptype capturePtype() const
Ptype oldPtype() const
移動前のPtype, i.e., 成る手だった場合成る前
const Square from() const
const PieceMask & piecesOnBoard(Player p) const
void clearBit()
unpromote(PTYPE) の駒のbit を消す
const Square square() const
const Piece pieceOf(int num) const
Square kingSquare() const
int y() const
将棋としてのY座標を返す.
const Square squareForBlack(Player player) const
static int add(const NumEffectState &state, Square to, Ptype ptype)
static void setUp(const Weights &weights)
static int addSub(const NumEffectState &state, Square to, Ptype ptype, Square from)
static void evalWithUpdateBang(const NumEffectState &state, Move moved, CArray< int, 2 > &last_value)
static int evalOne(const NumEffectState &)
static osl::CArray< int16_t, ONE_DIM > table
static int sub(const NumEffectState &state, Square from, Ptype ptype)
static CArray< int, 2 > eval(const NumEffectState &)
bool isPromoted(Ptype ptype)
ptypeがpromote後の型かどうかのチェック
constexpr Player alt(Player player)
PtypeO captured(PtypeO ptypeO)
unpromoteすると共に,ownerを反転する.
int value(size_t index) const