-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpotentialmove.hpp
71 lines (68 loc) · 1.84 KB
/
potentialmove.hpp
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
#ifndef POTENTIALMOVE_HPP
#define POTENTIALMOVE_HPP
#include "def.hpp"
class PotentialMove {
public:
PotentialMove(ExtendedSteps potentialMove_=ExtendedSteps()) :
potentialMove(std::move(potentialMove_)),
afterCurrentStep(potentialMove.end()) {}
ExtendedSteps current() const
{
return ExtendedSteps(potentialMove.begin(),afterCurrentStep);
}
const ExtendedSteps& all() const
{
return potentialMove;
}
bool empty() const
{
return afterCurrentStep==potentialMove.begin();
}
const ExtendedStep& back() const
{
return *prev(afterCurrentStep);
}
void clear()
{
potentialMove.clear();
afterCurrentStep=potentialMove.end();
}
void set(ExtendedSteps potentialMove_,const unsigned int offset)
{
potentialMove=std::move(potentialMove_);
afterCurrentStep=next(potentialMove.begin(),offset);
}
void append(const ExtendedSteps& steps)
{
if (startsWith(ExtendedSteps(afterCurrentStep,potentialMove.cend()),steps))
shiftEnd(steps.size());
else {
potentialMove.erase(afterCurrentStep,potentialMove.cend());
::append(potentialMove,steps);
afterCurrentStep=potentialMove.end();
}
}
void shiftEnd(const int numSteps)
{
assert(numSteps<=distance(afterCurrentStep,potentialMove.cend()));
assert(-numSteps<=distance(potentialMove.cbegin(),afterCurrentStep));
advance(afterCurrentStep,numSteps);
}
bool shiftEnd(const bool forward,const bool all)
{
const auto endPoint=(forward ? potentialMove.end() : potentialMove.begin());
if (afterCurrentStep==endPoint)
return false;
else {
if (all)
afterCurrentStep=endPoint;
else
advance(afterCurrentStep,forward ? 1 : -1);
return true;
}
}
private:
ExtendedSteps potentialMove;
ExtendedSteps::const_iterator afterCurrentStep;
};
#endif // POTENTIALMOVE_HPP