コード例 #1
0
 /// <summary>Gets the score of the best (first) node.</summary>
 public int GetScore(IBlockNode node)
 {
     if (Empty())
     {
         return(Scores.Loses(node.Depth));
     }
     return(this[0].Score);
 }
コード例 #2
0
        /// <summary>Applies the search on the current node.</summary>
        /// <param name="depth">
        /// The maximum depth to search.
        /// </param>
        /// <param name="pars">
        /// The parameters needed to apply the search.
        /// </param>
        public void Apply(byte depth, ApplyParameters pars)
        {
            if (depth > Depth && depth <= pars.MaximumDepth && pars.HasTimeLeft)
            {
                if (Children == null)
                {
                    Children = new List <BlockNodes <BlockRndNode> >();

                    foreach (var block in pars.Blocks[Depth])
                    {
                        var nodes = new BlockNodes <BlockRndNode>(block);
                        foreach (var field in pars.Generator.GetFields(Field, block))
                        {
                            if (!pars.HasTimeLeft)
                            {
                                return;
                            }

                            var applied = BlockNode.Apply(field, Depth, pars);
                            if (!applied.IsNone)
                            {
                                var child = Create(applied, pars);
                                nodes.InsertSorted(child);
                            }
                        }
                        Children.Add(nodes);
                    }
                }
                else
                {
                    foreach (var nodes in Children)
                    {
                        nodes.Apply(depth, pars, BranchingFactor);
                    }
                }
                Score = 0;
                foreach (var nodes in Children)
                {
                    Score += nodes.GetScore(this);
                }
                if (Children.Count == 2)
                {
                    // Divide by 2.
                    Score >>= 1;
                }
                // We can not find valid responses. We will lose next turn.
                else if (Children.Count == 0)
                {
                    Score = Scores.Loses(Depth + 1);
                }
                else
                {
                    Score /= Children.Count;
                }
            }
        }