bool GoLadderUtil::IsProtectedLiberty(const GoBoard& bd1, SgPoint liberty, SgBlackWhite col, bool& byLadder, bool& isKoCut, bool tryLadder) { byLadder = false; isKoCut = false; GoModBoard mbd(bd1); GoBoard& bd = mbd.Board(); const SgBlackWhite toPlay = bd1.ToPlay(); bd.SetToPlay(SgOppBW(col)); bool isProtected; if (! PlayIfLegal(bd, liberty)) isProtected = bd.LastMoveInfo(GO_MOVEFLAG_SUICIDE); // opponent cannot play there else { if (bd.LastMoveInfo(GO_MOVEFLAG_SUICIDE)) isProtected = true; else { if (bd.InAtari(liberty)) { if (bd.NumStones(liberty) > 1) isProtected = true; else { SgPoint p = bd.TheLiberty(liberty); if (PlayIfLegal(bd, p)) { isProtected = (bd.NumStones(p) != 1) || (bd.NumLiberties(p) != 1); // yes, can re-capture there bd.Undo(); } else isProtected = false; if (! isProtected) isKoCut = true; } } else if (tryLadder) { isProtected = Ladder(bd, liberty, bd.ToPlay(), true); if (isProtected) byLadder = true; } else // don't try ladder isProtected = false; } bd.Undo(); } bd.SetToPlay(toPlay); return isProtected; }
void GoBoardHistory::SetFromBoard(const GoBoard& bd) { m_boardSize = bd.Size(); m_rules = bd.Rules(); m_setup = bd.Setup(); m_moves.Clear(); for (int i = 0; i < bd.MoveNumber(); ++i) m_moves.PushBack(bd.Move(i)); m_toPlay = bd.ToPlay(); }
GoSetup GoSetupUtil::CurrentPosSetup(const GoBoard& bd) { GoSetup setup; setup.m_player = bd.ToPlay(); for (GoBoard::Iterator it2(bd); it2; ++it2) { SgPoint p = *it2; if (bd.Occupied(p)) setup.m_stones[bd.GetColor(p)].Include(p); } return setup; }