All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
piecePairWithStand.h
Go to the documentation of this file.
1 /* piecePairWithStand.h
2  */
3 #ifndef EVAL_PPAIR_PIECEPAIRWITHSTAND_H
4 #define EVAL_PPAIR_PIECEPAIRWITHSTAND_H
5 
7 #include "osl/eval/pieceEval.h"
8 
9 namespace osl
10 {
11  namespace eval
12  {
13  namespace ppair
14  {
22  template <class Table>
24  : public PiecePairEval<PiecePairWithStand<Table>,Table>
25  {
26  public:
27  static int standBonus(PtypeO ptypeo)
28  {
29  assert(isBasic(getPtype(ptypeo)));
30  if (isMajorBasic(getPtype(ptypeo)))
31  return Table::Piece_Value.value(newPtypeO(getOwner(ptypeo), PAWN));
32  return 0;
33  }
34  static int standBonus(const SimpleState& state);
35 
37  explicit PiecePairWithStand(const SimpleState& state);
38  protected:
40  public:
41  static int diffAfterDropMove(const SimpleState& state,Square to,PtypeO ptypeo)
42  {
43  const int bonus = standBonus(ptypeo);
44  return base_t::diffAfterDropMove(state,to,ptypeo) - bonus;
45  }
46  static int diffAfterSimpleMove(const SimpleState& state,
47  Square from, Square to,
48  int promote_mask)
49  {
50  int diff = base_t::diffAfterSimpleMove(state, from, to, promote_mask);
51  if (promote_mask) {
52  const Piece old_piece=state.pieceAt(from);
53  const PtypeO newPtypeO = promoteWithMask(old_piece.ptypeO(), promote_mask);
54  diff += Table::Piece_Value.promoteValue(newPtypeO);
55  }
56  return diff;
57  }
58  static int diffAfterCaptureMove(const SimpleState& state,
59  Square from, Square to,
60  PtypeO victim,int promote_mask)
61  {
62  const PtypeO captured = osl::captured(victim);
63  int bonus = standBonus(captured);
64  if (promote_mask) {
65  const Piece old_piece=state.pieceAt(from);
66  const PtypeO newPtypeO = promoteWithMask(old_piece.ptypeO(), promote_mask);
67  bonus += Table::Piece_Value.promoteValue(newPtypeO);
68  }
69  return base_t::diffAfterCaptureMove(state,from,to,victim,promote_mask)
70  + Table::Piece_Value.captureValue(victim) + bonus;
71  }
72  static int diffWithUpdate(const SimpleState& new_state, Move last_move)
73  {
74  int diff = base_t::diffWithUpdate(new_state, last_move);
75  if (last_move.isDrop()) {
76  const int bonus = standBonus(last_move.ptypeO());
77  return diff - bonus;
78  }
79  if (last_move.isPromotion())
80  diff += Table::Piece_Value.promoteValue(last_move.ptypeO());
81  if (last_move.capturePtype() != PTYPE_EMPTY) {
82  const PtypeO captured = last_move.capturePtypeO();
83  const int bonus = standBonus(osl::captured(captured));
84  diff += Table::Piece_Value.captureValue(captured) + bonus;
85  }
86  return diff;
87  }
88  static void setValues(const SimpleState&, container::PieceValues&);
89  };
90 
91  } // namespace ppair
92  } // namespace eval
93 } // namespace osl
94 
95 
96 #endif /* EVAL_PPAIR_PIECEPAIRWITHSTAND_H */
97 // ;;; Local Variables:
98 // ;;; mode:c++
99 // ;;; c-basic-offset:2
100 // ;;; End: