예제 #1
0
파일: Board.cs 프로젝트: diblaze/GoSharp
        // Remove all groups that are marked dead
        public override void DeleteDead()
        {
            foreach (int groupId in _markedGroups)
            {
                AbGroup groupToDelete = _groups[groupId];
                State   opponentColor = groupToDelete.GetColor();
                switch (opponentColor)
                {
                case State.Black:
                    Capture(groupToDelete, State.White);
                    break;

                case State.White:
                    Capture(groupToDelete, State.Black);
                    break;

                case State.None:
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }

            _markedGroups.RemoveWhere(c => _markedGroups.Contains(c));
        }
예제 #2
0
파일: Board.cs 프로젝트: diblaze/GoSharp
        /**
         * This method Updates the state of the board with the addition of the new stone
         */
        private void UpdateBoard(Coord coord, State color, State opponent)
        {
            _gridStones[coord.Column, coord.Row] = color; //Place the stone
            HashSet <Coord> neigh = GetNeighbours(coord); // Get the neighboouring coords.

            var g = new Group(GetNextGroupId(), coord, color, GetColoredNeighbour(neigh, State.None),
                              GetColoredNeighbour(neigh, opponent)); //Create the group

            _groups.Add(g.GetId(), g);                               // Add the group to the board
            _gridGroups[coord.Column, coord.Row] = g.GetId();        //Add group to grid

            foreach (Coord pos in neigh)                             //Merge adjacent groups of same color into this group.
            {
                int groupId = _gridGroups[pos.Column, pos.Row];
                if (!_groups.ContainsKey(groupId) || groupId == g.GetId()) // If there is no group of the ID do nothing
                {
                    continue;
                }
                AbGroup ng = _groups[_gridGroups[pos.Column, pos.Row]];
                if (ng?.GetColor() == color) // If the group is of the same collor merge the groups
                {
                    MergeGroupGrid(g, ng);
                    MergeGroup(g, ng);
                    g.AddStone(coord);
                }
                else if (ng?.GetColor() == opponent) // If the gorup is of the opponent
                {
                    ng.AddStone(coord);
                    if (ng.GetLiberties().Count == 0) // If we removed the last liberty capture the group
                    {
                        Capture(ng, color);
                    }
                }
            }

            // These methods prints the board and some debugg information in the output.
            WriteGroupBoard();
            WriteGroupLiberties();
        }