Index   Main   Namespaces   Classes   Hierarchy   Annotated   Files   Compound   Global   Pages  

GoBoardHistory.cpp

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


17 Jun 2010 Doxygen 1.4.7