My Project
progress.h
Go to the documentation of this file.
1/* newProgress.h */
2#ifndef PROGRESS_EXPERIMENTAL_NEW_PROGRESS_H
3#define PROGRESS_EXPERIMENTAL_NEW_PROGRESS_H
4
6#include "osl/eval/midgame.h"
7#include "osl/container.h"
8#include <cstdlib>
9namespace osl
10{
11 namespace progress
12 {
13 template <int N>
15 {
17 public:
18 explicit ProgressN(int value=0) : progress(value)
19 {
20 assert(isValid());
21 }
22 int value() const { return progress; }
23 bool isValid() const {
24 return (progress >= 0) && (progress < N);
25 }
26 };
27 template <int N>
29 {
30 return l.value() == r.value();
31 }
32 template <int N>
34 {
35 return ! (l == r);
36 }
37 template <int N>
39 {
40 return l.value() < r.value();
41 }
44
45 namespace ml
46 {
64
76 {
77 public:
78 enum { ProgressScale = 2 };
79 private:
80 static bool initialized_flag;
93 static int max_progress;
96 template <Player Owner>
98 void updatePawnFacing(const NumEffectState& state);
99 template <Player Attack>
100 void promotion37One(const NumEffectState& state, int rank);
101 void updatePromotion37(const NumEffectState& state);
102 void updatePieceStand7(const NumEffectState& state);
103 template <Player P>
104 static void progressOne(const NumEffectState &state,
105 int &attack, int &defense);
106 template <Player P>
108 template <Player P>
110 template <Player P>
111 int attack5x5Value(const NumEffectState &state) const;
112 template <Player P>
113 static int index(Square king, Square target)
114 {
115 const int x_diff = std::abs(king.x() - target.x()); // [0, 4]
116 const int y_diff = (P == BLACK ? king.y() - target.y() :
117 target.y() - king.y()) + 2; // [-2, 2] + 2
118 return x_diff * 5 + y_diff;
119 }
120 template <Player P>
121 static int indexX(Square king, Square target)
122 {
123 int target_x = (king.x() > 5 ? 10 - king.x() : king.x()); // [1, 5]
124 int x_diff = king.x() - target.x(); // [-4, 4]
125 if (P == BLACK && king.x() >= 6)
126 {
127 x_diff = -x_diff;
128 }
129 else if (P == WHITE && king.x() >= 5)
130 {
131 x_diff = -x_diff;
132 }
133 const int y_diff = (P == BLACK ? king.y() - target.y() :
134 target.y() - king.y()) + 2; // [-2, 2] + 2
135 return ((x_diff + 4) * 5 + y_diff) * 5 + target_x - 1;
136 }
137 template <Player P>
138 static int indexY(Square king, Square target)
139 {
140 const int x_diff = std::abs(king.x() - target.x()); // [0, 4]
141 const int y_diff = (P == BLACK ? king.y() - target.y() :
142 target.y() - king.y()) + 2; // [-2, 2] + 2
143 const int king_y = (P == BLACK ? king.y() : 10 - king.y()); // [1, 9]
144 return (x_diff * 5 + y_diff) * 9 + king_y - 1;
145 }
146 static int index5x5(int rook, int bishop, int gold, int silver,
147 int promoted)
148 {
149 assert(0 <= promoted && promoted <= 4);
150 return promoted + 5 * (silver + 5 * (gold + 5 * (bishop + 3 * rook)));
151 }
152 static int index5x5x(int rook, int bishop, int gold, int silver,
153 int promoted, int king_x)
154 {
155 assert(0 <= promoted && promoted <= 4);
156 return king_x - 1 +
157 5 * (promoted + 5 * (silver + 5 * (gold + 5 * (bishop + 3 * rook))));
158 }
159 static int index5x5y(int rook, int bishop, int gold, int silver,
160 int promoted, int king_y)
161 {
162 assert(0 <= promoted && promoted <= 4);
163 return king_y - 1 +
164 9 * (promoted + 5 * (silver + 5 * (gold + 5 * (bishop + 3 * rook))));
165 }
166 template <Player P>
167 static int indexPerEffect(Square king, Square target,
168 int count)
169 {
170 const int x_diff = std::abs(king.x() - target.x()); // [0, 4]
171 const int y_diff = (P == BLACK ? king.y() - target.y() :
172 target.y() - king.y()) + 2; // [-2, 2] + 2
173 return x_diff * 5 + y_diff + std::min(8, count) * 25;
174 }
175
176 template <Player P>
177 static int indexPerEffectY(Square king, Square target,
178 int count)
179 {
180 const int king_y = (P == BLACK ? king.y() : 10 - king.y());
181 const int x_diff = std::abs(king.x() - target.x()); // [0, 4]
182 const int y_diff = (P == BLACK ? king.y() - target.y() :
183 target.y() - king.y()) + 2; // [-2, 2] + 2
184 return king_y - 1 + 9 * (x_diff * 5 + y_diff + std::min(8, count) * 25);
185 }
186 template <Player P>
187 static int indexPerEffectX(Square king, Square target,
188 int count)
189 {
190 const int king_x = (king.x() > 5 ? 10 - king.x() : king.x());
191 int x_diff = king.x() - target.x(); // [-4, 4]
192 if ((P == BLACK && (king.x() > 5)) ||
193 (P == WHITE && (king.x() >= 5)))
194 x_diff = -x_diff;
195 const int y_diff = (P == BLACK ? king.y() - target.y() :
196 target.y() - king.y()) + 2; // [-2, 2] + 2
197 return king_x - 1 + 5 * (x_diff + 4 +
198 9 * (y_diff + 5 * std::min(8, count)));
199 }
200 template <Player P>
201 static int indexRelative(const Square king,
202 const Ptype ptype, const Square pos)
203 {
204 const int x = std::abs(pos.x() - king.x());
205 const int y = (king.y() - pos.y()) *
206 (P == osl::BLACK ? 1 : -1) + 8;
207 return (ptype - osl::PTYPE_PIECE_MIN) * 17 * 9 + (x * 17 + y);
208 }
209 static int indexRelative(const Player player, const Square king,
210 const Piece piece)
211 {
212 if (player == BLACK)
213 {
214 return indexRelative<BLACK>(king, piece.ptype(),
215 piece.square());
216 }
217 else
218 {
219 return indexRelative<WHITE>(king, piece.ptype(),
220 piece.square());
221 }
222 }
223 public:
224 NewProgress(const NumEffectState &state);
243 static int maxProgress() { return max_progress / ProgressScale; }
244 template<Player P>
245 void updateSub(const NumEffectState &new_state, Move last_move);
246 void update(const NumEffectState &new_state, Move last_move){
247 if(new_state.turn()==BLACK)
248 updateSub<WHITE>(new_state,last_move);
249 else
250 updateSub<BLACK>(new_state,last_move);
251 }
253 private:
254 template<Player P>
255 void updateMain(const NumEffectState &new_state, Move last_move);
256 public:
257 const Progress16 progress16() const
258 {
259 return Progress16(16 * progress() / maxProgress());
260 }
277 // p == attack player, alt(p) == king owner
279 {
280 assert(maxProgress() > 0);
281 return Progress16(
282 8 * std::max(
283 std::min(progresses[alt(p)] +
289 / ProgressScale / maxProgress() + 8);
290 }
291 // p == king owner (defense player)
293 {
294 assert(maxProgress() > 0);
295 return Progress16(
296 8 * std::max(
297 std::min(defenses[alt(p)] +
302 / ProgressScale / maxProgress() + 8);
303 }
304 static bool initialized()
305 {
306 return initialized_flag;
307 }
308 static bool setUp(const char *filename);
309 static bool setUp();
310 static std::string defaultFilename();
311 const NewProgressData rawData() const { return *this; }
312 };
313 bool operator==(const NewProgressData& l, const NewProgressData& r);
314 inline bool operator==(const NewProgress& l, const NewProgress& r)
315 {
316 return l.rawData() == r.rawData();
317 }
318 }
319 using ml::NewProgress;
320 }
323 using progress::NewProgress;
324}
325
326#endif // PROGRESS_EXPERIMENTAL_NEW_PROGRESS_H
327// ;;; Local Variables:
328// ;;; mode:c++
329// ;;; c-basic-offset:2
330// ;;; End:
圧縮していない moveの表現 .
利きを持つ局面
駒番号のビットセット.
Definition pieceMask.h:21
Ptype ptype() const
Definition basic_type.h:821
const Square square() const
Definition basic_type.h:832
Player turn() const
int y() const
将棋としてのY座標を返す.
Definition basic_type.h:567
int x() const
将棋としてのX座標を返す.
Definition basic_type.h:563
ProgressN(int value=0)
Definition progress.h:18
bool isValid() const
Definition progress.h:23
void updateMain(const NumEffectState &new_state, Move last_move)
Definition progress.cc:590
static CArray< int, 5625 > attack5x5_x_weight
Definition progress.h:83
static int index5x5x(int rook, int bishop, int gold, int silver, int promoted, int king_x)
Definition progress.h:152
const Progress16 progressAttack(Player p) const
Definition progress.h:278
void update(const NumEffectState &new_state, Move last_move)
Definition progress.h:246
static int indexRelative(const Square king, const Ptype ptype, const Square pos)
Definition progress.h:201
void updatePawnFacing(const NumEffectState &state)
Definition progress.cc:476
void promotion37One(const NumEffectState &state, int rank)
Definition progress.cc:492
void updateAttack5x5PiecesAndState(const NumEffectState &state)
Definition progress.cc:336
static CArray< int, 75 > effectstate_weight
Definition progress.h:85
static void progressOne(const NumEffectState &state, int &attack, int &defense)
Definition progress.cc:296
static int index5x5y(int rook, int bishop, int gold, int silver, int promoted, int king_y)
Definition progress.h:159
void updateSub(const NumEffectState &new_state, Move last_move)
Definition progress.cc:684
static CArray< int, 16 > promotion37_weight
Definition progress.h:91
static int indexRelative(const Player player, const Square king, const Piece piece)
Definition progress.h:209
const Progress16 progress16(Player p) const
Definition progress.h:261
void updateAttack5x5Pieces(PieceMask, const NumEffectState &)
Definition progress.cc:367
static CArray< int, 10 > pawn_facing_weight
Definition progress.h:90
static int indexPerEffectX(Square king, Square target, int count)
Definition progress.h:187
static CArray< int, 81 *15 *10 > defense_relative
Definition progress.h:87
const Progress16 progress16() const
Definition progress.h:257
static std::string defaultFilename()
Definition progress.cc:288
static int indexY(Square king, Square target)
Definition progress.h:138
int attack5x5Value(const NumEffectState &state) const
Definition progress.cc:386
const Progress16 progressDefense(Player p) const
Definition progress.h:292
static int indexPerEffectY(Square king, Square target, int count)
Definition progress.h:177
void updateNonPawnAttackedPtypePairOne(const NumEffectState &state)
Definition progress.cc:436
static int indexX(Square king, Square target)
Definition progress.h:121
static int index(Square king, Square target)
Definition progress.h:113
static CArray< int, 56 > piecestand7_weight
Definition progress.h:92
void updatePromotion37(const NumEffectState &state)
Definition progress.cc:523
static int index5x5(int rook, int bishop, int gold, int silver, int promoted)
Definition progress.h:146
static CArray< int, 262144 > attacked_ptype_pair_weight
Definition progress.h:89
void updatePieceKingRelativeBonus(const NumEffectState &state)
Definition progress.cc:410
const NewProgressData rawData() const
Definition progress.h:311
void updatePieceStand7(const NumEffectState &state)
Definition progress.cc:532
static int indexPerEffect(Square king, Square target, int count)
Definition progress.h:167
static CArray< int, 1125 > attack5x5_weight
Definition progress.h:82
static CArray< int, 81 *15 *10 > attack_relative
Definition progress.h:86
static CArray< int, Piece::SIZE > stand_weight
Definition progress.h:81
void updateNonPawnAttackedPtypePair(const NumEffectState &state)
Definition progress.cc:469
static CArray< int, 4284 > king_relative_weight
Definition progress.h:88
static CArray< int, 10125 > attack5x5_y_weight
Definition progress.h:84
NewProgressDebugInfo debugInfo() const
Definition progress.cc:726
bool operator==(const NewProgressData &l, const NewProgressData &r)
Definition progress.cc:12
bool operator!=(ProgressN< N > l, ProgressN< N > r)
Definition progress.h:33
bool operator==(ProgressN< N > l, ProgressN< N > r)
Definition progress.h:28
ProgressN< 16 > Progress16
Definition progress.h:42
ProgressN< 32 > Progress32
Definition progress.h:43
bool operator<(ProgressN< N > l, ProgressN< N > r)
Definition progress.h:38
Ptype
駒の種類を4ビットでコード化する
Definition basic_type.h:84
@ PTYPE_PIECE_MIN
Definition basic_type.h:104
constexpr int playerToIndex(Player player)
Definition basic_type.h:16
Player
Definition basic_type.h:8
@ WHITE
Definition basic_type.h:10
@ BLACK
Definition basic_type.h:9
constexpr Player alt(Player player)
Definition basic_type.h:13
CArray< int, 2 > effect_progresses
Definition progress.h:70
CArray< MultiInt, 2 > non_pawn_ptype_attacked_pair_eval
Definition progress.h:67
CArray< int, 2 > non_pawn_ptype_attacked_pair
Definition progress.h:72
CArray< int, 2 > king_relative_defense
Definition progress.h:72
CArray< int, 2 > attack5x5_progresses
Definition progress.h:69
CArray< int, 2 > king_relative_attack
Definition progress.h:72
CArray< int, 2 > stand_progresses
Definition progress.h:69
CArray< int, FEATURE_LIMIT > black_values
Definition progress.h:61
CArray< int, FEATURE_LIMIT > white_values
Definition progress.h:62