/// <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; } } }
/// <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 override void Apply(byte depth, ApplyParameters pars) { if (depth > Depth && depth <= pars.MaximumDepth && pars.HasTimeLeft) { if (Children == null) { var block = GetBlock(pars); Children = new BlockNodes <BlockRndNode>(block); var applied = BlockNode.Apply(Field, Depth, pars); if (!applied.IsNone) { foreach (var field in pars.Generator.GetFields(applied, block)) { if (!pars.HasTimeLeft) { return; } var child = Create(field, pars); // We can kill our opponent. if (child.Field.Points > Field.Points) { var garbageNew = child.Field.Points / 3; if (garbageNew - pars.Garbage > pars.Opponent.FirstFilled2) { child.SetFinalScore(Scores.Wins(2)); } } Children.InsertSorted(child); } } } else { if (Children.Empty()) { return; } Children.Apply(depth, pars, BranchingFactor); } Score = Children.GetScore(this); } }
/// <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 override void Apply(byte depth, ApplyParameters pars) { if (depth > Depth && depth <= pars.MaximumDepth && pars.HasTimeLeft) { if (Children == null) { BranchingFactor = pars.Current.BranchingFactor0; var block = GetBlock(pars); Children = new BlockNodes <Block1Node>(block); foreach (var candidate in pars.Generator.GetMoves(Field, block)) { if (!pars.HasTimeLeft) { return; } Block1Node child = Create(candidate.Field, candidate.Path, pars); // We can kill our opponent. if (child.Field.Points > Field.Points) { var garbageNew = child.Field.Points / 3; if (garbageNew - pars.Garbage > pars.Opponent.FirstFilled1) { child.SetFinalScore(Scores.Wins(1)); } } Children.InsertSorted(child); } } else { Children.Apply(depth, pars, BranchingFactor); } Score = Children.GetScore(this); } }
public void SetFinalScore(int score) { Score = score; Children = BlockNodes <BlockRndNode> .GetEmpty(); }