00001 /* historyState.cc 00002 */ 00003 #include "osl/state/historyState.h" 00004 #include "osl/apply_move/applyMove.h" 00005 #include "osl/misc/fastCopier.h" 00006 00007 osl::state::HistoryState::HistoryState() 00008 : dirty(false) 00009 { 00010 assert(current.isConsistent()); 00011 assert(initial_state.isConsistent()); 00012 } 00013 00014 osl::state::HistoryState::HistoryState(const SimpleState& initial) 00015 : initial_state(initial), current(initial), dirty(false) 00016 { 00017 assert(current.isConsistent()); 00018 assert(initial_state.isConsistent()); 00019 } 00020 00021 osl::state::HistoryState::~HistoryState() 00022 { 00023 } 00024 00025 void osl::state::HistoryState::setRoot(const SimpleState& initial) 00026 { 00027 initial_state = current = NumEffectState(initial); 00028 moves.clear(); 00029 dirty = false; 00030 } 00031 00032 void osl::state::HistoryState::makeMove(Move move) 00033 { 00034 if (dirty) 00035 update(); 00036 moves.push_back(move); 00037 ApplyMoveOfTurn::doMove(current, move); 00038 } 00039 00040 void osl::state::HistoryState::unmakeMove() 00041 { 00042 dirty = true; 00043 moves.pop_back(); 00044 } 00045 00046 void osl::state::HistoryState::makeMovePass() 00047 { 00048 makeMove(Move::PASS(state().getTurn())); 00049 } 00050 00051 void osl::state::HistoryState::unmakeMovePass() 00052 { 00053 assert(! moves.empty() && moves.back().isPass()); 00054 if (! dirty) { 00055 moves.pop_back(); 00056 current.changeTurn(); 00057 return; 00058 } 00059 unmakeMove(); 00060 } 00061 00062 void osl::state::HistoryState::update() const 00063 { 00064 current = initial_state; 00065 for (size_t i=0; i<moves.size(); ++i) 00066 ApplyMoveOfTurn::doMove(current, moves[i]); 00067 dirty = false; 00068 } 00069 00070 // ;;; Local Variables: 00071 // ;;; mode:c++ 00072 // ;;; c-basic-offset:2 00073 // ;;; End: