Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
lib
state
historyState.cc
Go to the documentation of this file.
1
/* historyState.cc
2
*/
3
#include "
osl/state/historyState.h
"
4
5
osl::state::HistoryState::HistoryState
()
6
: dirty(false)
7
{
8
assert(
current
.
isConsistent
());
9
assert(
initial_state
.
isConsistent
());
10
}
11
12
osl::state::HistoryState::HistoryState
(
const
SimpleState
& initial)
13
: initial_state(initial), current(initial), dirty(false)
14
{
15
assert(
current
.
isConsistent
());
16
assert(
initial_state
.
isConsistent
());
17
}
18
19
osl::state::HistoryState::~HistoryState
()
20
{
21
}
22
23
void
osl::state::HistoryState::setRoot
(
const
SimpleState
& initial)
24
{
25
initial_state = current =
NumEffectState
(initial);
26
moves
.clear();
27
dirty =
false
;
28
}
29
30
void
osl::state::HistoryState::makeMove
(
Move
move)
31
{
32
if
(dirty)
33
update
();
34
moves
.push_back(move);
35
current.makeMove(move);
36
}
37
38
void
osl::state::HistoryState::unmakeMove
()
39
{
40
dirty =
true
;
41
moves
.pop_back();
42
}
43
44
void
osl::state::HistoryState::makeMovePass
()
45
{
46
makeMove(
Move::PASS
(state().turn()));
47
}
48
49
void
osl::state::HistoryState::unmakeMovePass
()
50
{
51
assert(!
moves
.empty() &&
moves
.back().isPass());
52
if
(! dirty) {
53
moves
.pop_back();
54
current.changeTurn();
55
return
;
56
}
57
unmakeMove();
58
}
59
60
void
osl::state::HistoryState::update
()
const
61
{
62
current = initial_state;
63
for
(
size_t
i=0; i<
moves
.size(); ++i)
64
current.makeMove(
moves
[i]);
65
dirty =
false
;
66
}
67
68
// ;;; Local Variables:
69
// ;;; mode:c++
70
// ;;; c-basic-offset:2
71
// ;;; End:
Generated on Sun Jul 21 2013 13:37:24 by
1.8.4