Index   Main   Namespaces   Classes   Hierarchy   Annotated   Files   Compound   Global   Pages  

SgMiaiMap.cpp

Go to the documentation of this file.
00001 //----------------------------------------------------------------------------
00002 /** @file SgMiaiMap.cpp
00003     See SgMiaiMap.h
00004 */
00005 //----------------------------------------------------------------------------
00006 
00007 #include "SgSystem.h"
00008 #include "SgMiaiMap.h"
00009 
00010 #include "SgWrite.h"
00011 
00012 //----------------------------------------------------------------------------
00013 
00014 SgMiaiMap::SgMiaiMap() 
00015     : m_forcedMove(SG_NULLPOINT),
00016       m_failed(false),
00017       m_map(SgArray<int,SG_MAXPOINT>(SG_NULLPOINT))
00018 {
00019 }
00020     
00021 /** See SgStrategy::ExecuteMove */
00022 void SgMiaiMap::ExecuteMove(SgPoint p, SgBlackWhite player)
00023 {
00024     if (m_forcedMove != SG_NULLPOINT)
00025     {
00026         SG_ASSERT(m_forcedMove == p);
00027         m_forcedMove = SG_NULLPOINT;
00028     }
00029     else if (m_map[player][p] != SG_NULLPOINT)
00030     {
00031         m_forcedMove = m_map[player][p];
00032         m_map[player][p] = SG_NULLPOINT;
00033         m_map[player][m_forcedMove] = SG_NULLPOINT; // too early???
00034         
00035         SgBlackWhite opp = SgOppBW(player);
00036         SgPoint temp = m_map[opp][p];
00037         if (temp != SG_NULLPOINT)
00038         {
00039             SG_ASSERT(temp != SG_NULLPOINT);
00040             m_map[opp][p] = SG_NULLPOINT;
00041             SG_ASSERT(m_map[opp][temp] == p);
00042             m_map[opp][temp] = SG_NULLPOINT;
00043         }
00044     }
00045 }
00046 
00047 SgStrategyStatus SgMiaiMap::Status() const
00048 {
00049     return m_failed ? SGSTRATEGY_FAILED :
00050            m_forcedMove != SG_NULLPOINT ? SGSTRATEGY_THREATENED :
00051            SGSTRATEGY_ACHIEVED;
00052 }
00053 
00054 void SgMiaiMap::ConvertFromSgMiaiStrategy(const SgMiaiStrategy& s)
00055 {
00056     SG_ASSERT(! s.HasOverlappingMiaiPairs());
00057     
00058     const SgBlackWhite player = s.Player();
00059     for (SgVectorIterator<SgMiaiPair> it(s.MiaiStrategies()); it; ++it)
00060     {
00061         const SgPoint p1 = (*it).first;
00062         const SgPoint p2 = (*it).second;
00063         SG_ASSERT(m_map[player][p1] == SG_NULLPOINT);
00064         SG_ASSERT(m_map[player][p2] == SG_NULLPOINT);
00065         m_map[player][p1] = p2;
00066         m_map[player][p2] = p1;
00067     }
00068     const SgPoint m = s.OpenThreatMove();
00069     if (m != SG_NULLPOINT)
00070         m_forcedMove = m;
00071 }
00072 
00073 void SgMiaiMap::ConvertToSgMiaiStrategy(SgMiaiStrategy* s) const
00074 {
00075     SG_UNUSED(s);
00076     SG_ASSERT(false);
00077 }
00078 
00079 //----------------------------------------------------------------------------


17 Jun 2010 Doxygen 1.4.7