示例#1
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);
                }
            }
        }
示例#2
0
 private void copySpaces(SpaceCollection src, SpaceCollection dest, SpaceCollection groupSpaces = null)
 {
     foreach (Space space in src)
     {
         dest.AddAt(space.X, space.Y);
         Space copySpace = dest.GetSpace(space.X, space.Y);
         copySpace.SpaceColor = space.SpaceColor;
         if (groupSpaces != null)
         {
             groupSpaces.GetSpace(space.X, space.Y).SetGroup(dest);
         }
     }
 }
示例#3
0
        public SpaceCollection GetSpaceLibertyList(int x, int y)
        {
            if (Spaces.GetSpace(x, y).SpaceColor == Space.Color.None)
            {
                return(null);
            }

            SpaceCollection liberties = new SpaceCollection();

            int libertyX = x - 1;
            int libertyY = y;

            if (libertyX > 0 && Spaces.GetSpace(libertyX, libertyY).SpaceColor == Space.Color.None)
            {
                liberties.AddAt(libertyX, libertyY);
            }

            libertyX = x + 1;
            if (libertyX <= this.BoardSize && Spaces.GetSpace(libertyX, libertyY).SpaceColor == Space.Color.None)
            {
                liberties.AddAt(libertyX, libertyY);
            }

            libertyX = x;
            libertyY = y - 1;
            if (libertyY > 0 && Spaces.GetSpace(libertyX, libertyY).SpaceColor == Space.Color.None)
            {
                liberties.AddAt(libertyX, libertyY);
            }

            libertyY = y + 1;
            if (libertyY <= this.BoardSize && Spaces.GetSpace(libertyX, libertyY).SpaceColor == Space.Color.None)
            {
                liberties.AddAt(libertyX, libertyY);
            }

            return(liberties);
        }
示例#4
0
        public int GetGroupLiberties(SpaceCollection group)
        {
            SpaceCollection liberties = new SpaceCollection();

            foreach (Space space in group)
            {
                SpaceCollection spaceLiberties = GetSpaceLibertyList(space.X, space.Y);

                foreach (Space liberty in spaceLiberties)
                {
                    liberties.AddAt(liberty.X, liberty.Y);
                }
            }

            return(liberties.Count);
        }