/// <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 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> /// robber for test uses /// </summary> public Robber(int startNode, Board board) { myPath = new List <int>(); ocpupiedNode = startNode; movesSoFar = 0; myNeighbors = new List <int>(); myNeighbors = board.findNeighbors(ocpupiedNode); }
/// <summary> /// robber for test uses /// </summary> public Robber(int startNode, Board board) { myPath = new List<int>(); ocpupiedNode = startNode; movesSoFar = 0; myNeighbors = new List<int>(); myNeighbors = board.findNeighbors(ocpupiedNode); }
/// <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); }
/// <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); }
public static List <List <int> > removePitfalls(Board board) { int numberOfNodes = board.neighborForClass.Count(); bool isEqual = true; for (int i = 0; i < numberOfNodes; i++) { List <int> nodeList = board.neighborForClass[i]; if (nodeList.Count != 0) { for (int j = 0; j < nodeList.Count; j++) { isEqual = true; int node = nodeList[j]; List <int> robPos = new List <int>(nodeList); List <int> copPos = new List <int>(board.findNeighbors(node, true)); copPos.Add(node); robPos.Add(i); copPos.Sort(); robPos.Sort(); for (int k = 0; k < robPos.Count; k++) { if (!copPos.Contains(robPos[k])) { isEqual = false; break; } } if (isEqual) { // nodeList.Remove(i); foreach (List <int> tmp in board.neighborForClass) { if (tmp.Contains(i)) { tmp.Remove(i); } } nodeList.Clear(); board.neighborForClass = removePitfalls(board); nodeList = board.neighborForClass[0]; i = 0; j = 0; break; } } } } return(board.neighborForClass); }
private void plansza_MouseDown(object sender, MouseButtonEventArgs e) { string elem = findElement(sender, e); if (elem == null || elem == "") { } else if (elem != "" && elem.Substring(0, 3) == "nod") { clickedElement = Convert.ToInt32(elem.Substring(4, elem.Length - 4)); if (copTurn) { if (copPlaced) { if (cop.myNeighbors.Contains(clickedElement)) { checkboard.Children.Remove(cop.myNode.elly); cop.myNode.number = clickedElement; cop.myNeighbors = board.findNeighbors(cop.myNode.number); board.pointCop(findPoint(elem), cop.myNode); checkboard.Children.Add(cop.myNode.elly); RobberMove(); } else { cop.myNeighbors = board.findNeighbors(cop.myNode.number); MessageBox.Show("tak daleko nie dobiegnę..."); } } else { int tmp; cop = new Cop(board, findPoint(elem, out tmp), tmp); checkboard.Children.Add(cop.myNode.elly); copPlaced = true; copTurn = false; lblTura.Text = "Złodziej"; } } else { if (!robberPlaced) { int tmp; robber = new Robber(board, findPoint(elem, out tmp), tmp); checkboard.Children.Add(robber.myNode.elly); robberPlaced = true; copTurn = true; lblTura.Text = "Gliniarz"; } } } else if (elem.Substring(0, 3) == "rob" || elem.Substring(0, 3) == "cop") { if (copTurn) { if (cop.myNeighbors.Contains(robber.myNode.number)) { gameEnd("cop"); } else { MessageBox.Show("jeszcze za daleko"); } } else { if (robber.myNeighbors.Contains(cop.myNode.number)) { gameEnd("robber"); } else { MessageBox.Show("no widze go i co?!"); } } } }
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; }
public static List<int> Dijkstra(int from, int startNode, int finalNode, Board board) { nodeNumber = board.neighbor.Count; List<int> path = new List<int>(); List<List<int>> visited = new List<List<int>>(nodeNumber); for (int i = 0; i < nodeNumber; i++) { visited.Add(new List<int>()); } List<int> neighbors = board.findNeighbors(startNode); Queue<int> q = new Queue<int>(nodeNumber); int tmpNode; visited[startNode].Add(from); foreach (int i in neighbors) { if (i == finalNode) { path.Add(startNode); path.Add(finalNode); return path; } else { q.Enqueue(i); visited[i].Add(startNode); } } while (q.Count != 0) { tmpNode = q.Dequeue(); neighbors = board.findNeighbors(tmpNode); foreach (int node in neighbors) { if (node == finalNode) { q.Enqueue(node); visited[node].Add(tmpNode); createPathFromQueue(visited, out path, node, startNode); return path; } else { if (visited[node].Count == 0) { q.Enqueue(node); visited[node].Add(tmpNode); } } } } return path; }
public static int alphabeta(int node, int depth, int alpha, int beta, bool player, int oponentNode, int startDepth, Board board) { int goNode = node; if (depth == 0 || node == oponentNode) //lub koniec gry { return getNodeValue(node, oponentNode, player, board); } if (player == true) { foreach (int neighbor in board.findNeighbors(node)) { int alpha2 = Math.Max(alpha, alphabeta(oponentNode, depth - 1, alpha, beta, !player, neighbor, startDepth, board)); if (alpha2 > alpha) { goNode = neighbor; alpha = alpha2; } if (alpha>=beta) { return beta; } } return alpha; } else { foreach (int neighbor in board.findNeighbors(oponentNode)) { beta = Math.Min(beta, alphabeta(oponentNode, depth - 1, alpha, beta, !player, neighbor, startDepth, board)); if (alpha>=beta) { return alpha; } } return beta; } }
public static List<List<int>> removePitfalls(Board board) { int numberOfNodes = board.neighborForClass.Count(); bool isEqual=true; for (int i = 0; i < numberOfNodes; i++) { List<int> nodeList = board.neighborForClass[i]; if (nodeList.Count != 0) for (int j = 0; j < nodeList.Count; j++) { isEqual = true; int node = nodeList[j]; List<int> robPos = new List<int>(nodeList); List<int> copPos = new List<int>(board.findNeighbors(node, true)); copPos.Add(node); robPos.Add(i); copPos.Sort(); robPos.Sort(); for (int k = 0; k < robPos.Count; k++) { if (!copPos.Contains(robPos[k])) { isEqual = false; break; } } if (isEqual) { // nodeList.Remove(i); foreach (List<int> tmp in board.neighborForClass) { if (tmp.Contains(i)) tmp.Remove(i); } nodeList.Clear(); board.neighborForClass = removePitfalls(board); nodeList = board.neighborForClass[0]; i = 0; j = 0; break; } } } return board.neighborForClass; }
/// <summary> /// move and find neighbor list /// </summary> /// <param name="node">node number to move to</param> /// <param name="board">board for witch we find neighborhood</param> public void move(int node, Board board) { ocupiedNode = node; myNeighbors = board.findNeighbors(ocupiedNode); }
/// <summary> /// cop for test uses /// </summary> public Cop(int startNode, Board board) { ocupiedNode = startNode; myNeighbors = new List<int>(); myNeighbors = board.findNeighbors(ocupiedNode); }
/// <summary> /// move and find neighbor list /// </summary> /// <param name="node">node number to move to</param> /// <param name="board">board for witch we find neighborhood</param> public void move(int node, Board board) { ocupiedNode = node; myNeighbors = board.findNeighbors(ocupiedNode); }
/// <summary> /// cop for test uses /// </summary> public Cop(int startNode, Board board) { ocupiedNode = startNode; myNeighbors = new List <int>(); myNeighbors = board.findNeighbors(ocupiedNode); }