protected void CreateEnclosedRegions() { if (ColorEnclosedRegions == null) { ColorEnclosedRegions = new ColorEnclosedRegions(this); } }
protected void Clear() { AllBlocks = new List <GoBlockBase>(); GoEmptyBlock lEmptyBlock = new GoEmptyBlock(this); UndoStack = new UndoStack(this); Turn = Color.Black; ZobrishHashes = new Dictionary <ZobristHash, int>(); LastMove = CoordinateSystem.PASS; MoveList = new List <KeyValuePair <Color, int> >(); SimpleKoPoint = CoordinateSystem.PASS; MoveNbr = 0; Komi = 0; GameOver = false; CapturedStoneCnt = new int[2]; ColorEnclosedRegions = null; SafetyStatusMap = null; ZobristHash = new ZobristHash(); Cells = new GoCell[Coord.BoardArea]; for (int i = 0; i < Coord.BoardArea; i++) { Cells[i] = new GoCell(i, this, lEmptyBlock); } for (int i = 0; i < Coord.BoardArea; i++) { Cells[i].SetNeighbors(); } }
public void Undo() { int lUndoMove = LastMove; ColorEnclosedRegions = null; SafetyStatusMap = null; UndoStack.Undo(); if (ZobrishHashes.Count > 0) { int lMove; if (!ZobrishHashes.TryGetValue(ZobristHash, out lMove)) { return; } if (lMove == MoveNbr) { ZobrishHashes.Remove(ZobristHash); } } //#if DEBUG // if (!_SelfTest()) // Console.WriteLine("GoBoard::_SelfTest() Failed"); //#endif }
public GoBoardUndoState(GoBoard goBoard) { Turn = goBoard.Turn; SimpleKoPoint = goBoard.SimpleKoPoint; Komi = goBoard.Komi; CapturedStoneCnt0 = goBoard.CapturedStoneCnt[0]; CapturedStoneCnt1 = goBoard.CapturedStoneCnt[1]; LastMove = goBoard.LastMove; SafetyStatusMap = goBoard.SafetyStatusMap; GameOver = goBoard.GameOver; ColorEnclosedRegions = goBoard.ColorEnclosedRegions; }
public int CountSafePoints(Color color, SafetySolverType pSafetySolverType) { if ((SafetyStatusMap != null) && (SafetyStatusMap.SafetySolverType == pSafetySolverType)) { CreateEnclosedRegions(); return(SafetyStatusMap.CountSafePoints(color)); } else { ColorEnclosedRegions lColorEnclosedRegions = ColorEnclosedRegions; ColorEnclosedRegions = null; CreateEnclosedRegions(); SafetyMap lSafetyStatusMap = new SafetyMap(this, pSafetySolverType); ColorEnclosedRegions = lColorEnclosedRegions; return(lSafetyStatusMap.CountSafePoints(color)); } }
public void SetSafetySolver(SafetySolverType pSafetySolverType) { SafetySolver = pSafetySolverType; SafetyStatusMap = null; ColorEnclosedRegions = null; }
public bool PlayStone(int index, Color color, bool allowUndo) { if (!IsLegal(index, color)) { return(false); } if (allowUndo) { UndoStack.Mark(); UndoStack.Add(new GoBoardUndoState(this)); } else { UndoStack.Clear(); } if (index == CoordinateSystem.RESIGN) { GameOver = true; } if ((index == CoordinateSystem.PASS) && (LastMove == CoordinateSystem.PASS) && (MoveNbr > 0)) { GameOver = true; } ColorEnclosedRegions = null; SafetyStatusMap = null; // set turn Turn = color; LastMove = index; MoveList.Add(new KeyValuePair <Color, int>(color, index)); // save hash if (LastMove != CoordinateSystem.PASS) { if (!ZobrishHashes.ContainsKey(ZobristHash)) { ZobrishHashes.Add(ZobristHash.Clone(), MoveNbr); } } // increment move number MoveNbr++; // Console.WriteLine("# " + MoveNbr + " " + color.ToString() + " " + Coord.ToString(index)); // Dump(); SimpleKoPoint = CoordinateSystem.PASS; if (!(index == CoordinateSystem.PASS) || (index == CoordinateSystem.RESIGN)) { // update blocks ExecutePlay(index, color, allowUndo); } //#if DEBUG // if (!_SelfTest()) // Console.WriteLine("GoBoard::_SelfTest() Failed"); //#endif return(true); }
protected void CreateEnclosedRegions() { if (ColorEnclosedRegions == null) ColorEnclosedRegions = new ColorEnclosedRegions(this); }
protected void Clear() { AllBlocks = new List<GoBlockBase>(); GoEmptyBlock lEmptyBlock = new GoEmptyBlock(this); UndoStack = new UndoStack(this); Turn = Color.Black; ZobrishHashes = new Dictionary<ZobristHash, int>(); LastMove = CoordinateSystem.PASS; MoveList = new List<KeyValuePair<Color, int>>(); SimpleKoPoint = CoordinateSystem.PASS; MoveNbr = 0; Komi = 0; GameOver = false; CapturedStoneCnt = new int[2]; ColorEnclosedRegions = null; SafetyStatusMap = null; ZobristHash = new ZobristHash(); Cells = new GoCell[Coord.BoardArea]; for (int i = 0; i < Coord.BoardArea; i++) Cells[i] = new GoCell(i, this, lEmptyBlock); for (int i = 0; i < Coord.BoardArea; i++) Cells[i].SetNeighbors(); }
public void Undo() { int lUndoMove = LastMove; ColorEnclosedRegions = null; SafetyStatusMap = null; UndoStack.Undo(); if (ZobrishHashes.Count > 0) { int lMove; if (!ZobrishHashes.TryGetValue(ZobristHash, out lMove)) return; if (lMove == MoveNbr) ZobrishHashes.Remove(ZobristHash); } //#if DEBUG // if (!_SelfTest()) // Console.WriteLine("GoBoard::_SelfTest() Failed"); //#endif }
public bool PlayStone(int index, Color color, bool allowUndo) { if (!IsLegal(index, color)) return false; if (allowUndo) { UndoStack.Mark(); UndoStack.Add(new GoBoardUndoState(this)); } else UndoStack.Clear(); if (index == CoordinateSystem.RESIGN) GameOver = true; if ((index == CoordinateSystem.PASS) && (LastMove == CoordinateSystem.PASS) && (MoveNbr > 0)) GameOver = true; ColorEnclosedRegions = null; SafetyStatusMap = null; // set turn Turn = color; LastMove = index; MoveList.Add(new KeyValuePair<Color, int>(color, index)); // save hash if (LastMove != CoordinateSystem.PASS) if (!ZobrishHashes.ContainsKey(ZobristHash)) ZobrishHashes.Add(ZobristHash.Clone(), MoveNbr); // increment move number MoveNbr++; // Console.WriteLine("# " + MoveNbr + " " + color.ToString() + " " + Coord.ToString(index)); // Dump(); SimpleKoPoint = CoordinateSystem.PASS; if (!(index == CoordinateSystem.PASS) || (index == CoordinateSystem.RESIGN)) { // update blocks ExecutePlay(index, color, allowUndo); } //#if DEBUG // if (!_SelfTest()) // Console.WriteLine("GoBoard::_SelfTest() Failed"); //#endif return true; }
public int CountSafePoints(Color color, SafetySolverType pSafetySolverType) { if ((SafetyStatusMap != null) && (SafetyStatusMap.SafetySolverType == pSafetySolverType)) { CreateEnclosedRegions(); return SafetyStatusMap.CountSafePoints(color); } else { ColorEnclosedRegions lColorEnclosedRegions = ColorEnclosedRegions; ColorEnclosedRegions = null; CreateEnclosedRegions(); SafetyMap lSafetyStatusMap = new SafetyMap(this, pSafetySolverType); ColorEnclosedRegions = lColorEnclosedRegions; return lSafetyStatusMap.CountSafePoints(color); } }