00001 //---------------------------------------------------------------------------- 00002 /** @file SpMaxEyePlayer.cpp 00003 */ 00004 //---------------------------------------------------------------------------- 00005 00006 #include "SgSystem.h" 00007 #include "SpMaxEyePlayer.h" 00008 00009 #include "GoEyeUtil.h" 00010 00011 //---------------------------------------------------------------------------- 00012 00013 using namespace std; 00014 00015 //---------------------------------------------------------------------------- 00016 00017 float SpMaxEyeMoveGenerator::Heuristic(SgPoint p, SgBlackWhite colour) 00018 { 00019 // Score is inversely proportional to number of moves to make eye 00020 int nummoves; 00021 bool eyepossible = 00022 GoEyeUtil::NumberOfMoveToEye2(m_board, colour, p, nummoves); 00023 00024 // Impossible eyes are not urgent 00025 if (! eyepossible) 00026 return 0.0f; 00027 00028 // Otherwise the fewer moves to completion, the more urgent to play 00029 if (colour == m_board.Opponent()) 00030 return 1.0f / (static_cast<float>(nummoves) + 1.0f); 00031 00032 // Opponent is to play, so urgency is half a move greater 00033 else 00034 return 1.0f / (static_cast<float>(nummoves) + 0.5f); 00035 } 00036 00037 int SpMaxEyeMoveGenerator::Evaluate() 00038 { 00039 // We are Opponent since this is after executing our move 00040 SgBlackWhite player = m_board.Opponent(); 00041 SgBlackWhite opponent = m_board.ToPlay(); 00042 00043 float sign = 0; 00044 float maxeyescore = -1; 00045 float totaleyescore = 0; 00046 00047 for (GoBoard::Iterator iBoard(m_board); iBoard; ++iBoard) 00048 { 00049 float playerscore = Heuristic(*iBoard, player); 00050 float oppscore = Heuristic(*iBoard, opponent); 00051 00052 totaleyescore += playerscore - oppscore; 00053 00054 if (playerscore > maxeyescore) 00055 { 00056 maxeyescore = playerscore; 00057 sign = 1; 00058 } 00059 00060 if (oppscore > maxeyescore) 00061 { 00062 maxeyescore = oppscore; 00063 sign = -1; 00064 } 00065 } 00066 00067 // Find the point with the maximum eye score 00068 // Tie-break using the total eye score 00069 if (m_eyeGo) 00070 return static_cast<int>( 00071 maxeyescore * sign * 10000.0f + totaleyescore * 100.0f); 00072 00073 // Play to score the most eye-ishly overall 00074 else 00075 return static_cast<int>( 00076 totaleyescore * 100.0f); 00077 } 00078 00079 //---------------------------------------------------------------------------- 00080