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