Пример #1
0
        /// <summary>
        ///     A little helper method to check if a group is dead.
        ///     The free liberties are checked and if they are = 0,
        ///     then the group is removed and the captured stones
        ///     counter increases
        /// </summary>
        /// <param name="pos">
        ///     A stone of the group to check for death
        /// </param>
        protected void CheckSurroundingGroupsForDeathHelper(ref BoardPosition pos)
        {
            if (pos == null)
            {
                return;
            }

            BoardPositionEntry entry = pos.Contains;
            int size = 0;

            if (pos != null)
            {
                if (!CheckForFreeLiberties(pos))
                {
                    size = pos.Group.RemoveGroup(this);
                }
            }
            if (entry == BoardPositionEntry.BLACK)
            {
                CapturedBlackStones += size;
            }
            else if (entry == BoardPositionEntry.WHITE)
            {
                CapturedWhiteStones += size;
            }
        }
Пример #2
0
        /// <summary>
        ///     Places a new stone on the board at the
        ///     given position. This method then checks
        ///     if the new stone connects some groups
        ///     and if it kills any surrounding groups.
        /// </summary>
        /// <param name="x">
        ///     The new stone's x-Coordinate
        /// </param>
        /// <param name="y">
        ///     The new stone's y-Coordinate
        /// </param>
        /// <param name="entry">
        ///     The new stone's color
        /// </param>
        public void SetStone(int x, int y, BoardPositionEntry entry)
        {
            if (x < 0 || x >= size)
            {
                throw new System.Exception("Position out of range");
            }
            if (y < 0 || y >= size)
            {
                throw new System.Exception("Position out of range");
            }

            if (board[x, y].Contains == BoardPositionEntry.EMTPY)
            {
                board[x, y].Contains = entry;
            }

            ConnectToGroups(board[x, y]);
            if (!CheckForFreeLiberties(board[x, y]))
            {
                System.Console.WriteLine("This move is not allowed!");
            }

            CheckSurroundingGroupsForDeath(board[x, y]);
            MoveNumber++;
        }
Пример #3
0
 /// <summary>
 ///     Flips the board horizontally
 /// </summary>
 public void FlipBoardHorizontally()
 {
     for (int x = 0; x < Size; x++)
     {
         for (int y = 0; y < Size; y++)
         {
             BoardPositionEntry tmp = board[x, y].Contains;
             board[x, y].Contains            = board[x, Size - y - 1].Contains;
             board[x, Size - y - 1].Contains = tmp;
         }
     }
 }
Пример #4
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public int RemoveGroup(Board board)
        {
            int size = Stones.Count;
            BoardPositionEntry entry = BoardPositionEntry.EMTPY;

            foreach (BoardPosition pos in Stones)
            {
                entry = pos.Contains;
                board.RemoveStone(pos);
            }
            Stones.Clear();
            board.Groups.Remove(this);

            return(size);
        }
Пример #5
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="x"></param>
 /// <param name="y"></param>
 /// <param name="entry"></param>
 public BoardPosition(int x, int y, BoardPositionEntry entry)
 {
     this.x        = x;
     this.y        = y;
     this.contains = entry;
 }
Пример #6
0
        /// <summary>
        ///     Places a new stone on the board at the
        ///     given position. This method then checks
        ///     if the new stone connects some groups
        ///     and if it kills any surrounding groups.
        /// </summary>
        /// <param name="x">
        ///     The new stone's x-Coordinate
        /// </param>
        /// <param name="y">
        ///     The new stone's y-Coordinate
        /// </param>
        /// <param name="entry">
        ///     The new stone's color
        /// </param>
        public void SetStone(int x, int y, BoardPositionEntry entry)
        {
            if(x < 0 || x >= size)
                throw new System.Exception("Position out of range");
            if (y < 0 || y >= size)
                throw new System.Exception("Position out of range");

            if (board[x, y].Contains == BoardPositionEntry.EMTPY)
                board[x, y].Contains = entry;

            ConnectToGroups(board[x, y]);
            if (!CheckForFreeLiberties(board[x, y]))
            {
                System.Console.WriteLine("This move is not allowed!");
            }

            CheckSurroundingGroupsForDeath(board[x, y]);
            MoveNumber++;
        }
Пример #7
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="x"></param>
 /// <param name="y"></param>
 /// <param name="entry"></param>
 public BoardPosition(int x, int y, BoardPositionEntry entry)
 {
     this.x = x;
     this.y = y;
     this.contains = entry;
 }