All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
historyTable.h
Go to the documentation of this file.
1 /* historyTable.h
2  */
3 #ifndef OSL_HISTORYTABLE_H
4 #define OSL_HISTORYTABLE_H
5 
6 #include "osl/move.h"
7 #include "osl/misc/carray.h"
8 #include "osl/misc/carray2d.h"
9 #include "osl/stl/vector.h"
10 #ifdef OSL_SMP
11 # include "osl/misc/lightMutex.h"
12 #endif
13 #include <iosfwd>
14 namespace osl
15 {
16  namespace search
17  {
19  {
20  public:
21  struct Entry
22  {
23  uint64_t value;
24 #ifdef OSL_SMP
25  mutable LightMutex mutex;
26 #endif
27  Entry() : value(0)
28  {
29  }
30  };
31  private:
32  CArray<CArray2d<Entry,Square::SIZE, Square::SIZE>,2> table;
33  public:
34  uint64_t value(Move move) const
35  {
36  if (! move.isNormal())
37  return 0;
38  const int from_index = move.isDrop() ? (int)move.ptype() : (int)move.from().uintValue();
39  const Entry& e = table[move.player()][from_index][move.to().uintValue()];
40  return e.value;
41  }
42  void add(Move move, int inc)
43  {
44  if (! move.isNormal())
45  return;
46  const int from_index = move.isDrop() ? (int)move.ptype() : (int)move.from().uintValue();
47  Entry& e = table[move.player()][from_index][move.to().uintValue()];
48 #ifdef OSL_SMP
49  SCOPED_LOCK(lk, e.mutex);
50 #endif
51  e.value += inc;
52  }
53  void clear(Move move)
54  {
55  if (! move.isNormal())
56  return;
57  const int from_index = move.isDrop() ? (int)move.ptype() : (int)move.from().uintValue();
58  Entry& e = table[move.player()][from_index][move.to().uintValue()];
59  e.value = 0;
60  }
61  struct OutputEntry
62  {
65  uint64_t value;
66  explicit OutputEntry(int i=0, int j=0, uint64_t v=0)
67  : from_or_ptype(i), to(Square::makeDirect(j)), value(v)
68  {
69  }
70  bool operator>(const OutputEntry& r) const
71  {
72  if (value != r.value)
73  return value > r.value;
75  return from_or_ptype > r.from_or_ptype;
76  return to > r.to;
77  }
78  };
79  void extractTopN(Player p, vector<OutputEntry>& out, size_t limit) const;
80  };
81  std::ostream& operator<<(std::ostream&, const HistoryTable::OutputEntry&);
82  }
83 };
84 
85 #endif /* OSL_HISTORYTABLE_H */
86 // ;;; Local Variables:
87 // ;;; mode:c++
88 // ;;; c-basic-offset:2
89 // ;;; End: