00001 //---------------------------------------------------------------------------- 00002 /** @file GoBoardHistory.cpp 00003 See GoBoardHistory.h */ 00004 //---------------------------------------------------------------------------- 00005 00006 #include "SgSystem.h" 00007 #include "GoBoardHistory.h" 00008 00009 using namespace std; 00010 00011 //---------------------------------------------------------------------------- 00012 00013 void GoBoardHistory::SetFromBoard(const GoBoard& bd) 00014 { 00015 m_boardSize = bd.Size(); 00016 m_rules = bd.Rules(); 00017 m_setup = bd.Setup(); 00018 m_moves.Clear(); 00019 for (int i = 0; i < bd.MoveNumber(); ++i) 00020 m_moves.PushBack(bd.Move(i)); 00021 m_toPlay = bd.ToPlay(); 00022 } 00023 00024 bool GoBoardHistory::IsAlternatePlayFollowUpOf(const GoBoardHistory& other, 00025 vector<SgPoint>& sequence) 00026 { 00027 if (m_boardSize != other.m_boardSize 00028 || m_rules != other.m_rules 00029 || m_setup != other.m_setup 00030 || m_moves.Length() < other.m_moves.Length()) 00031 return false; 00032 for (int i = 0; i < other.m_moves.Length(); ++i) 00033 if (m_moves[i] != other.m_moves[i]) 00034 return false; 00035 sequence.clear(); 00036 SgBlackWhite toPlay = other.m_toPlay; 00037 for (int i = other.m_moves.Length(); i < m_moves.Length(); ++i) 00038 { 00039 GoPlayerMove m = m_moves[i]; 00040 if (m.Color() != toPlay) 00041 return false; 00042 sequence.push_back(m.Point()); 00043 toPlay = SgOppBW(toPlay); 00044 } 00045 if (toPlay != m_toPlay) 00046 return false; 00047 return true; 00048 } 00049 00050 //----------------------------------------------------------------------------