double basisfield::Peek(unsigned int vi, FieldIndex fi) { if (vi<0 || vi>=FieldSz()) {throw BasisfieldException("basisfield::PeekField:: Voxel index out of bounds");} if (!coef) {return(0.0);} // Consider field as zero if no coefficients set if (!UpToDate(fi)) {Update(fi);} return(UnsafePeek(vi,fi)); }
void GoSafetySolver::GenBlocksRegions() { if (UpToDate()) /* */ return; /* */ GoStaticSafetySolver::GenBlocksRegions(); Regions()->GenChains(); // merge blocks adjacent to 1-vital with 2 conn. points for (SgBWIterator it; it; ++it) { SgBlackWhite color(*it); for (SgVectorIteratorOf<GoRegion> it(Regions()->AllRegions(color)); it; ++it) { GoRegion* r = *it; r->ComputeFlag(GO_REGION_STATIC_1VITAL); } bool changed = true; while (changed) { changed = false; for (SgVectorIteratorOf<GoRegion> it(Regions()->AllRegions(color)); it; ++it) { GoRegion* r = *it; if ( r->GetFlag(GO_REGION_STATIC_1VC) && r->Chains().IsLength(2) && r->Has2Conn() // || r->Safe2Cuts(Board()) changed from && to || // @todo does not work if blocks are already chains??? // must explicitly keep chain libs info. ) // easy case of only 2 chains { GoChain* c1 = r->Chains().Front(); GoChain* c2 = r->Chains().Back(); Merge(c1, c2, r, false); // false = not by search changed = true; break; // to leave iteration } else if ( r->GetFlag(GO_REGION_STATIC_1VITAL) && r->GetFlag(GO_REGION_CORRIDOR) && ! r->GetFlag(GO_REGION_USED_FOR_MERGE) ) { GoChain* c1 = 0; GoChain* c2 = 0; if (r->Find2Mergable(&c1, &c2)) { Merge(c1, c2, r, false); changed = true; break; // to leave iteration } } } } } m_code = Board().GetHashCode(); }
boost::shared_ptr<NEWMAT::ColumnVector> basisfield::get(FieldIndex fi) { if (!coef) {throw BasisfieldException("basisfield::Get: Coefficients undefined");} if (!UpToDate(fi)) { Update(fi); } return(field[fi]); }
void GoRegionBoard::ExecuteMovePrologue() { if (! UpToDate()) // full recomputation { if (DEBUG_REGION_BOARD) SgDebug() << "recompute everything\n"; GenBlocksRegions(); } }
// @todo: as a first cut, this simply checks if the regions has any // stones in it. It does not check if the move is suitable for capturing the // stones. bool GoSafetySolver::PotentialCaptureMove(SgPoint p, SgBlackWhite regionColor) const { SG_ASSERT(UpToDate()); SG_ASSERT(Board().ToPlay() == regionColor); const GoRegion* r = Regions()->RegionAt(p, regionColor); SG_ASSERT(r); return r->Points().Overlaps(Board().All(SgOppBW(regionColor))); }
double basisfield::Peek(unsigned int x, unsigned int y, unsigned int z, FieldIndex fi) { if (x<0 || y<0 || z<0 || x>=FieldSz_x() || y>=FieldSz_y() || z>=FieldSz_z()) { throw BasisfieldException("basisfield::PeekField:: Co-ordinates out of bounds"); } if (!coef) {return(0.0);} // Consider field as zero if no coefficients set if (!UpToDate(fi)) {Update(fi);} return(UnsafePeek(z*FieldSz_x()*FieldSz_y()+y*FieldSz_x()+x,fi)); }
void GoRegionBoard::ReInitializeBlocksRegions() { SG_ASSERT(UpToDate()); for (SgBWIterator it; it; ++it) { SgBlackWhite color(*it); for (SgVectorIteratorOf<GoBlock> it(AllBlocks(color)); it; ++it) (*it)->ReInitialize(); for (SgVectorIteratorOf<GoRegion> it2(AllRegions(color)); it2; ++it2) (*it2)->ReInitialize(); } }
void GoUctFeatureKnowledge:: ProcessPosition(std::vector<SgUctMoveInfo>& moves) { SG_ASSERT(UpToDate()); const GoBoard& bd = GoAdditiveKnowledge::Board(); SG_DEBUG_ONLY(bd); for (std::vector<SgUctMoveInfo>::iterator it = moves.begin(); it != moves.end(); ++it) { const SgPoint move = it->m_move; SG_ASSERT(bd.IsLegal(move)); const float moveValue = MoveValue(move); it->m_predictorValue = m_param.PredictorValue(-moveValue); } }
void GoRegionBoard::CheckConsistency() const { SG_ASSERT(CHECK && UpToDate()); for (SgBWIterator it; it; ++it) { SgBlackWhite color(*it); SgPointSet blockArea, regionArea; for (SgVectorIteratorOf<GoRegion> it(AllRegions(color)); it; ++it) { SG_ASSERT((*it)->Points().Disjoint(regionArea)); SG_ASSERT((*it)->Points().Disjoint(blockArea)); (*it)->CheckConsistency(); regionArea |= (*it)->Points(); } for (SgVectorIteratorOf<GoBlock> it(AllBlocks(color)); it; ++it) { SG_ASSERT((*it)->Stones().Disjoint(regionArea)); SG_ASSERT((*it)->Stones().Disjoint(blockArea)); for (SgSetIterator it2((*it)->Stones()); it2; ++it2) SG_ASSERT(m_block[*it2] == *it); (*it)->CheckConsistency(); blockArea |= (*it)->Stones(); } SG_ASSERT(blockArea.Disjoint(regionArea)); SG_ASSERT((blockArea | regionArea) == Board().AllPoints()); // check m_region array for (SgPoint p = SgPointUtil::Pt(1, 1); p <= SgPointUtil::Pt(SG_MAX_SIZE, SG_MAX_SIZE); ++p) { SG_ASSERT((m_region[color][p] == 0) != regionArea.Contains(p)); } } // check block array for (SgPoint p = SgPointUtil::Pt(1, 1); p <= SgPointUtil::Pt(SG_MAX_SIZE, SG_MAX_SIZE); ++p) { GoBlock* block = m_block[p]; SG_DEBUG_ONLY(block); SG_ASSERT((block != 0) == Board().Occupied().Contains(p)); } }
GoBlock* GoRegionBoard::GetBlock(const SgPointSet& boundary, SgBlackWhite color) const { SG_ASSERT(UpToDate()); for (SgVectorIteratorOf<GoBlock> it(AllBlocks(color)); it; ++it) { if (boundary.SubsetOf((*it)->Stones())) /* */ return *it; /* */ } SgDebug() << "ERROR: no block on set"; const int size = Board().Size(); boundary.Write(SgDebug(), size); SgDebug() << "blocks:"; for (SgVectorIteratorOf<GoBlock> it(AllBlocks(color));it; ++it) (*it)->Stones().Write(SgDebug(), size); SG_ASSERT(false); return 0; }
void basisfield::AsVolume(volume<float>& vol, FieldIndex fi) { if (int(FieldSz_x()) != vol.xsize() || int(FieldSz_y()) != vol.ysize() || int(FieldSz_z()) != vol.zsize()) { throw BasisfieldException("basisfield::AsVolume:: Matrix size mismatch beween field and volume"); } if (Vxs_x() != vol.xdim() || Vxs_y() != vol.ydim() || Vxs_z() != vol.zdim()) { throw BasisfieldException("basisfield::AsVolume:: Voxel size mismatch beween field and volume"); } if (!coef) {throw BasisfieldException("basisfield::AsVolume: Coefficients undefined");} if (!UpToDate(fi)) {Update(fi);} const boost::shared_ptr<NEWMAT::ColumnVector> tmptr = Get(fi); int vindx=0; for (unsigned int k=0; k<FieldSz_z(); k++) { for (unsigned int j=0; j<FieldSz_y(); j++) { for (unsigned int i=0; i<FieldSz_x(); i++) { vol(i,j,k) = tmptr->element(vindx++); } } } }
void GoRegionBoard::GenBlocksRegions() { if (UpToDate()) return; Clear(); GenBlocks(); for (SgBWIterator it; it; ++it) { SgBlackWhite color(*it); for (SgConnCompIterator it(AllPoints() - All(color), Board().Size()); it; ++it) GenRegion(*it, color); } FindBlocksWithEye(); m_code = Board().GetHashCode(); m_invalid = false; if (HEAVYCHECK) CheckConsistency(); }
void GoUctFeatureKnowledge:: SetPriorKnowledge(std::vector<SgUctMoveInfo>& moves) { SG_ASSERT(UpToDate()); ClearValues(); switch (m_param.m_priorKnowledgeType) { case PRIOR_SIMPLE: SetPriorsSimple(moves); break; case PRIOR_SCALE_NU_GAMES: SetPriorsScaleNuGames(moves); break; case PRIOR_SCALE_PROBABILITIES_LINEAR: SetPriorsScaleProbabilitiesLinearly(moves); break; case PRIOR_TOP_N: SetPriorsTopN(moves); break; default: SG_ASSERT(false); } AddValuesTo(moves); }