static void WriteEdge(string word1, string word2, CONNECTION_TYPE type) { word1 = RemoveInterpunction(word1.ToLower()); word2 = RemoveInterpunction(word2.ToLower()); if (!dic.ContainsKey(word1)) { dic[word1] = dicIndex++; } if (!dic.ContainsKey(word2)) { dic[word2] = dicIndex++; } /* edges += dic[word1] + " "; * * edges += dic[word2] + " "; * edges += Array.IndexOf(Enum.GetValues(type.GetType()), type); * edges += Environment.NewLine;*/ writer.Write(dic[word1] + " "); writer.Write(dic[word2] + " "); writer.WriteLine(Array.IndexOf(Enum.GetValues(type.GetType()), type)); // Console.ReadKey(); }
static void Main(string[] args) { reader = new StreamReader(@"D:\poems.txt"); writer = new StreamWriter(@"D:\graph.txt"); string lastWordInPreviousLine = null; while (reader.Peek() >= 0) { string line = reader.ReadLine(); if (line == START || line == END) { SkipLines(3); continue; } string[] words = line.Split(' '); if (words.Length == 1) { continue; } if (lastWordInPreviousLine != null) { WriteEdge(lastWordInPreviousLine, words[0], CONNECTION_TYPE.newLine); } for (int x = 0; x < words.Length - 1; x++) { string word = words[x]; if (word == "-") { continue; } string nextWord = words[x + 1]; if (nextWord == "-" && x + 2 < words.Length) { nextWord = words[x + 2]; } CONNECTION_TYPE type = GetConnectionType(word); WriteEdge(word, nextWord, type); } lastWordInPreviousLine = words[words.Length - 1]; if (lastWordInPreviousLine == "-") { lastWordInPreviousLine = null; } } writer.WriteLine("<END>"); WriteAllWords(); writer.WriteLine("<TYPES>"); WriteAllTypes(); writer.Close(); }
public static Connection initConnection(string adr, int port, int socket, CONNECTION_TYPE type) { switch (type) { case CONNECTION_TYPE.TCP: return(new TCPConnection(adr, port, socket)); case CONNECTION_TYPE.UDP: return(new UDPConnection()); default: return(null); } }
//create the connection from rb1 to rb2 if there is one between their child nodes public static void AddConnectionsFromTo(Node rb1, Node rb2) { //find out if any of the node's children are connected to the other node's children //if not then exit early CONNECTION_TYPE connection = GetConnectionBetweenRigidBodies(rb1, rb2); if (connection == CONNECTION_TYPE.NONE) { return; } float cost = (rb1.position - rb2.position).Length(); //other costs can be included here, such as taking into account the type of motion required (jump/fall/walk), or looking at the properties of the rigidbodies such as friction or bounciness rb1.addConnection(new Connection(rb2.index, cost, CONNECTION_TYPE.HIGH_LEVEL)); }
//The following method assumes the nodes provided are rigidbodies with leaf nodes attached to them private static CONNECTION_TYPE GetConnectionBetweenRigidBodies(Node rigidBody1, Node rigidBody2) { WorldGraph mainGraph = WorldGraph.GetWorldGraph(); CONNECTION_TYPE toReturn = CONNECTION_TYPE.NONE; List <Physics.Vector2D> nodePositions1, nodePositions2; //compare each node from rigidbody 1 to each node in rigidbody 2 foreach (Node node1 in rigidBody1.internalNodes) { foreach (Node node2 in rigidBody2.internalNodes) { //Due to the presence of moving platforms, create lists of the different possible positions of each node nodePositions1 = new List <Physics.Vector2D>(); nodePositions2 = new List <Physics.Vector2D>(); //add the node's default positions nodePositions1.Add(mainGraph.topLevelNode.GetNodePosition(node1)); nodePositions2.Add(mainGraph.topLevelNode.GetNodePosition(node2)); //if rigidbody 1 moves between two points, add the position of node1 at BOTH those points to the list if (rigidBody1 is NodeOnRails) { nodePositions1.Add( mainGraph.topLevelNode.GetNodePosition(rigidBody1.index.GetParentIndex()) + ((NodeOnRails)rigidBody1).railPoint1 + node1.position); nodePositions1.Add( mainGraph.topLevelNode.GetNodePosition(rigidBody1.index.GetParentIndex()) + ((NodeOnRails)rigidBody1).railPoint2 + node1.position); } //if rigidbody 2 moves between two points, add the position of node2 when at BOTH those points to the list if (rigidBody2 is NodeOnRails) { nodePositions2.Add( mainGraph.topLevelNode.GetNodePosition(rigidBody2.index.GetParentIndex()) + ((NodeOnRails)rigidBody2).railPoint1 + node2.position); nodePositions2.Add( mainGraph.topLevelNode.GetNodePosition(rigidBody2.index.GetParentIndex()) + ((NodeOnRails)rigidBody2).railPoint2 + node2.position); } //at this point two lists have been created containing all the positions each node could occupy //loop through both lists to determine if any position combinations should be connected CONNECTION_TYPE temp; //loop through both lists, adding all possible connections to node1 foreach (Physics.Vector2D pos1 in nodePositions1) { foreach (Physics.Vector2D pos2 in nodePositions2) { //find out if the two nodes can be connected temp = GetConnectionBetween(node1.type, node2.type, pos1, pos2); if (temp != CONNECTION_TYPE.NONE) { float cost = (pos1 - pos2).Length(); //modify cost based on the type of connection switch (temp) { case CONNECTION_TYPE.JUMP: cost += 20; break; case CONNECTION_TYPE.FALL: cost += 5; break; default: cost += 2; break; } node1.addConnection(new Connection(node2.index, cost, temp)); //change the return value to reflect the presence of a connection toReturn = CONNECTION_TYPE.HIGH_LEVEL; } } } } } return(toReturn); }
public Connection(CONNECTION_TYPE type) { this.TYPE = type; isConnected = true; //packetBuilder = new PacketBuilder(); }
public Connection(NodeIndex dest, float cost, CONNECTION_TYPE connectionType) { destination = new NodeIndex(dest); traversalCost = cost; connType = connectionType; }