00001
00002
00003
00004
00005
00006
00007 #include "SgSystem.h"
00008 #include "SpLadderPlayer.h"
00009
00010 #include "GoLadder.h"
00011 #include "GoMoveExecutor.h"
00012 #include "SgConnCompIterator.h"
00013 #include "SgEvaluatedMoves.h"
00014
00015 using GoLadderUtil::LadderStatus;
00016
00017
00018
00019 int SpLadderMoveGenerator::Score(SgPoint p)
00020 {
00021 SG_UNUSED(p);
00022
00023
00024 SG_ASSERT(false);
00025 return INT_MIN;
00026 }
00027
00028 void SpLadderMoveGenerator::GenerateMoves(SgEvaluatedMoves& eval,
00029 SgBlackWhite toPlay)
00030 {
00031
00032 GoRestoreToPlay restoreToPlay(m_board);
00033 m_board.SetToPlay(toPlay);
00034 GoRestoreSuicide restoreSuicide(m_board, false);
00035 for (SgBlackWhite color = SG_BLACK; color <= SG_WHITE; ++color)
00036 {
00037 for (SgConnCompIterator it(m_board.All(color), m_board.Size());
00038 it; ++it)
00039 {
00040 SgPointSet block(*it);
00041 SgPoint p = block.PointOf(), toCapture, toEscape;
00042 GoLadderStatus st = LadderStatus(m_board, p, false, &toCapture,
00043 &toEscape);
00044 if (st == GO_LADDER_UNSETTLED)
00045 {
00046 SgPoint move =
00047 color == m_board.ToPlay() ? toEscape : toCapture;
00048 int size = 1000 * block.Size();
00049 eval.AddMove(move, size);
00050 if ((color == m_board.ToPlay()) && (move == SG_PASS))
00051 {
00052
00053 for (GoBoard::LibertyIterator it(m_board, p); it; ++it)
00054 {
00055 SgPoint lib = *it;
00056 GoMoveExecutor m(m_board, lib, color);
00057 if (m.IsLegal() && m_board.Occupied(p))
00058 {
00059 SgPoint toCapture2, toEscape2;
00060 GoLadderStatus st2 =
00061 LadderStatus(m_board, p, false, &toCapture2,
00062 &toEscape2);
00063 if (st2 == GO_LADDER_ESCAPED)
00064 eval.AddMove(lib, size);
00065 }
00066 }
00067 }
00068 }
00069 }
00070 }
00071 }
00072
00073
00074