예제 #1
0
 static PentagoNodeEx SelectOptimalNode(PentagoNodeEx node1, PentagoNodeEx node2)
 {
     if (node1.Value > node2.Value)
     {
         return(node1);
     }
     else
     {
         return(node2);
     }
 }
예제 #2
0
 public PentagoNodeEx(PentagoBoard currentState, PentagoNodeEx parent)
     : base(parent.Depth + 1)
 {
     this.CurrentState  = currentState;
     this.currentTurn   = parent.NextTurn();
     this.Parent        = parent;
     this.maxDepth      = parent.maxDepth;
     this.nodeType      = (parent.nodeType == NodeTypeEnum.MAX) ? NodeTypeEnum.MIN : NodeTypeEnum.MAX;
     this.EvaluateState = parent.EvaluateState;
     this.Expand        = parent.Expand;
     this.SelectNode    = parent.SelectNode;
     //System.Diagnostics.Debug.WriteLine(Depth+" "+currentTurn.State);
 }
예제 #3
0
        static PentagoNodeEx StochasticallySelect(PentagoNodeEx node1, PentagoNodeEx node2)
        {
            var tem = 100000.0f;
            var rnd = new Random();

            if (rnd.NextDouble() > 1 / (1 + Math.Exp((node1.Value - node2.Value) / tem)))
            {
                return(node1);
            }
            else
            {
                return(node2);
            }
        }
예제 #4
0
        public static AbstractTreeNode[] Expand(PentagoNodeEx currentNode, Status player)
        {
            var currentState = currentNode.CurrentState;
            LinkedList <PentagoNodeEx> result = new LinkedList <PentagoNodeEx>();

            for (int i = 0; i < currentState.TotalWidth; i++)
            {
                for (int j = 0; j < currentState.TotalHeight; j++)
                {
                    if (currentState[i, j].State == Status.StateEnum.empty)
                    {
                        for (int k = 0; k < currentState.Sections.Count; k++)
                        {
                            result.AddLast(new PentagoNodeEx(currentState, currentNode)
                            {
                                PlaceX    = i,
                                PlaceY    = j,
                                SectionNo = k,
                                Clockwise = true,
                            });
                            //if the board state remains the same after rotating clockwise, it will be the same after rotating counterclockwise
                            //so the node can be eliminated
                            if (!currentState.Sections[k].IsSameInBothDirection)
                            {
                                result.AddLast(new PentagoNodeEx(currentState, currentNode)
                                {
                                    PlaceX    = i,
                                    PlaceY    = j,
                                    SectionNo = k,
                                    Clockwise = false,
                                });
                            }
                        }
                    }
                }
            }
            return(result.ToArray());
        }