00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef GO_LADDER_H
00012 #define GO_LADDER_H
00013
00014 #include "GoBoard.h"
00015 #include "SgBoardColor.h"
00016 #include "GoModBoard.h"
00017 #include "SgPoint.h"
00018 #include "SgPointSet.h"
00019 #include "SgVector.h"
00020
00021
00022
00023 enum GoLadderStatus
00024 {
00025
00026 GO_LADDER_UNKNOWN,
00027
00028
00029 GO_LADDER_CAPTURED,
00030
00031
00032 GO_LADDER_UNSETTLED,
00033
00034
00035 GO_LADDER_ESCAPED
00036 };
00037
00038
00039
00040
00041 class GoLadder
00042 {
00043 public:
00044 GoLadder();
00045
00046
00047
00048
00049
00050
00051
00052 int Ladder(const GoBoard& bd, SgPoint prey, SgBlackWhite toPlay,
00053 SgVector<SgPoint>* sequence, bool twoLibIsEscape = false);
00054
00055 private:
00056
00057
00058
00059 static const int MAX_LADDER_MOVES = 200;
00060
00061
00062 int m_maxMoveNumber;
00063
00064 GoBoard* m_bd;
00065
00066 SgPointSet m_partOfPrey;
00067
00068 SgBlackWhite m_preyColor;
00069
00070 SgBlackWhite m_hunterColor;
00071
00072 bool CheckMoveOverflow() const;
00073
00074 void InitMaxMoveNumber();
00075
00076 bool PointIsAdjToPrey(SgPoint p);
00077
00078 bool BlockIsAdjToPrey(SgPoint p, int numAdj);
00079
00080 void MarkStonesAsPrey(SgPoint p, SgVector<SgPoint>* stones = 0);
00081
00082 void FilterAdjacent(GoPointList& adjBlocks);
00083
00084 int PlayHunterMove(int depth, SgPoint move, SgPoint lib1, SgPoint lib2,
00085 const GoPointList& adjBlk,
00086 SgVector<SgPoint>* sequence);
00087
00088 int PlayPreyMove(int depth, SgPoint move, SgPoint lib1,
00089 const GoPointList& adjBlk, SgVector<SgPoint>* sequence);
00090
00091 bool IsSnapback(SgPoint prey);
00092
00093 int PreyLadder(int depth, SgPoint lib1, const GoPointList& adjBlk,
00094 SgVector<SgPoint>* sequence);
00095
00096 int HunterLadder(int depth, SgPoint lib1, const GoPointList& adjBlk,
00097 SgVector<SgPoint>* sequence);
00098
00099 int HunterLadder(int depth, SgPoint lib1, SgPoint lib2,
00100 const GoPointList& adjBlk, SgVector<SgPoint>* sequence);
00101
00102 void ReduceToBlocks(GoPointList& stones);
00103 };
00104
00105
00106
00107 namespace GoLadderUtil {
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118 bool Ladder(const GoBoard& board, SgPoint prey, SgBlackWhite toPlay,
00119 bool fTwoLibIsEscape = false, SgVector<SgPoint>* sequence = 0);
00120
00121
00122
00123
00124
00125
00126
00127
00128 GoLadderStatus LadderStatus(const GoBoard& bd, SgPoint prey,
00129 bool fTwoLibIsEscape = false,
00130 SgPoint* toCapture = 0, SgPoint* toEscape = 0);
00131
00132
00133
00134
00135
00136
00137
00138
00139 bool IsProtectedLiberty(const GoBoard& bd, SgPoint liberty, SgBlackWhite col,
00140 bool& byLadder, bool& isKoCut, bool tryLadder = true);
00141
00142
00143 bool IsProtectedLiberty(const GoBoard& bd, SgPoint liberty, SgBlackWhite col);
00144
00145 SgPoint TryLadder(const GoBoard& bd, SgPoint prey, SgBlackWhite firstPlayer);
00146
00147 }
00148
00149
00150
00151 #endif // GO_LADDER_H
00152