// public bool CmdRun{ // set{ // cmdRun_v = value; // } // get{ // return cmdRun_v; // } // } static void Main(string[] args) { Node node = new Node(PORT); node.Add("Handler", new Handler()) ; node.Start(); while (true){ // if (node.CmdRun){ Console.Write("command(join/sign off/start/exit): "); string cmd = Console.ReadLine(); if (cmd.Equals ("join")) { Console.Write ("ip: "); string ip = Console.ReadLine (); node.joinNetwork (ip); } else if (cmd.Equals ("sign off")) node.leaveNetwork (); else if (cmd.Equals ("start")) { Console.Write ("synchronized method (cme/raa): "); string sync = Console.ReadLine (); if (sync.Equals ("cme")) { node.task (sync); } else if (sync.Equals ("raa")) { node.task (sync); } } else if (cmd.Equals ("test")) node.Handler.test (); else if (cmd.Equals("exit")) break; else Console.WriteLine("wrong command"); // } } Console.WriteLine("---end---"); }
public static void Calculate (State from, Node to, List<Limb[]> output) { if (!IsArcValid(from, to)) { return; } int hoverable_count = 0; Limb[] original = new Limb[from.limbs.Length]; for (int i = 0; i < from.limbs.Length; ++i) { Limb from_limb = from.limbs[i]; Analyzer.Node.Limb to_limb = to.limbs[i]; if (to_limb == null) { original[i] = Limb.ToPassiveDown(from_limb, to.second); } else { original[i] = LimbHelper.TransitionToV3(from_limb, to_limb, to.second); } if (IsHoverable(original[i].main.movement)) { ++hoverable_count; } if (IsHoverable(original[i].sub.movement)) { ++hoverable_count; } else if (IsHoverable(original[i].extra.movement)) { ++hoverable_count; } original[i].sanityCheck(); } if (!IsOverlapping(original) && IsValidOrNot3Bracket(original)) { output.Add(original); } if (hoverable_count >= 2) { for (int limb_index = 0; limb_index < from.limbs.Length; ++limb_index) { Limb limb = original[limb_index]; if (IsHoverable(limb.main.movement)) { Limb[] with_unknown = CloneWithHover(original, limb_index, to.second, 0); if (!IsOverlapping(with_unknown) && IsValidOrNot3Bracket(with_unknown)) { output.Add(with_unknown); } } if (IsHoverable(limb.sub.movement)) { if (IsHoverable(limb.extra.movement)) { Limb[] with_unknown = CloneWithHover(original, limb_index, to.second, 1, 2); if (!IsOverlapping(with_unknown) && IsValidOrNot3Bracket(with_unknown)) { output.Add(with_unknown); } } else { Limb[] with_unknown = CloneWithHover(original, limb_index, to.second, 1); if (!IsOverlapping(with_unknown) && IsValidOrNot3Bracket(with_unknown)) { output.Add(with_unknown); } } } else if (IsHoverable(limb.extra.movement)) { Limb[] with_unknown = CloneWithHover(original, limb_index, to.second, 2); if (!IsOverlapping(with_unknown) && IsValidOrNot3Bracket(with_unknown)) { output.Add(with_unknown); } } } } }
public static bool IsArcValid (State from, Node to) { for (int i = 0; i < from.limbs.Length; ++i) { if (to.limbs[i] == null) { continue; } if (!LimbHelper.IsArcValid(from.limbs[i], to.limbs[i])) { return false; } } return true; }
public async Task WriteToFileAsync(Node node, string filePath) { var nodeDescription = _nodeDescriber.Describe(node); try { File.WriteAllText(filePath, nodeDescription); } catch (Exception e) { Console.WriteLine(e.ToString()); } }
public void save(String path) { output = path; Node.Node node = getRoot(); if (node == null || node.getSon() == null || node.getSon().Count() == 0) { return; } else { save(node); } }
public void save(Node.Node node) { if (node.getSon() == null || node.getSon().Count() == 0) { return; } for (int i = 0; i < node.getSon().Count(); i++) { if (node.getSon().ElementAt(i).getName() != null) { //show(node.getSon().ElementAt(i)); writeInFile(node.getSon().ElementAt(i)); } save(node.getSon().ElementAt(i)); } }
public Node Transform(Node node) { var nodeType = node.GetType(); if (nodeType == typeof(NoChildrenNode)) { return node; } else { var @switch = new Dictionary<Type, Action> { { typeof(SingleChildNode), () => node = TransformSingleChildNode((SingleChildNode)node) }, { typeof(TwoChildrenNode), () => node = TransformTwoChildrenNode((TwoChildrenNode)node) }, { typeof(ManyChildrenNode), () => node = TransformManyChildrenNode((ManyChildrenNode)node) }, }; @switch[nodeType](); } return node; }
public void insert() { if (age == -1 && sex == null && name.GetHashCode() == "NULL".GetHashCode()) { setHasGroup(true); } else { setHasGroup(false); } Int64 temp = qq; string position = temp.ToString(); Node.Node buoy = getRoot(); for (int i = 0; i < position.Length; i++) { char shadown = position [i]; int key = shadown - '0'; if (i != position.Length - 1) { if (buoy.getSon() == null) { buoy.setSon(new LinkedList <Node.Node> ()); buoy.getSon().AddLast(createNullNode()); buoy.getSon().ElementAt(0).setQQ(key); buoy = buoy.getSon().ElementAt(0); } else { bool flag = true; for (int j = 0; j < buoy.getSon().Count(); j++) { if (buoy.getSon().ElementAt(j).getQQ() == key) { flag = false; buoy = buoy.getSon().ElementAt(j); break; } } if (flag) { buoy.getSon().AddLast(createNullNode()); buoy = buoy.getSon().ElementAt(buoy.getSon().Count() - 1); } } } else { if (buoy.getSon() == null) { buoy.setSon(new LinkedList <Node.Node> ()); buoy.getSon().AddLast(createNullNode()); if (hasgroup == true) { buoy.getSon().ElementAt(0).setQQ(key); buoy.getSon().ElementAt(0).setInfo(describe); buoy.getSon().ElementAt(0).setGroupName(groupName); buoy.getSon().ElementAt(0).setTime(createTime); buoy.getSon().ElementAt(0).setHasGroup(true); } else { buoy.getSon().ElementAt(0).setQQ(key); buoy.getSon().ElementAt(0).setAge(age); buoy.getSon().ElementAt(0).setSex(sex); buoy.getSon().ElementAt(0).setName(name); buoy.getSon().ElementAt(0).setGroup(new LinkedList <GroupNode.GroupNode>()); buoy.getSon().ElementAt(0).getGroup().AddLast(new GroupNode.GroupNode()); buoy.getSon().ElementAt(0).getGroup().ElementAt(0).setId(groupId); buoy.getSon().ElementAt(0).getGroup().ElementAt(0).setName(groupName); buoy.getSon().ElementAt(0).getGroup().ElementAt(0).setPrivilege(privilege); } } else { for (int j = 0; j < buoy.getSon().Count(); j++) { if (buoy.getSon().ElementAt(j).getQQ() == key) { if (hasgroup == null) { Environment.Exit(1); } else if (hasgroup == true) { buoy.getSon().ElementAt(j).setHasGroup(true); buoy.getSon().ElementAt(j).setQQ(key); buoy.getSon().ElementAt(j).setGroupName(groupName); buoy.getSon().ElementAt(j).setInfo(describe); buoy.getSon().ElementAt(j).setTime(createTime); } else if (hasgroup == false) { buoy.getSon().ElementAt(j).setQQ(key); buoy.getSon().ElementAt(j).setAge(age); buoy.getSon().ElementAt(j).setSex(sex); buoy.getSon().ElementAt(j).setName(name); if (buoy.getSon().ElementAt(j).getGroup() != null) { for (int k = 0; k < buoy.getSon().ElementAt(j).getGroup().Count(); k++) { if (buoy.getSon().ElementAt(j).getGroup().ElementAt(k).getGroupId() == groupId) { buoy.getSon().ElementAt(j).getGroup().ElementAt(k).setName(groupName); buoy.getSon().ElementAt(j).getGroup().ElementAt(k).setPrivilege(privilege); return; } } buoy.getSon().ElementAt(j).getGroup().AddLast(new GroupNode.GroupNode()); int index = buoy.getSon().ElementAt(j).getGroup().Count() - 1; buoy.getSon().ElementAt(j).getGroup().ElementAt(index).setId(groupId); buoy.getSon().ElementAt(j).getGroup().ElementAt(index).setName(groupName); buoy.getSon().ElementAt(j).getGroup().ElementAt(index).setPrivilege(privilege); } else { buoy.getSon().ElementAt(j).setGroup(new LinkedList <GroupNode.GroupNode> ()); buoy.getSon().ElementAt(j).getGroup().AddLast(new GroupNode.GroupNode()); buoy.getSon().ElementAt(j).getGroup().ElementAt(0).setId(groupId); buoy.getSon().ElementAt(j).getGroup().ElementAt(0).setName(groupName); buoy.getSon().ElementAt(j).getGroup().ElementAt(0).setPrivilege(privilege); } } return; } } buoy.getSon().AddLast(createNullNode()); int shadow = buoy.getSon().Count() - 1; if (hasgroup == null) { Environment.Exit(1); } else if (hasgroup == true) { buoy.getSon().ElementAt(shadow).setQQ(key); buoy.getSon().ElementAt(shadow).setHasGroup(true); buoy.getSon().ElementAt(shadow).setGroupName(groupName); buoy.getSon().ElementAt(shadow).setInfo(describe); buoy.getSon().ElementAt(shadow).setTime(createTime); } else if (hasgroup == false) { buoy.getSon().ElementAt(shadow).setQQ(key); buoy.getSon().ElementAt(shadow).setAge(age); buoy.getSon().ElementAt(shadow).setSex(sex); buoy.getSon().ElementAt(shadow).setName(name); if (buoy.getSon().ElementAt(shadow).getGroup() != null) { for (int k = 0; k < buoy.getSon().ElementAt(shadow).getGroup().Count(); k++) { if (buoy.getSon().ElementAt(shadow).getGroup().ElementAt(k).getGroupId() == groupId) { buoy.getSon().ElementAt(shadow).getGroup().ElementAt(k).setName(groupName); buoy.getSon().ElementAt(shadow).getGroup().ElementAt(k).setPrivilege(privilege); return; } } buoy.getSon().ElementAt(shadow).getGroup().AddLast(new GroupNode.GroupNode()); int index = buoy.getSon().ElementAt(shadow).getGroup().Count() - 1; buoy.getSon().ElementAt(shadow).getGroup().ElementAt(index).setId(groupId); buoy.getSon().ElementAt(shadow).getGroup().ElementAt(index).setName(groupName); buoy.getSon().ElementAt(shadow).getGroup().ElementAt(index).setPrivilege(privilege); } else { buoy.getSon().ElementAt(shadow).setGroup(new LinkedList <GroupNode.GroupNode> ()); buoy.getSon().ElementAt(shadow).getGroup().AddLast(new GroupNode.GroupNode()); buoy.getSon().ElementAt(shadow).getGroup().ElementAt(0).setId(groupId); buoy.getSon().ElementAt(shadow).getGroup().ElementAt(0).setName(groupName); buoy.getSon().ElementAt(shadow).getGroup().ElementAt(0).setPrivilege(privilege); } } } } } }
private void init() { root = new Node.Node(); }
public Trie(String path) { root = null; init(); }
public void writeInFile(Node.Node node) { }
public Node.Node search(int info) { Int64 temp = info; String shadow = temp.ToString(); Node.Node aim = getRoot(); for (int i = 0; i < shadow.Length; i++) { int key = shadow [i] - '0'; if (i != shadow.Length - 1) { if (aim == null) { return(null); } else { bool flag = true; for (int j = 0; j < aim.getSon().Count(); j++) { if (aim.getSon().ElementAt(j).getQQ() == key) { flag = false; aim = aim.getSon().ElementAt(j); break; } } if (flag) { return(null); } } } else { if (aim.getSon() == null) { return(null); } else { for (int j = 0; j < aim.getSon().Count(); j++) { if (aim.getSon().ElementAt(j).getQQ() == key) { Node.Node node = aim.getSon().ElementAt(j); this.output = "QQ : " + info; if (node.getName().GetHashCode() != "NULL".GetHashCode()) { this.output += "\n昵称 : " + node.getName(); } if (node.getHasGroup() == true) { this.output += "\n群名 : " + node.getGroupName(); this.output += "\n创建时间 : " + node.getTime(); } if (node.getAge() != -1) { this.output += "\n年龄 : " + node.getAge(); } if (node.getSex() != null) { this.output += "\n性别 : " + (node.getSex() == true ? "男" : "女"); } if (node.getGroup() != null) { for (int k = 0; k < node.getGroup().Count(); k++) { this.output += "\n群号 : " + node.getGroup().ElementAt(k).getGroupId() + "\n群内昵称 : " + node.getGroup().ElementAt(k).getName() + "\n群内权限 : " + node.getGroup().ElementAt(k).getPrivilege(); } } return(aim.getSon().ElementAt(j)); } } } } } return(null); }
public static void Init() { System = new TestSystem(); System.Start(); }