Index   Main   Namespaces   Classes   Hierarchy   Annotated   Files   Compound   Global   Pages  

SpLibertyPlayer.cpp

Go to the documentation of this file.
00001 //----------------------------------------------------------------------------
00002 /** @file SpLibertyPlayer.cpp
00003     See SpLibertyPlayer.h
00004 */
00005 //----------------------------------------------------------------------------
00006 
00007 #include "SgSystem.h"
00008 #include "SpLibertyPlayer.h"
00009 
00010 #include "GoBoardUtil.h"
00011 #include "SgConnCompIterator.h"
00012 
00013 using GoBoardUtil::ExpandToBlocks;
00014 using GoBoardUtil::MoveLegalAndNotAtari;
00015 
00016 //----------------------------------------------------------------------------
00017 
00018 int SpLibertyMoveGenerator::Score(SgPoint p)
00019 // high score for playing liberties of weak blocks
00020 // AR may be suicidal.
00021 {
00022     SgPointSet nb;
00023     const int size = m_board.Size();
00024     nb.Include(p);
00025     nb = nb.Border(size) & m_board.Occupied();
00026     ExpandToBlocks(m_board, nb);
00027 
00028     int score(INT_MIN);
00029 
00030     if (MoveLegalAndNotAtari(m_board, p))
00031     {
00032         score = m_board.NumEmptyNeighbors(p);
00033         for (SgConnCompIterator it(nb, m_board.Size()); it; ++it)
00034         { 
00035             int nuLibs = ((*it).Border(size) & m_board.AllEmpty()).Size();
00036             if (nuLibs == 1)
00037                 score += 20;
00038             else if (nuLibs == 2)
00039                 score += 10;
00040             else if (nuLibs == 3)
00041                 score += 5;
00042             else if (nuLibs == 4)
00043                 score += 3;
00044             else
00045                 ++score;
00046         }
00047     }
00048     return score;
00049 }
00050 
00051 /** counts surplus liberties of all blocks, those above 2.
00052     penalty for less than 2 liberties.
00053     @todo make threshold of 2 variable, experiment
00054 */
00055 int LibertyMinus2(const GoBoard& board, SgBlackWhite color)
00056 {
00057     int nuLibs = 0;
00058     const int size = board.Size();
00059     for (SgConnCompIterator it(board.All(color), board.Size()); it; ++it)
00060     {
00061         nuLibs += ((*it).Border(size) & board.AllEmpty()).Size() - 2;
00062     }
00063     return nuLibs;
00064 }
00065 


17 Jun 2010 Doxygen 1.4.7