00001 //---------------------------------------------------------------------------- 00002 /** @file SpSimplePlayer.cpp 00003 See SpSimplePlayer.h */ 00004 //---------------------------------------------------------------------------- 00005 00006 #include "SgSystem.h" 00007 #include "SpSimplePlayer.h" 00008 00009 #include <limits> 00010 #include <cstdio> 00011 #include <iostream> 00012 #include <string> 00013 #include "GoSafetySolver.h" 00014 #include "SgDebug.h" 00015 #include "SgEvaluatedMoves.h" 00016 #include "SgNode.h" 00017 #include "SgWrite.h" 00018 #include "SpCapturePlayer.h" 00019 #include "SpMoveGenerator.h" 00020 #include "SpRandomPlayer.h" 00021 #include "SpUtil.h" 00022 00023 //---------------------------------------------------------------------------- 00024 00025 SpSimplePlayer::SpSimplePlayer(const GoBoard& board, 00026 SpMoveGenerator* generator) 00027 : GoPlayer(board), 00028 m_generator(generator), 00029 m_randomGenerator(new SpRandomMoveGenerator(board)) 00030 { 00031 } 00032 00033 SpSimplePlayer::~SpSimplePlayer() 00034 { 00035 SG_ASSERT(m_generator); 00036 SG_ASSERT(m_randomGenerator); 00037 delete m_generator; 00038 m_generator = 0; 00039 delete m_randomGenerator; 00040 m_randomGenerator = 0; 00041 } 00042 00043 int SpSimplePlayer::MoveValue(SgPoint p) 00044 { 00045 SgPointSet relevant = Board().AllEmpty(); 00046 if (UseFilter()) 00047 { 00048 GoSafetySolver solver(Board()); 00049 SgBWSet safe; 00050 solver.FindSafePoints(&safe); 00051 relevant -= safe[SG_BLACK]; 00052 relevant -= safe[SG_WHITE]; 00053 } 00054 if (relevant[p]) 00055 { 00056 return m_generator->EvaluateMove(p); 00057 } 00058 return std::numeric_limits<int>::min(); 00059 } 00060 00061 SgPoint SpSimplePlayer::GenMove(const SgTimeRecord& time, SgBlackWhite toPlay) 00062 { 00063 SG_UNUSED(time); 00064 SgPointSet relevant = 00065 SpUtil::GetRelevantMoves(Board(), toPlay, UseFilter()); 00066 // Generate moves. 00067 SgEvaluatedMovesArray moves(relevant); 00068 00069 // note: generators can disable certain unwanted moves by calling 00070 // Disable(p) 00071 m_generator->GenerateMoves(moves, toPlay); 00072 // Generate random moves if no other found 00073 if ((moves.BestMove() == SG_PASS) && m_randomGenerator) 00074 m_randomGenerator->GenerateMoves(moves, toPlay); 00075 return moves.BestMove(); 00076 } 00077 00078 //---------------------------------------------------------------------------- 00079