Index   Main   Namespaces   Classes   Hierarchy   Annotated   Files   Compound   Global   Pages  

SpUtil.cpp

Go to the documentation of this file.
00001 //----------------------------------------------------------------------------
00002 /** @file SpUtil.cpp
00003 */
00004 //----------------------------------------------------------------------------
00005 
00006 #include "SgSystem.h"
00007 #include "SpUtil.h"
00008 
00009 #include "GoBoard.h"
00010 #include "GoSafetySolver.h"
00011 
00012 using namespace std;
00013 
00014 //----------------------------------------------------------------------------
00015 
00016 SgPointSet SpUtil::GetRelevantMoves(GoBoard& bd, SgBlackWhite toPlay,
00017                                     bool useFilter)
00018 {
00019     SgPointSet legal;
00020     for (SgSetIterator it(bd.AllEmpty()); it; ++it)
00021         if (bd.IsLegal(*it))
00022             legal.Include(*it);
00023     if (! useFilter)
00024         return legal;
00025     GoSafetySolver safetySolver(bd);
00026     SgBWSet safe;
00027     safetySolver.FindSafePoints(&safe);
00028     SgBlackWhite opp = SgOppBW(toPlay);
00029     SgPointSet moves;
00030     const GoRules& rules = bd.Rules();
00031     const bool captureDead = rules.CaptureDead();
00032     //const bool japaneseScoring = rules.JapaneseScoring();
00033     for (SgSetIterator it(legal); it; ++it)
00034     {
00035         SgPoint p = *it;
00036         const bool isSafe = safe[toPlay].Contains(p);
00037         const bool isSafeOpp = safe[opp].Contains(p);
00038         const bool hasOppNeighbors = bd.HasNeighbors(p, opp);
00039         if (  (! isSafe && ! isSafeOpp)
00040            || (isSafe && captureDead && hasOppNeighbors)
00041            // || (isSafeOpp && ! japaneseScoring)
00042            )
00043             moves.Include(p);
00044     }
00045     return moves;
00046 }
00047 
00048 //----------------------------------------------------------------------------
00049 


17 Jun 2010 Doxygen 1.4.7