repetitionCounter.h Source File

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
repetitionCounter.h
Go to the documentation of this file.
1 /* repetitionCounter.h
2 */
3 #ifndef OSL_REPETITIONCOUNTER_H
4 #define OSL_REPETITIONCOUNTER_H
5
6 #include "osl/move.h"
7 #include "osl/state/numEffectState.h"
8 #include "osl/hash/hashKeyStack.h"
9 #include "osl/stl/slist.h"
10 #include "osl/stl/vector.h"
11 #include "osl/sennichite.h"
12 #include <boost/scoped_ptr.hpp>
13 #include <cassert>
14 #include <iosfwd>
15 namespace osl
16 {
22 class RepetitionCounter
23 {
24 struct Table;
25 boost::scoped_ptr<Table> table;
26 CArray<osl::vector<int>, 2> continuous_check;
27 HashKeyStack hash_history;
28 int order() const { return hash_history.size(); }
29 public:
30 typedef osl::slist<int> list_t;
31
32 RepetitionCounter();
33 RepetitionCounter(const RepetitionCounter& c);
34 explicit RepetitionCounter(const NumEffectState& initial);
35 ~RepetitionCounter();
36
37 private:
38 void push(const HashKey& new_key, bool is_check);
39 public:
43 void push(const NumEffectState& state, Move move);
47 void push(const NumEffectState& state);
51 void push(const HashKey& key, const NumEffectState& state);
52 void pop();
53 void clear();
54
55 const Sennichite isSennichite(const NumEffectState& state, Move move) const;
56 private:
57 const Sennichite isAlmostSennichiteUnsafe(int first_move) const
58 {
59 assert(first_move >= 0);
60 const int duration = (order() - first_move) / 2;
61 if (continuous_check[BLACK].back() >= duration)
62 return Sennichite::BLACK_LOSE();
63 if (continuous_check[WHITE].back() >= duration)
64 return Sennichite::WHITE_LOSE();
65 return Sennichite::DRAW();
66 }
67 public:
71 const Sennichite isAlmostSennichite(const HashKey& key) const
72 {
73 const int first_move = getFirstMove(key);
74 if (first_move < 0)
75 return Sennichite::NORMAL();
76 return isAlmostSennichiteUnsafe(first_move);
77 }
79 const std::pair<Sennichite,int> distanceToSennichite(const HashKey& key) const;
80 unsigned int countRepetition(const HashKey&) const;
81 const list_t getRepetitions(const HashKey&) const;
82 void printMatches(const HashKey& key) const;
87 int getLastMove(const HashKey& key) const;
92 int getFirstMove(const HashKey& key) const;
93 int checkCount(Player attack) const {
94 assert(! continuous_check[attack].empty());
95 return continuous_check[attack].back();
96 }
97 const HashKeyStack& history() const { return hash_history; }
98 bool isConsistent() const;
99
100 static bool maybeEqual(const RepetitionCounter& l, const RepetitionCounter& r);
101 };
102
103 }
104
105 #endif /* OSL_REPETITIONCOUNTER_H */
106 // ;;; Local Variables:
107 // ;;; mode:c++
108 // ;;; c-basic-offset:2
109 // ;;; End: