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