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
|
/* historyState.cc
*/
#include "osl/state/historyState.h"
osl::state::HistoryState::HistoryState()
: dirty(false)
{
assert(current.isConsistent());
assert(initial_state.isConsistent());
}
osl::state::HistoryState::HistoryState(const SimpleState& initial)
: initial_state(initial), current(initial), dirty(false)
{
assert(current.isConsistent());
assert(initial_state.isConsistent());
}
osl::state::HistoryState::~HistoryState()
{
}
void osl::state::HistoryState::setRoot(const SimpleState& initial)
{
initial_state = current = NumEffectState(initial);
moves.clear();
dirty = false;
}
void osl::state::HistoryState::makeMove(Move move)
{
if (dirty)
update();
moves.push_back(move);
current.makeMove(move);
}
void osl::state::HistoryState::unmakeMove()
{
dirty = true;
moves.pop_back();
}
void osl::state::HistoryState::makeMovePass()
{
makeMove(Move::PASS(state().turn()));
}
void osl::state::HistoryState::unmakeMovePass()
{
assert(! moves.empty() && moves.back().isPass());
if (! dirty) {
moves.pop_back();
current.changeTurn();
return;
}
unmakeMove();
}
void osl::state::HistoryState::update() const
{
current = initial_state;
for (size_t i=0; i<moves.size(); ++i)
current.makeMove(moves[i]);
dirty = false;
}
// ;;; Local Variables:
// ;;; mode:c++
// ;;; c-basic-offset:2
// ;;; End:
|