All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
progressEval.h
Go to the documentation of this file.
1 /* progressEval.h
2  */
3 #ifndef EVAL_PROGRESSEVAL_H
4 #define EVAL_PROGRESSEVAL_H
5 
6 // #define EXPERIMENTAL_EVAL
7 
8 #include "osl/effect_util/pin.h"
9 #include "osl/eval/pieceEval.h"
11 
14 #include "osl/eval/mobilityTable.h"
15 #include "osl/progress/effect5x3.h"
22 #include <boost/static_assert.hpp>
23 
24 namespace osl
25 {
26  namespace eval
27  {
29  {
34 
35  // break down of progress bonus
37  // progress independent bonus
40  // progress dependent bonus
42 
44  };
45 
49  template <class OpeningEval>
51  {
52  public:
53  typedef OpeningEval opening_eval_t;
57  private:
63  // Records pinned pieces of a player, not the opponent's
64  // (owner of pieces == player)
65  mutable CArray<PieceMask, 2> pin_mask;
66  CArray2d<int, 2, SHORT8_DIRECTION_MAX+1> can_check_pieces;
70  CArray<int,2> attack_bonus; // index is king (i.e., defense)
72  enum{
74  };
75  mutable int cache;
76 
77  static CArray<int, PTYPEO_SIZE> capture_values;
78 
79  template<Player P, Ptype PTYPE, Direction Dir, Direction LongDir>
80  void initializeCheckPieceDir(const NumEffectState &state, int count);
81  template <Player P, Ptype PTYPE>
82  void initializeCheckPiece(const NumEffectState &state);
83  static void setUpInternal(const char *filename=0);
84  public:
85  ProgressEvalGeneral(const NumEffectState& state);
86  void changeTurn() {}
87  static bool initialized()
88  {
89  return opening_eval_t::initialized();
90  }
91  static bool setUp(const char *filename)
92  {
93  if (! opening_eval_t::setUp())
94  return false;
95  setUpInternal(filename);
96  return true;
97  }
98  static bool setUp()
99  {
100  if (! opening_eval_t::setUp())
101  return false;
102  setUpInternal();
103  return true;
104  }
105 
107  static const int ROUND_UP = 64;
109  static int attackDefenseBonusT16(Progress16 black, Progress16 white,
110  Progress16 black_defense,
111  Progress16 white_defense)
112  {
113  return
114  (white.value() * 2 - white_defense.value()
115  - black.value() * 2 + black_defense.value())
116  * 3200 / 2;
117  }
118  static int composeValue(int value_opening, int value_endgame,
119  Progress16 progress16,
120  Progress16 black,
121  Progress16 white,
122  Progress16 black_defense,
123  Progress16 white_defense,
124  int minor_piece_bonus,
127  {
130  assert(progress16.isValid());
131  assert(black.isValid());
132  assert(white.isValid());
133  /*
134  value_opening * (16 - progress16) + value_endgame * progress16
135  + bonus * (white_progress - black_progress) * prorgress16 / 16 */
136  int result = value_opening*16 +
137  progress16.value() * (value_endgame-value_opening +
138  (attackDefenseBonusT16(black, white,
139  black_defense,
140  white_defense))
141  / 16);
142 
143  result += progress_independent_bonus;
144  result += minor_piece_bonus;
145  result += progress_dependent_bonus;
146  result &= ~(ROUND_UP-1);
147  assert(result % 2 == 0);
148  return result;
149  }
150  const Progress16 progress16() const { return current_progress.progress16(); }
151  const Progress16 progress16bonus(Player p) const {
153  }
155  cache=INVALID;
156  }
157  int value() const
158  {
159  if(cache==INVALID)
161  openingValue(),
162  endgame_eval.value(),
163  progress16(),
169  progress16(),
174 
175  return cache;
176  }
177  const Progress32 progress32() const {
178  return Progress32(current_progress.progress16(BLACK).value()
180  }
181  static void setValues(const SimpleState&, Progress16 progress16,
183  static void setValues(const SimpleState& s, container::PieceValues& o);
184 
185  int expect(const NumEffectState& state, Move move) const;
186  Move suggestMove(const NumEffectState&) const
187  {
188  return Move();
189  }
190  void update(const NumEffectState& new_state, Move last_move);
191  template <Player p>
192  int calculateAttackBonusEach(const NumEffectState& state) const;
193  template <Player Attack, Direction Dir>
194  int calculateAttackBonusOne(const NumEffectState& state) const;
195  int calculateKnightCheck(const NumEffectState& state) const;
196  template <osl::Player P>
197  int calculateKnightCheckEach(const NumEffectState& state) const;
198  template <Player p>
199  int calculateEnterKingBonus(const NumEffectState& state) const ;
200  template <Player p>
201  int calculateMiddleKingBonus(const NumEffectState& state) const;
202  int calculateRookRankBonus(const NumEffectState& state) const;
203 
204  public:
205  static int infty()
206  {
207  assert(endgame_eval_t::infty() <= opening_eval_t::infty());
208  // 序盤を使用
209  return composeValue(opening_eval_t::infty(), 0, Progress16(0),
210  Progress16(0), Progress16(0), Progress16(0),
211  Progress16(0), 0, 0, 0);
212  }
213 
214  static int captureValue(PtypeO ptypeO)
215  {
216  return capture_values[ptypeOIndex(ptypeO)];
217  }
218  static int seeScale()
219  {
222  }
223 
224  const PieceMask pins(Player player) const {
225  return pin_mask[player];
226  }
227  // for debug
228  int minorPieceValue() const {
232  }
233  int openingValue() const { return opening_eval.value(); }
234  int endgameValue() const { return endgame_eval.value(); }
235  ProgressDebugInfo debugInfo(const NumEffectState& state) const;
236 
237  // public for debugging purpose only
238  // also updates pin_mask
239  int calculatePinBonus(const NumEffectState& state) const;
240  int calculateMobilityBonus() const;
241  static int calculateMobilityBonusRook(const NumEffectState& state);
242  static int calculateMobilityBonusBishop(const NumEffectState& state);
243  static int calculateMobilityBonusLance(const NumEffectState& state);
244  int calculateAttackRooks(const NumEffectState& state) const;
245  int calculateAttackBonus(const NumEffectState& state) const;
246  int calculateSilverPenalty(const NumEffectState& state) const;
247  int calculateGoldPenalty(const NumEffectState& state) const;
248 
249  int attackDefenseBonus() const
250  {
251  return progress16().value()
256  / 16;
257  }
258  int attackBonusScale(int val, Player attack) const
259  {
260  return val * current_progress.progress16(alt(attack)).value() / 16 * 4;
261  }
262  void debug() const {}
265  static void resetWeights(const int *weight);
266  };
267 
268  typedef PiecePairPieceEval progress_eval_opening_t;
269  class ProgressEval : public ProgressEvalGeneral<progress_eval_opening_t>
270  {
271  public:
272  explicit ProgressEval(const NumEffectState& state)
274  {
275  }
277  : ProgressEvalGeneral<progress_eval_opening_t>(NumEffectState())
278  {
279  }
281  };
282  } // namespace eval
283  using eval::ProgressEval;
284 } // namespace osl
285 
286 #endif /* EVAL_PROGRESSEVAL_H */
287 // ;;; Local Variables:
288 // ;;; mode:c++
289 // ;;; c-basic-offset:2
290 // ;;; End: