public TheDecisionNode() { LeafNode = false; YesNode = null; NoNode = null; }
/// <summary> /// find a node with a specific value /// -----PSEUDO CODE----- /// (L is the LinkedList, x is the node to find) /// Search(L,x) /// y = L.head /// while y =/= NIL and y =/= x /// y = y.next /// return y /// -----PSEUDO CODE----- /// </summary> /// <param name="x">value of the node to find</param> /// <returns>the found node or null</returns> public override TheNode <T> Search(TheNode <T> x) { TheNode <T> y = head; while (y != null && y.CompareTo(x) != 0) { y = y.next; } return(y); }
/// <summary> /// remove a node from the list /// -----PSEUDO CODE----- /// (L is the LinkedList, x is the node to be deleted) /// Delete(L,x) /// y = Predecessor(L,x) /// if y =/= NIL /// y.next = y.next.next /// L.size = L.size - 1 /// -----PSEUDO CODE----- /// </summary> /// <param name="x">node to be removed</param> /// <returns>True if node was removed</returns> public override bool Delete(TheNode <T> x) { TheNode <T> y = Predecessor(x); if (y != null) { y.next = y.next.next; size--; return(true); } return(false); }
// this function goes thorugh the tree testing differnt decsisions until it reaches a leaf node public void TraverseTree(TheNode TheCurrentNode, RealBattleUIScript TheUI, MonsterScript TheMonster) { if (TheCurrentNode.LeafNode) { CurrentNode.ExecuteAction(TheUI); } else { CurrentNode = TheCurrentNode.MakeDecision(TheMonster); // the function does not do anything yet //CurrentNode = TheCurrentNode.MakeDecision(); TraverseTree(CurrentNode, TheUI, TheMonster); } }
/// <summary> /// check if the list contains a node /// -----PSEUDO CODE----- /// (L is the LinkedList, x is the node to look for) /// Contains(L,x) /// y = L.head /// while y =/= NIL /// if y == x /// return True /// y = y.next /// return False /// -----PSEUDO CODE----- /// </summary> /// <param name="n">the node to find</param> /// <returns>True if the list contain the node</returns> public override bool Contains(TheNode <T> x) { TheNode <T> y = head; while (y != null) { if (y.CompareTo(x) == 0) { return(true); } y = y.next; } return(false); }
/// <summary> /// find the node preceding the node /// -----PSEUDO CODE----- /// (L is the LinkedList, x is the value of the node to look at) /// Predecessor(L,x) /// y = L.head /// if y == NIL /// return NIL /// while y.next =/= NIL /// if y.next == x /// return y /// y = y.next /// -----PSEUDO CODE----- /// </summary> /// <param name="n">node to look at</param> /// <returns>the found node or null</returns> public override TheNode <T> Predecessor(TheNode <T> x) { TheNode <T> y = head; if (y == null) { return(null); } while (y.next != null) { if (y.next.CompareTo(x) == 0) { return(y); } y = y.next; } return(null); }
IEnumerator createNode(List <int[]> ids) { if (ids.Count >= 1) { for (int i = 0; i < ids.Count; i++) { List <M_Finger> m_Fingers = new List <M_Finger>(); yield return(new WaitForSeconds(0f)); for (int j = 0; j < ids[i].Length; j++) { try { M_Finger FINGER = KP_FINGER_ID_m_Finger[ids[i][j]]; m_Fingers.Add(FINGER); //获取三个角顶点,为了加入给中心Node } catch (System.Exception e) { break; throw e; } } GameObject g = Instantiate(TheNodeObj);//新建中心点 TheNode theNode = g.GetComponent <TheNode>(); g.transform.SetParent(this.transform); theNode.Ini(m_Fingers, ids[i]);//初始化N } } }
public TheAIScript(TheNode Root) { TheRootNode = Root; CurrentNode = null; }
public void AddNoNode(TheNode TheNoNode) { NoNode = TheNoNode; }
public void AddYesNode(TheNode TheYesNode) { YesNode = TheYesNode; }
/// <summary> /// Perform a series of test to a linked list class and calculate its time. /// Test are: Inserting, Deleting values, searching values and deleting found nodes. /// </summary> /// <typeparam name="T">can be of any type, needs to implement IComparable</typeparam> /// <param name="testList">the linked list to be tested</param> private static void LinkedListTest <T>(TheLinkedList <T> testList) where T : IComparable { #region INSERT_TEST // Speed test: Insert LIST_SIZE elements to the list Console.Write($"- Inserting {LIST_SIZE} elements -"); long time = DateTime.Now.Ticks; // Get the current ticks. for (int i = 0; i < myArray.Length; i++) { testList.Insert((dynamic)myArray[i]); } time = DateTime.Now.Ticks - time; // Get the time spent inserting. long totalTime = time; // Get the time spend for this test. Console.WriteLine($"- {testList.Count} elements inserted. -"); Console.WriteLine($"\tTotal Seconds: {TimeSpan.FromTicks(time).TotalSeconds}"); // Print the time spent in seconds. #endregion #region DELETE_VALUE_TEST // Speed test: Delete TEST_AMOUNT elements from the list Console.Write($"- Deleting {TEST_AMOUNT} values. -"); time = DateTime.Now.Ticks; // Get the current ticks. for (int i = 0; i < delTestArray.Length; i++) { testList.Delete((dynamic)delTestArray[i]); // Delete using value } time = DateTime.Now.Ticks - time; // Get the time spent Deleting. totalTime += time; // Add the time spend for this test Console.WriteLine($"- {testList.Count} nodes left. -"); Console.WriteLine($"\tTotal Seconds: {TimeSpan.FromTicks(time).TotalSeconds}"); // Print the time spent in seconds. #endregion #region SEARCH_VALUE_TEST // Speed test: Search TEST_AMOUNT elements from the list TheNode <int>[] theFoundNodes = new TheNode <int> [TEST_AMOUNT]; // Found nodes from this test Console.Write($"- Searching {TEST_AMOUNT} values. -"); time = DateTime.Now.Ticks; // Get the current ticks. for (int i = 0; i < searchTestArray.Length; i++) { theFoundNodes[i] = testList.Search((dynamic)searchTestArray[i]); // The found nodes are placed in an array for further testing. } time = DateTime.Now.Ticks - time; // Get the time spent Searching. totalTime += time; // Add the time spend for this test int foundNodes = 0; foreach (var item in theFoundNodes) // Check the found nodes { if (item != null) // Count how many nodes are null meaning not found. { foundNodes++; } } Console.WriteLine($"- {foundNodes} nodes found. -"); Console.WriteLine($"\tTotal Seconds: {TimeSpan.FromTicks(time).TotalSeconds}"); // Print the time spent in seconds. #endregion #region DELETE_NODE_FOUND_TEST // Speed test: Deleting foundNodes node from the list Console.Write($"- Deleting {foundNodes} nodes. -"); time = DateTime.Now.Ticks; // Get the current ticks. for (int i = 0; i < theFoundNodes.Length; i++) { testList.Delete((dynamic)theFoundNodes[i]); // Delete using nodes. } time = DateTime.Now.Ticks - time; // Get the time spent Searching. totalTime += time; // Add the time spend for this test Console.WriteLine($"- {testList.Count} nodes left -"); Console.WriteLine($"\tTotal Seconds: {TimeSpan.FromTicks(time).TotalSeconds}"); // Print the time spent in seconds. #endregion #region CONTAINS_TEST // Speed test: Do a contains of TEST_AMOUNT elements from the list Console.WriteLine($"- Run contains on {TEST_AMOUNT} values. -"); time = DateTime.Now.Ticks; // Get the current ticks. for (int i = 0; i < containTestArray.Length; i++) { testList.Contains((dynamic)containTestArray[i]); // Check if list contains a node with specific value. } time = DateTime.Now.Ticks - time; // Get the time spent looking. totalTime += time; // Add the time spend for this test Console.WriteLine($"\tTotal Seconds: {TimeSpan.FromTicks(time).TotalSeconds}"); // Print the time spent in seconds. #endregion Console.WriteLine("- Class Speed for all tests -"); Console.WriteLine($"\tTotal seconds : {TimeSpan.FromTicks(totalTime).TotalSeconds}"); // Print the time spent in seconds for all tests combined }
public void ini(List <M_Finger> _m_Fingers, TheNode _theNode) { m_Fingers = _m_Fingers; theNode = _theNode; }
/// <summary> /// remove a node with a specific value from the list /// -----PSEUDO CODE----- /// (L is the LinkedList, k is the value of the node to be deleted) /// Delete(L,k) /// y = Search(L,k) /// Delete(L,y) /// -----PSEUDO CODE----- /// </summary> /// <param name="k">value of the node to be removed</param> /// <returns>True if node was removed</returns> public override bool Delete(T k) { TheNode <T> y = Search(k); return(Delete(y)); }
/// <summary> /// Add a new node to the list /// -----PSEUDO CODE----- /// (L is the LinkedList, x is the node to be added) /// Insert(L,x) /// x.next = L.head /// L.head = x /// L.size = L.size + 1 /// -----PSEUDO CODE----- /// </summary> /// <param name="x">node to be added</param> public override void Insert(TheNode <T> x) { x.next = head; head = x; size++; }