Index   Main   Namespaces   Classes   Hierarchy   Annotated   Files   Compound   Global   Pages  

SpSimplePlayer.cpp

Go to the documentation of this file.
00001 //----------------------------------------------------------------------------
00002 /** @file SpSimplePlayer.cpp
00003     See SpSimplePlayer.h
00004 */
00005 //----------------------------------------------------------------------------
00006 
00007 #include "SgSystem.h"
00008 #include "SpSimplePlayer.h"
00009 
00010 #include <limits>
00011 #include <cstdio>
00012 #include <iostream>
00013 #include <string>
00014 #include "GoSafetySolver.h"
00015 #include "SgDebug.h"
00016 #include "SgEvaluatedMoves.h"
00017 #include "SgNode.h"
00018 #include "SgWrite.h"
00019 #include "SpCapturePlayer.h"
00020 #include "SpMoveGenerator.h"
00021 #include "SpRandomPlayer.h"
00022 #include "SpUtil.h"
00023 
00024 //----------------------------------------------------------------------------
00025 
00026 SpSimplePlayer::SpSimplePlayer(GoBoard& board, 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 


17 Jun 2010 Doxygen 1.4.7