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