[go: up one dir, main page]

Menu

[r9]: / trunk / rlgo / RlTracker.h  Maximize  Restore  History

Download this file

147 lines (103 with data), 4.3 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
//----------------------------------------------------------------------------
/** @file RlTracker.h
Base class for incrementally tracking evaluation and active set
*/
//----------------------------------------------------------------------------
#ifndef RLTRACKER_H
#define RLTRACKER_H
#include "RlActiveSet.h"
#include "RlUtils.h"
class RlDirtySet;
class RlMoveFilter;
//----------------------------------------------------------------------------
/** Base class for incrementally tracking active set of binary features */
class RlTracker
{
public:
RlTracker(GoBoard& board);
virtual ~RlTracker() { }
/** Initialise tracker after (multi-stage) construction is complete */
virtual void Initialise();
/** Clear changes, reset, and apply changes */
void DoReset();
/** Clear changes, execute, and apply changes */
void DoExecute(SgMove move, SgBlackWhite colour);
/** Clear changes, and execute without applying changes */
void DoEvaluate(SgMove move, SgBlackWhite colour);
/** Undo and apply changes */
void DoUndo();
/** Update dirty points for specified move */
virtual void UpdateDirty(SgMove move, SgBlackWhite colour,
RlDirtySet& dirty);
/** Size of active set */
virtual int GetActiveSize() const = 0;
/** Debug output */
virtual void Display(std::ostream& ostr) { SG_UNUSED(ostr); }
/** Current list of changes (after GenMove, Execute or Undo) */
const RlChangeList& ChangeList() const { return m_changeList; }
/** Currently active features */
const RlActiveSet& Active() const { return m_active; }
/** Remember current position for fast resets */
virtual void SetMark() { m_mark = true; }
virtual void ClearMark() { m_mark = false; }
bool MarkSet() const { return m_mark; }
/** Specify whether undo functionality is supported */
virtual bool SupportUndo() const { return false; }
//-------------------------------------------------------------------------
/* The previous functions provide the main API, and should be preferred.
Certain compound trackers may need to control the order of calling,
for which the following functions are provided for finer control. */
/** Reset evaluation and features to current board position */
virtual void Reset();
/** Update features from this move
Called after board is updated */
virtual void Execute(SgMove move, SgBlackWhite colour, bool execute);
/** Update features from undo
Called after board is updated */
virtual void Undo();
/** Track changes to features after evaluation change */
virtual void TrackEval(int q, RlFloat eval,
bool execute, bool incremental);
/** Clear all changes including child trackers */
virtual void ClearChanges();
/** Propagate changes from child trackers */
virtual void PropagateChanges();
/** Add current change list into active set, and store for undo */
virtual void AddChanges(bool store);
/** Restore change list from undo stack, and subtract from active set */
virtual void SubChanges();
/** Colour graph to make sure that tracker doesn't get duplicate calls */
void Tick() { m_tick++; }
int Tock() const { return m_tick; }
protected:
void StoreChanges();
void RestoreChanges();
void NewChange(int slot, int featureindex, RlOccur occurrences);
void MakeChangesToClearActive();
void MarkAtarisDirty(SgMove move, SgBlackWhite colour);
void MarkAllDirty();
protected:
GoBoard& m_board; //@todo: constify
private:
RlActiveSet m_active;
bool m_mark;
int m_tick;
RlChangeList m_changeList;
struct ChangeStack
{
std::vector<RlChangeList> m_stack;
int m_capacity;
int m_numChangeLists;
ChangeStack();
void Clear();
void Store(const RlChangeList& changelist);
void Restore(RlChangeList& changelist);
} m_changeStack;
};
inline void RlTracker::NewChange(int slot, int featureindex,
RlOccur occurrences)
{
m_changeList.Change(RlChange(slot, featureindex, occurrences));
}
//----------------------------------------------------------------------------
#endif // RLTRACKER_H