Esempio n. 1
0
        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);
        }
Esempio n. 2
0
 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);
     }
 }
Esempio n. 3
0
        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)));
        }
Esempio n. 4
0
 private void ClearQiOfBlock(GoPoint dian)
 {
     if (dian == null || dian.Block == null)
     {
         return;
     }
     dian.Block.CleanQi();
 }
Esempio n. 5
0
        public void PushStep(GoStep step)
        {
            GoPoint        point       = OnAddChess(step.Coord, step.Type);
            List <GoCoord> removedList = OnCheckCapture(point);

            step.SetRemovedList(removedList);
            steps_.Push(step);
            OnChessChanged();
        }
Esempio n. 6
0
 private void OnRemoveChess(GoPoint point)
 {
     if (point.Block != null && point.Block.DianNumber != 0)
     {
         GoBlock block = point.Block;
         block.RemoveDian(point);
         point.Type = GoPointType.EMPTY;
     }
 }
Esempio n. 7
0
        public int GetQi(int row, int col)
        {
            GoPoint point = GetPoint(row, col);

            if (point != null && point.Type != GoPointType.EMPTY)
            {
                return(point.Qi);
            }
            return(-1);
        }
Esempio n. 8
0
 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;
         }
     }
 }
Esempio n. 9
0
//         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);
        }
Esempio n. 10
0
        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);
        }
Esempio n. 11
0
        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();
        }
Esempio n. 12
0
        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);
        }
Esempio n. 13
0
        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);
        }
Esempio n. 14
0
        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);
        }
Esempio n. 15
0
        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);
        }
Esempio n. 16
0
        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);
        }