All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
stateInfo.h
Go to the documentation of this file.
1 /* stateInfo.h
2  */
3 #ifndef OSL_MOVE_PROBABILITY_STATEINFO_H
4 #define OSL_MOVE_PROBABILITY_STATEINFO_H
5 
10 #include "osl/stl/vector.h"
12 #include "osl/container/square8.h"
15 #include <algorithm>
16 
17 namespace osl
18 {
19  namespace move_probability
20  {
21  struct StateInfo
22  {
23  const NumEffectState *state;
24  const MoveStack *history;
25  Progress16 progress16;
27  CArray<Piece,2> threatened;
28  typedef FixedCapacityVector<int,8> long_attack_t;
29  CArray2d<long_attack_t,40,8> long_attack_cache; // BlockLong
30  typedef CArray<int,16> pattern_square_t;
31  CArray<pattern_square_t,Square::SIZE> pattern_cache;
32  CArray2d<bool,40,2> attack_shadow;
33  PieceMask last_add_effect;
35  CArray<PieceMask,2> pin;
37  Square8 sendoffs;
38  typedef FixedCapacityVector<PinnedGeneral,64> pinned_gs_t;
39  CArray<pinned_gs_t,2> exchange_pins;
40  CArray<bool,2> move_candidate_exists; // king => bool
41  mutable NumEffectState copy;
42  BoardMask changed_effects;
43  CArray<std::pair<Piece,Square>,2> checkmate_defender;
45  CArray<Move,2> bookmove;
46  bool dirty;
47 
48  StateInfo() : state(0), history(0), progress16(0), dirty(true)
49  {
50  }
51  StateInfo(const NumEffectState& s, Progress16 p, const MoveStack& h,
52  Move t=Move())
53  : state(&s), history(&h), progress16(p), dirty(true)
54  {
55  clearOldCache();
56  threatmate_move = t;
57  finishUpdate();
58  }
59  void reset0(const NumEffectState& s, Progress16 p)
60  {
61  dirty = true;
62  state = &s;
63  progress16 = p;
64  pin_by_opposing_sliders.clear();
65  king8_long_pieces.clear();
67  clearOldCache();
68  }
69  void reset1(const MoveStack& h)
70  {
71  history = &h;
72  }
73  void finishUpdate();
74  void reset(const NumEffectState& s, Progress16 p,
75  const MoveStack& h, Move threatmate_move=Move())
76  {
77  reset0(s, p);
78  reset1(h);
80  finishUpdate();
81  }
82  void setThreatmate(Move move) { threatmate_move = move; }
83 
84  bool pinByOpposingSliders(Piece p) const
85  {
87  p) != pin_by_opposing_sliders.end();
88  }
90  {
91  return King8Info(state->Iking8Info(pl));
92  }
93  int progress8() const { return progress16.value()/2; }
94  static std::pair<Piece,Square> findCheckmateDefender(const NumEffectState& state, Player king);
95  static Move findShortThreatmate(const NumEffectState&, Move last_move);
96  private:
97  void clearOldCache();
98  void updateDelayed();
99  void makePinOfLongPieces();
100  void makeLongAttacks();
101  void updatePinnedGenerals(Player owner);
102  };
103  bool operator==(const StateInfo& l, const StateInfo& r);
104  }
105 }
106 
107 #endif /* OSL_MOVE_PROBABILITY_STATEINFO_H */
108 // ;;; Local Variables:
109 // ;;; mode:c++
110 // ;;; c-basic-offset:2
111 // ;;; End: