/// <summary> /// creates ellipse on a board in Point and gives it number i /// </summary> public Cop(Board board, Point node, int i) { myNode = new Node(node); myNeighbors = new List<int>(); myNode.number = i; board.pointCop(node, myNode); myNeighbors = board.findNeighbors(myNode.number); }
/// <summary> /// creates ellipse on a board in Point and gives it number i /// </summary> public Robber(Board board, Point node, int i) { myNode = new Node(node); myNeighbors = new List<int>(); myNode.number = i; movesSoFar = 0; myPath = new List<int>(); board.pointRobber(node, myNode); myNeighbors = board.findNeighbors(myNode.number); }
internal static Node<Data> simulateGame(int searchWidth, int searchDepth, int copnumber, Node<Data> node, Board board) { if (searchDepth != 0) { Data nodeInfo = node.GetData(); List<int> neighborList = new List<int>(board.findNeighbors(nodeInfo.RobberPos)); List<int> path = new List<int>(); int robberNodePosition; for (int i = 0; i < searchWidth; i++) { node.AddChild(FindChildOnBoard(neighborList, nodeInfo, copnumber, out robberNodePosition, board)); if (neighborList.Contains(robberNodePosition)) neighborList.Remove(robberNodePosition); } //obliczanie prawdopodobieństw do ruchu na zaraz int sum = 0, iter = 0, maxNode = 0; double maxProbNode = 0; foreach (Node<Data> child in node.GetChildren()) { sum += child.GetData().RobberCopDistance; } foreach (Node<Data> child in node.GetChildren()) { child.GetData().Probability = (double)child.GetData().RobberCopDistance / sum; if (child.GetData().Probability > maxProbNode) { maxProbNode = child.GetData().Probability; maxNode = iter; } iter++; } simulateGame(searchWidth, searchDepth - 1, copnumber, node.GetChild(maxNode), board); } return node; }
internal static Node<Data> PropagateChildrenProbability(Node<Data> nodeTMP) { while (true) { if (nodeTMP.areAllChildrenLeaf() || nodeTMP.GetData().Visited == 1) { nodeTMP.GetData().Visited = 1; break; } foreach (Node<Data> child in nodeTMP.GetChildren()) { if (child.IsLeaf()) { if (child.GetData().Probability > child.GetParent().GetData().Probability) { child.GetParent().GetData().Probability = child.GetData().Probability; } child.GetData().Visited = 1; } else { PropagateChildrenProbability(child); child.GetData().Visited = 1; } } } return nodeTMP; }
public Node pointRobber(Point point, Node node) { node.elly = drawRobber(node.elly); node.elly.SetValue(Canvas.LeftProperty, point.X); node.elly.SetValue(Canvas.TopProperty, point.Y); node.elly.Name = "robber"; return node; }
public Node pointCop(Point point, Node node) { if (!node.isDrawn) { node.elly = drawCop(node.elly); node.elly.Name = "cop"; } node.elly.SetValue(Canvas.LeftProperty, point.X); node.elly.SetValue(Canvas.TopProperty, point.Y); return node; }
/// <summary> /// create a point on graph with user game /// </summary> /// <param name="x and y"> positions of point</param> /// <param name="i">point number in list</param> public Node point(double x, double y, int i) { Ellipse myEllipse = new Ellipse(); myEllipse = drawEllipse(myEllipse); myEllipse.SetValue(Canvas.LeftProperty, x); myEllipse.SetValue(Canvas.TopProperty, y); myEllipse.Name = "node" + i.ToString(); Node punkt = new Node(x, y, myEllipse, i); return punkt; }