Example #1
0
        public int RemoveDeadStones(int exceptionX = 0, int exceptionY = 0)
        {
            bool exception  = false;
            int  deadStones = 0;

            for (int i = this._groups.Count - 1; i >= 0; i--)
            {
                SpaceCollection grp = this._groups[i];

                if (this.GetGroupLiberties(grp) == 0)
                {
                    foreach (Space space in grp)
                    {
                        if (space.X == exceptionX && space.Y == exceptionY)
                        {
                            exception = true;
                        }
                    }

                    if (!exception)
                    {
                        deadStones += grp.Count;
                        while (grp.Count > 0)
                        {
                            this.RemoveStone(grp.GetByIndex(0).X, grp.GetByIndex(0).Y);
                        }
                    }
                    exception = false;
                }
            }

            return(deadStones);
        }
Example #2
0
        private void addToGroup(Space space)
        {
            SpaceCollection newGroup = new SpaceCollection();

            newGroup.AddAt(space.X, space.Y);
            this._groups.Add(newGroup);
            space.SetGroup(newGroup);

            // TODO: Modify: get each connected space and add the groups for all connected spaces together
            List <Space> connected = GetConnectedSpaces(space.X, space.Y);

            foreach (Space cSpace in connected)
            {
                if (cSpace.GetGroup() != space.GetGroup())
                {
                    SpaceCollection cGroup = cSpace.GetGroup();
                    for (int i = cGroup.Count - 1; i >= 0; i--)
                    {
                        Space groupSpace      = cGroup.GetByIndex(i);
                        Space boardGroupSpace = Spaces.GetSpace(groupSpace.X, groupSpace.Y);
                        space.GetGroup().AddAt(boardGroupSpace.X, boardGroupSpace.Y);
                        boardGroupSpace.SetGroup(space.GetGroup());
                    }
                    this._groups.Remove(cGroup);
                }
            }
        }