public bool RemoveDian(GoPoint dian) { if (dian.Type != type_) { return(false); } int index = dian.Coord.GetIndex(size_); if (!dianMap_.ContainsKey(index)) { return(false); } // remove the block; dian.Block = null; dianMap_.Remove(index); ClearQiOfBlock(dian.UP); ClearQiOfBlock(dian.DOWN); ClearQiOfBlock(dian.LEFT); ClearQiOfBlock(dian.RIGHT); if (DianNumber != 0) { CleanQi(); } return(true); }
private bool DetectNeighborBlock(GoPoint dian, GoPoint nextDian) { if (nextDian == null || nextDian.Type == GoPointType.EMPTY) { return(false); } else if (nextDian.Block == null || nextDian.Block.DianNumber == 0) { //Error need refresh throw new Exception("ERROR: The Block of Zi is NULL or EMPTY"); } else if (nextDian.Block.Type != dian.Type) { nextDian.Block.CleanQi(); return(false); } else if (dian.Block != nextDian.Block) { dian.Block.Merge(nextDian.Block); return(true); } else { return(false); } }
public GoPoint GetPointByDirection(GoPoint dian, Direction direction) { int newRow = dian.Coord.Row; int newCol = dian.Coord.Col; switch (direction) { case Direction.UP: newRow--; break; case Direction.DOWN: newRow++; break; case Direction.LEFT: newCol--; break; case Direction.RIGHT: newCol++; break; } return(layout_.GetPoint(new GoCoord(newRow, newCol))); }
private void ClearQiOfBlock(GoPoint dian) { if (dian == null || dian.Block == null) { return; } dian.Block.CleanQi(); }
public void PushStep(GoStep step) { GoPoint point = OnAddChess(step.Coord, step.Type); List <GoCoord> removedList = OnCheckCapture(point); step.SetRemovedList(removedList); steps_.Push(step); OnChessChanged(); }
private void OnRemoveChess(GoPoint point) { if (point.Block != null && point.Block.DianNumber != 0) { GoBlock block = point.Block; block.RemoveDian(point); point.Type = GoPointType.EMPTY; } }
public int GetQi(int row, int col) { GoPoint point = GetPoint(row, col); if (point != null && point.Type != GoPointType.EMPTY) { return(point.Qi); } return(-1); }
private void ResetPoint() { for (int i = 0; i < SIZE; i++) { for (int j = 0; j < SIZE; j++) { GoPoint point = new GoPoint(new GoCoord(i, j), visitor_); layout_[i * SIZE + j] = point; } } }
// public bool SetDian(GoCoord coord, GoDianType type) // { // // else if (dian.Type == type) // { // // no change // return true; // } // else if (type == GoDianType.EMPTY) // { // // Remove Zi // RemoveChess(dian); // return true; // } // else if (dian.Type != GoDianType.EMPTY) // { // // if (!allowChangeZi_) // // { // // //Error need refresh // // GoException.Throw("Cannot change chess, should remove it firstly"); // // } // RemoveChess(dian); // } // dian.Type = type; // dian.Block = new GoBlock(SIZE, dian); // // if (autoTake_) // // { // if (dian.Qi == 0 && !CheckTiZi(dian)) // { // RemoveChess(dian); // return false; // } // else // { // CheckTiZi(dian); // } // /* }*/ // // if (DianChanged != null) // { // DianChanged(); // } // // return true; // } public bool SetupPoint(GoCoord coord, GoPointType type) { GoPoint point = GetPoint(coord); if (point != null && point.Type != type) { OnRemoveChess(point); OnAddChess(coord, type); OnChessChanged(); } return(true); }
private int CalculateCurrentQi(GoPoint dian) { if (dian == null) { return(0); } dian.SetStatusAsVisited(); visitedList_.Add(dian); int qi = 0; qi += CalculateNextQi(dian, dian.UP); qi += CalculateNextQi(dian, dian.DOWN); qi += CalculateNextQi(dian, dian.LEFT); qi += CalculateNextQi(dian, dian.RIGHT); return(qi); }
private void CalculateQi() { if (dianMap_.Count == 0) { throw new Exception("ERROR: Calculate Qi from a empty block"); } if (qi_ != -1) { return; } GoPoint dian = dianMap_.Values.First(); qi_ = CalculateCurrentQi(dian); foreach (GoPoint visited in visitedList_) { visited.ResetStatus(); } visitedList_.Clear(); }
public GoBlock(int size, GoPoint dian) { size_ = size; type_ = dian.Type; ID = ++mainid; if (dian.Block != null) { GoException.Throw("Attempt add a Dian to double Block"); } int index = dian.Coord.GetIndex(size_); dianMap_.Add(index, dian); dian.Block = this; CleanQi(); DetectNeighborBlock(dian, dian.UP); DetectNeighborBlock(dian, dian.DOWN); DetectNeighborBlock(dian, dian.LEFT); DetectNeighborBlock(dian, dian.RIGHT); }
private int CalculateNextQi(GoPoint dian, GoPoint newDian) { int qi = 0; if (newDian == null || newDian.IsVisited()) { return(0); } else if (newDian.Type == GoPointType.EMPTY) { newDian.SetStatusAsVisited(); visitedList_.Add(newDian); qi += 1; } else if (newDian.Type == dian.Type) { qi += CalculateCurrentQi(newDian); } return(qi); }
private GoPoint OnAddChess(GoCoord coord, GoPointType type) { GoPoint point = GetPoint(coord); if (point == null) { GoException.Throw("The Coord is out of bounds"); } else if (point.Type == type) { // no change return(point); } if (point.Type != GoPointType.EMPTY) { GoException.Throw("Should remove the Chess first"); } point.Type = type; point.Block = new GoBlock(SIZE, point); return(point); }
private List <GoCoord> OnCheckCapture(GoPoint point) { List <GoCoord> removedList = new List <GoCoord>(); if (point.UP != null && point.UP.Qi == 0) { removedList.AddRange(RemoveBlock(point.UP.Block)); } if (point.DOWN != null && point.DOWN.Qi == 0) { removedList.AddRange(RemoveBlock(point.DOWN.Block)); } if (point.LEFT != null && point.LEFT.Qi == 0) { removedList.AddRange(RemoveBlock(point.LEFT.Block)); } if (point.RIGHT != null && point.RIGHT.Qi == 0) { removedList.AddRange(RemoveBlock(point.RIGHT.Block)); } return(removedList); }
public bool PopStep() { GoStep step = steps_.Pop(); GoPoint point = GetPoint(step.Coord); OnRemoveChess(point); if (step.Removed.Count != 0) { GoPointType removedType = GoPointType.EMPTY; if (step.Type == GoPointType.BLACK) { removedType = GoPointType.WHITE; } else if (step.Type == GoPointType.WHITE) { removedType = GoPointType.BLACK; } foreach (GoCoord item in step.Removed) { SetupPoint(item, removedType); } } return(false); }