All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
attackDefense.h
Go to the documentation of this file.
1 
4 #ifndef EVAL_ENDGAME_ATTACKtDEFENSE_H
5 #define EVAL_ENDGAME_ATTACKtDEFENSE_H
6 
9 #include "osl/eval/pieceEval.h"
10 #include "osl/eval/evalTraits.h"
11 #include "osl/misc/carray.h"
12 
13 namespace osl
14 {
15  namespace container
16  {
17  class PieceValues;
18  } // namespace container
19  namespace eval
20  {
21  namespace endgame
22  {
28  {
29  CArray<int,2> values;
30  void reset() { values.fill(0); }
31  void addValue(Player owner, int value)
32  {
33  values[playerToIndex(owner)] += value;
34  }
35  void addValue(Piece king_black, Piece king_white, Piece target)
36  {
37  assert(king_black.ptype() == KING);
38  assert(king_white.ptype() == KING);
39  assert(king_black.owner() == BLACK);
40  assert(king_white.owner() == WHITE);
41  addValue(target.owner(), valueOf(king_black, king_white, target));
42  }
43  public:
44  explicit AttackDefense(const SimpleState&);
45  void changeTurn() {}
46  static bool initialized() { return true; }
47 
48  int value() const { return values[0] + values[1]; }
49  int value(Player p) const { return values[playerToIndex(p)]; }
50 
51  void update(const SimpleState& new_state, Move last_move);
52 
53  int expect(const SimpleState& state, Move move) const;
54  private:
55  void updateKingMove(const SimpleState&, Square from, Square to);
56  void updateKingMove(const SimpleState&, Square from, Square to,
57  Piece target);
58  public:
59  static int infty()
60  {
61  return PieceEval::infty()*2; // 2倍未満のボーナス
62  }
63 
64  static int valueOf(Piece black_king, Piece white_king,
65  Piece target)
66  {
67  return valueOf(black_king, white_king,
68  target.ptypeO(), target.square());
69  }
70  static int valueOf(Piece black_king, Piece white_king,
71  PtypeO ptypeo, Square position)
72  {
73  assert(black_king.owner() == BLACK);
74  assert(white_king.owner() == WHITE);
75 
76  const Player player = getOwner(ptypeo);
77  const Piece my_king
78  = (player == BLACK) ? black_king : white_king;
79  const Piece op_king
80  = (player == BLACK) ? white_king : black_king;
81 
82  const int attack = AttackKing::valueOf(op_king, ptypeo, position);
83  const int defense = DefenseKing::valueOf(my_king, ptypeo, position);
84 
85  return max(player, attack, defense);
86  }
87  static void setValues(const SimpleState&, container::PieceValues&);
88  static void resetWeights(const int *w);
89  };
90  } // namespace endgame
91  } // namespace endgame
92 } // namespace osl
93 
94 #endif /* EVAL_ENDGAME_ATTACKKING_H */
95 // ;;; Local Variables:
96 // ;;; mode:c++
97 // ;;; c-basic-offset:2
98 // ;;; End: