Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef GO_REGION_H
00015 #define GO_REGION_H
00016
00017 #include <bitset>
00018 #include <iosfwd>
00019 #include "GoBoard.h"
00020 #include "GoBoardUtil.h"
00021 #include "GoEyeCount.h"
00022 #include "SgVector.h"
00023 #include "SgIncrementalStack.h"
00024 #include "SgMiaiStrategy.h"
00025 #include "SgPointArray.h"
00026
00027 class GoBlock;
00028 class GoChain;
00029 class GoRegionBoard;
00030
00031
00032
00033
00034
00035
00036 enum GoRegionFlag
00037 {
00038 GO_REGION_SMALL,
00039 GO_REGION_CORRIDOR,
00040 GO_REGION_STATIC_1VC,
00041 GO_REGION_1VC,
00042 GO_REGION_STATIC_2V,
00043 GO_REGION_2V,
00044 GO_REGION_SINGLE_BLOCK_BOUNDARY,
00045 GO_REGION_OPP_CAN_LIVE_INSIDE,
00046 GO_REGION_AT_LEAST_SEKI,
00047 GO_REGION_SAFE,
00048 GO_REGION_PROTECTED_CUTS,
00049 GO_REGION_STATIC_1VITAL,
00050 GO_REGION_1VITAL,
00051 GO_REGION_USED_FOR_MERGE,
00052 GO_REGION_VALID,
00053 GO_REGION_COMPUTED_BLOCKS,
00054 GO_REGION_COMPUTED_CHAINS,
00055 GO_REGION_COMPUTED_NAKADE,
00056 _GO_REGION_FLAG_COUNT
00057 };
00058
00059
00060 typedef std::bitset<_GO_REGION_FLAG_COUNT> GoRegionFlags;
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083 class GoRegion
00084 {
00085 public:
00086
00087 GoRegion(const GoBoard& board, const SgPointSet& points,
00088 SgBlackWhite color);
00089
00090
00091 ~GoRegion()
00092 {
00093 #ifndef NDEBUG
00094 ++s_free;
00095 #endif
00096 }
00097
00098
00099 void ReInitialize();
00100
00101
00102 void CheckConsistency() const;
00103
00104
00105
00106 const SgPointSet& Points() const
00107 {
00108 return m_points;
00109 }
00110
00111
00112 SgPointSet Dep() const
00113 {
00114 return m_points.Border(m_bd.Size());
00115 }
00116
00117
00118 SgPointSet AllInsideLibs() const;
00119
00120
00121 const SgVectorOf<GoChain>& Chains() const
00122 {
00123 return m_chains;
00124 }
00125
00126
00127 const SgVectorOf<GoBlock>& Blocks() const
00128 {
00129 return m_blocks;
00130 }
00131
00132
00133
00134 SgVectorOf<GoBlock>& BlocksNonConst()
00135 {
00136 return m_blocks;
00137 }
00138
00139
00140 SgVectorOf<GoBlock> InteriorBlocks() const;
00141
00142
00143 bool IsInteriorBlock(const GoBlock* block) const;
00144
00145
00146 bool IsBoundaryBlock(const GoBlock* block) const
00147 {
00148 return ! IsInteriorBlock(block);
00149 }
00150
00151
00152 SgPointSet BlocksPoints() const;
00153
00154
00155 SgPointSet PointsPlusInteriorBlocks() const;
00156
00157
00158 SgBlackWhite Color() const
00159 {
00160 return m_color;
00161 }
00162
00163
00164 int MinEyes() const {return m_eyes.MinEyes();}
00165
00166
00167 int MaxEyes() const {return m_eyes.MaxEyes();}
00168
00169
00170 int MinPotEyes() const {return m_eyes.MinPotEyes();}
00171
00172
00173 int MaxPotEyes() const {return m_eyes.MaxPotEyes();}
00174
00175
00176 void Write(std::ostream& out) const;
00177
00178
00179 void WriteID(std::ostream& out) const;
00180
00181
00182
00183 bool GetFlag(GoRegionFlag flag) const;
00184
00185
00186 bool ComputeAndGetFlag(GoRegionFlag flag);
00187
00188
00189 bool ComputedFlag(GoRegionFlag flag) const;
00190
00191
00192 void ComputeFlag(GoRegionFlag flag);
00193
00194
00195
00196 void ResetNonBlockFlags()
00197 { m_computedFlags.reset();
00198 m_computedFlags.set(GO_REGION_COMPUTED_BLOCKS);
00199 m_eyes.Clear();
00200 Invalidate();
00201 }
00202
00203
00204 bool IsValid() const {return m_flags.test(GO_REGION_VALID);}
00205
00206
00207 void Invalidate() {m_flags.reset(GO_REGION_VALID);}
00208
00209
00210
00211
00212 void ComputeBasicFlags();
00213
00214
00215 void DoComputeFlag(GoRegionFlag flag);
00216
00217
00218 void SetComputedFlag(GoRegionFlag flag) {m_computedFlags.set(flag);}
00219
00220
00221 void SetFlag(GoRegionFlag flag, bool value)
00222 { m_computedFlags.set(flag);
00223 m_flags.set(flag, value);
00224 }
00225
00226
00227 void Set1VCDepth(int depth) {m_1vcDepth = depth;}
00228
00229
00230
00231 bool Has2ConnForChains(const GoChain* c1, const GoChain* c2) const;
00232
00233
00234 bool Has2Conn() const;
00235
00236
00237 bool HealthyForSomeBlock(const SgVectorOf<GoBlock>& blocks) const;
00238
00239
00240 bool IsSurrounded(const SgVectorOf<GoBlock>& blocks) const;
00241
00242
00243 bool ComputedVitalForDepth(int depth) const;
00244
00245
00246 bool SomeBlockIsSafe() const;
00247
00248
00249 bool AllBlockIsSafe() const;
00250
00251
00252 bool AdjacentToBlock(SgPoint anchor) const;
00253
00254
00255 bool AdjacentToSomeBlock(const SgVector<SgPoint>& anchors) const;
00256
00257
00258 bool Safe2Cuts(const GoBoard& board) const;
00259
00260
00261
00262 bool AllEmptyAreLibs() const;
00263
00264
00265
00266
00267
00268
00269
00270 bool Has2SureLibs(SgMiaiStrategy* miaiStrategy) const;
00271
00272
00273 void InsideLibs(const GoBlock* b, SgVector<SgPoint>* libs) const;
00274
00275
00276 bool HasBlockLibs(const GoBlock* b) const;
00277
00278
00279 bool HasLibsForBlock(const GoBlock* b, int n) const;
00280
00281
00282 bool HasLibForAllBlocks() const;
00283
00284
00285 bool HasLibsForAllBlocks(int n) const;
00286
00287
00288
00289
00290 bool Find2ConnForAll() const;
00291
00292
00293
00294 bool Find2ConnForAllInterior(SgMiaiStrategy* miaiStrategy,
00295 SgVector<SgPoint>& usedLibs) const;
00296
00297
00298
00299
00300 bool Has2IPs(const SgVector<SgPoint>& interiorEmpty, SgMiaiPair* ips)
00301 const;
00302
00303
00304
00305 bool Has2IntersectionPoints(const SgVector<SgPoint>& usedLibs) const;
00306
00307
00308 void GetIPs(SgVector<SgPoint>* ips) const;
00309
00310
00311
00312
00313
00314 void GetDivideMiaiPairs(SgVector<SgMiaiPair>& pairs) const;
00315
00316
00317
00318 void JointLibs(SgVector<SgPoint>* libs) const;
00319
00320
00321 bool IsCorridor() const;
00322
00323
00324 bool ReplaceChain(const GoChain* old, const GoChain* newChain);
00325
00326
00327 bool Find2Mergable(GoChain** c1, GoChain** c2) const;
00328
00329
00330
00331
00332 void Find2FreeLibs(const GoChain* c1, const GoChain* c2,
00333 SgPoint* lib1, SgPoint* lib2) const;
00334
00335
00336 void FindBlocks(const GoRegionBoard& ra);
00337
00338
00339 void SetBlocks(const SgVectorOf<GoBlock>& blocks);
00340
00341
00342
00343 void FindChains(const GoRegionBoard& ra);
00344
00345
00346 void SetToSafe() {SetFlag(GO_REGION_SAFE, true);}
00347
00348
00349
00350 void RemoveBlock(const GoBlock* b);
00351
00352
00353 void OnAddStone(SgPoint p);
00354
00355
00356 void OnRemoveStone(SgPoint p);
00357
00358
00359 static void Fini();
00360
00361 private:
00362
00363
00364 const GoBoard& m_bd;
00365
00366
00367 GoRegionFlags m_flags;
00368
00369
00370 GoRegionFlags m_computedFlags;
00371
00372
00373 SgPointSet m_points;
00374
00375
00376 SgBlackWhite m_color;
00377
00378
00379 SgVectorOf<GoBlock> m_blocks;
00380
00381
00382 SgVectorOf<GoChain> m_chains;
00383
00384
00385 GoEyeCount m_eyes;
00386
00387
00388 SgPoint m_vitalPoint;
00389
00390
00391 int m_1vcDepth;
00392
00393
00394 SgMiaiStrategy m_miaiStrategy;
00395
00396
00397
00398
00399
00400
00401
00402 bool ProtectedCuts(const GoBoard& board) const;
00403
00404
00405
00406 bool ComputeIs1Vital() const;
00407
00408
00409 bool StaticIs1VitalAndConnected() const;
00410
00411
00412 void ComputeNakade();
00413
00414
00415 void ComputeSingleBlockEyeSpace();
00416
00417
00418 void ComputeMultipleBlockEyeSpace();
00419
00420
00421 void ComputeEyeSpace();
00422
00423
00424
00425 void InteriorEmpty(SgVector<SgPoint>* interiorEmpty, int maxNu) const;
00426
00427 #ifndef NDEBUG
00428
00429 static int s_alloc, s_free;
00430 #endif
00431 };
00432
00433 std::ostream& operator<<(std::ostream& stream, const GoRegion& r);
00434
00435
00436
00437 #endif // GO_REGION_H
00438