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


Sun Mar 13 2011 Doxygen 1.7.1