Exemplo n.º 1
0
        /// <summary>
        /// The territory of a player are those empty points on the board which are entirely surrounded by his live stones.
        /// This method adds up total territory of players. The scores include prisoners and dead stones.
        /// </summary>
        /// <param name="currentNode">Node of tree representing the previous move.</param>
        /// <param name="deadPositions">Positions marked as dead.</param>
        /// <returns>The score of players, which does not include number of prisoners and dead stones.</returns>
        protected Scores CountTerritory(GameTreeNode currentNode, IEnumerable <Position> deadPositions)
        {
            Scores scores = new Scores(0, 0);

            //prisoners
            IEnumerable <GameTreeNode> history = currentNode.GetNodeHistory();

            foreach (GameTreeNode node in history)
            {
                if (node.Move.Captures.Count != 0)
                {
                    if (node.Move.WhoMoves == StoneColor.Black)
                    {
                        scores.WhiteScore -= node.Move.Captures.Count;
                    }
                    else if (node.Move.WhoMoves == StoneColor.White)
                    {
                        scores.BlackScore -= node.Move.Captures.Count;
                    }
                }
            }

            //dead stones
            foreach (Position position in deadPositions)
            {
                if (RulesetInfo.BoardState[position.X, position.Y] == StoneColor.Black)
                {
                    scores.BlackScore--;
                }
                else if (RulesetInfo.BoardState[position.X, position.Y] == StoneColor.White)
                {
                    scores.WhiteScore--;
                }
            }

            //regions
            Scores regionScores = GetRegionScores(currentNode, deadPositions);

            scores.WhiteScore += regionScores.WhiteScore;
            scores.BlackScore += regionScores.BlackScore;

            return(scores);
        }
Exemplo n.º 2
0
        /// <summary>
        /// The area of a player are all live stones of player left on the board together with any points of his territory. In this case, prisoners are ignored.
        /// This method adds up total area of players.
        /// </summary>
        /// <param name="currentNode">Node of tree representing the previous move.</param>
        /// <param name="deadPositions">Positions marked as dead.</param>
        /// <returns>The score of players.</returns>
        protected Scores CountArea(GameTreeNode currentNode, IEnumerable <Position> deadPositions)
        {
            Scores scores = GetRegionScores(currentNode, deadPositions);

            for (int i = 0; i < RulesetInfo.BoardSize.Width; i++)
            {
                for (int j = 0; j < RulesetInfo.BoardSize.Height; j++)
                {
                    if (RulesetInfo.BoardState[i, j] == StoneColor.Black)
                    {
                        scores.BlackScore++;
                    }
                    else if (RulesetInfo.BoardState[i, j] == StoneColor.White)
                    {
                        scores.WhiteScore++;
                    }
                }
            }

            return(scores);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Returns the scores after adding up total territory of players.
        /// </summary>
        /// <param name="currentNode">Node of tree representing the previous move.</param>
        /// <param name="deadPositions">Positions marked as dead.</param>
        /// <returns>The score of players, which includes number of prisoners and dead stones yet.</returns>
        private Scores GetRegionScores(GameTreeNode currentNode, IEnumerable <Position> deadPositions)
        {
            RulesetInfo.SetBoard(currentNode.BoardState.BoardWithoutTheseStones(deadPositions));

            Scores scores = new Scores(0, 0);

            Territory[,] regions = DetermineTerritory(RulesetInfo.BoardState);
            for (int i = 0; i < RulesetInfo.BoardSize.Width; i++)
            {
                for (int j = 0; j < RulesetInfo.BoardSize.Height; j++)
                {
                    if (regions[i, j] == Territory.Black)
                    {
                        scores.BlackScore++;
                    }
                    else if (regions[i, j] == Territory.White)
                    {
                        scores.WhiteScore++;
                    }
                }
            }

            return(scores);
        }