All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
pieceEval.h
Go to the documentation of this file.
1 /* pieceEval.h
2  */
3 #ifndef OSL_PIECEEVAL_H
4 #define OSL_PIECEEVAL_H
5 
7 #include "osl/eval/evalTraits.h"
11 #include "osl/misc/carray.h"
12 #include <cassert>
13 
14 namespace osl
15 {
16  namespace eval
17  {
19  {
20  protected:
21  CArray<int, PTYPEO_SIZE> ptypeO2Val;
22  CArray<int, PTYPEO_SIZE> promoteVal;
23  CArray<int, PTYPEO_SIZE> captureVal;
24  public:
27 
28  public:
32  int value(PtypeO ptypeO) const{
33  assert(isValidPtypeO(ptypeO));
34  return ptypeO2Val[ptypeO-PTYPEO_MIN];
35  }
39  int value(Ptype ptype) const{
40  assert(isValid(ptype));
41  return ptypeO2Val[ptype-PTYPEO_MIN];
42  }
46  int promoteValue(PtypeO ptypeO) const{
47  assert(isPromoted(ptypeO));
48  return promoteVal[ptypeO-PTYPEO_MIN];
49  }
53  int captureValue(PtypeO ptypeO) const{
54  assert(isValidPtypeO(ptypeO));
55  return captureVal[ptypeO-PTYPEO_MIN];
56  }
57  void reset(const CArray<int, PTYPE_SIZE>& values);
58  };
59  extern const PtypeEvalTable Ptype_Eval_Table;
60 
67  class PieceEval
68  {
69  int val;
70  public:
71  explicit PieceEval(const NumEffectState& state);
72  explicit PieceEval(int v) : val(v) {}
73  PieceEval();
74  static bool initialized() { return true; }
75  void changeTurn() {}
76  int value() const
77  {
78  assert(isConsistentValueForNormalState<PieceEval>(val));
79  return val;
80  }
81  static int diffWithMove(const NumEffectState&, Move move)
82  {
83  int ret = 0;
84  if (move.capturePtype() != PTYPE_EMPTY)
86  if (move.isPromotion())
88  return ret;
89  }
90  static int infty() { return 57984; }
91 
103  template<Player P>
104  static int computeDiffAfterMove(const NumEffectState& state,Move move);
105  static int computeDiffAfterMove(const NumEffectState& state,Move move)
106  {
107  assert(state.turn() == move.player());
108  if (state.turn() == BLACK)
109  return computeDiffAfterMove<BLACK>(state,move);
110  else
111  return computeDiffAfterMove<WHITE>(state,move);
112  }
119  template<Player P>
120  static int computeDiffAfterMoveForRP(const NumEffectState& state,Move move)
121  {
122  assert(move.player()==P);
123  const int diff = computeDiffAfterMove<P>(state,move);
124  return (P==BLACK) ? diff : -diff;
125  }
126  static int computeDiffAfterMoveForRP(const NumEffectState& state, Move move)
127  {
128  if (move.player()==BLACK)
129  return computeDiffAfterMoveForRP<BLACK>(state,move);
130  else
131  return computeDiffAfterMoveForRP<WHITE>(state,move);
132  }
133  private:
134  void addVal(int d) { val+=d; }
135  public:
136  const Move suggestMove(const NumEffectState&) const
137  {
138  return Move();
139  }
141  int expect(const NumEffectState& /*state*/, Move move) const
142  {
143  if (move.isPass() || move.isDrop())
144  return value();
145  const PtypeO ptypeO=move.ptypeO();
146  const PtypeO captured=move.capturePtypeOSafe();
147  int result = val
148  + Ptype_Eval_Table.value(ptypeO)
149  - Ptype_Eval_Table.value(move.oldPtypeO());
150  if (getPtype(captured) != PTYPE_EMPTY)
151  result += Ptype_Eval_Table.value(osl::captured(captured))
152  - Ptype_Eval_Table.value(captured);
153  return result;
154  }
155 
156  const Progress32 progress32() const { return Progress32(0); }
157  const Progress16 progress16() const { return Progress16(0); }
158  static int seeScale() { return 1; }
162  static int captureValue(PtypeO ptypeO)
163  {
164  return Ptype_Eval_Table.captureValue(ptypeO);
165  }
166  static int value(PtypeO ptypeO)
167  {
168  return Ptype_Eval_Table.value(ptypeO);
169  }
170 
171  void update(const NumEffectState& /*new_state*/, Move last_move)
172  {
173  if (last_move.isPass() || last_move.isDrop())
174  return;
175 
176  addVal(Ptype_Eval_Table.value(last_move.ptypeO())
177  - Ptype_Eval_Table.value(last_move.oldPtypeO()));
178  if (last_move.capturePtype() != PTYPE_EMPTY) {
179  const PtypeO capture_ptypeo = last_move.capturePtypeO();
180  addVal(Ptype_Eval_Table.value(captured(capture_ptypeo))
181  - Ptype_Eval_Table.value(capture_ptypeo));
182  }
183  }
184 
186  };
187 
188  } // namespace eval
189  using eval::PieceEval;
190 } // namespace osl
191 
192 #endif /* OSL_PIECEEVAL_H */
193 // ;;; Local Variables:
194 // ;;; mode:c++
195 // ;;; c-basic-offset:2
196 // ;;; End: