public void GetStartKeys() { var AT = new AlphaTrie<string>(); Assert.IsNotNull(AT.FindByKeyStart("a").Count() == 0); AT.Insert("a", "word"); Assert.IsNotNull(AT.FindByKeyStart("a").Count() == 1); AT.Insert("ab", "word"); Assert.IsNotNull(AT.FindByKeyStart("a").Count() == 2); AT.Insert("aba", "word"); Assert.IsNotNull(AT.FindByKeyStart("a").Count() == 3); AT.Insert("abb", "word"); Assert.IsNotNull(AT.FindByKeyStart("a").Count() == 4); AT.Insert("abab", "word"); Assert.IsNotNull(AT.FindByKeyStart("a").Count() == 5); Assert.IsNotNull(AT.FindByKeyStart("b").Count() == 0); AT.Insert("bbbb", "word"); Assert.IsNotNull(AT.FindByKeyStart("b").Count() == 1); AT.Insert("bbba", "word"); Assert.IsNotNull(AT.FindByKeyStart("b").Count() == 2); AT.Insert("bbb", "word"); Assert.IsNotNull(AT.FindByKeyStart("b").Count() == 3); AT.Insert("bb", "word"); Assert.IsNotNull(AT.FindByKeyStart("b").Count() == 4); AT.Insert("b", "word"); Assert.IsNotNull(AT.FindByKeyStart("b").Count() == 5); }
public void MultipleInsertion() { var AT = new AlphaTrie<string>(); AT.Insert("first", "word"); Assert.IsNotNull(AT.FindByKeyExact("first")); AT.Insert("firsts", "awesome"); Assert.IsNotNull(AT.FindByKeyExact("first")); Assert.IsNotNull(AT.FindByKeyExact("firsts")); AT.Insert("second", "time"); Assert.IsNotNull(AT.FindByKeyExact("first")); Assert.IsNotNull(AT.FindByKeyExact("firsts")); Assert.IsNotNull(AT.FindByKeyExact("second")); AT.Insert("seconds", "matter"); Assert.IsNotNull(AT.FindByKeyExact("first")); Assert.IsNotNull(AT.FindByKeyExact("firsts")); Assert.IsNotNull(AT.FindByKeyExact("second")); Assert.IsNotNull(AT.FindByKeyExact("seconds")); AT.Insert("secondary", "place"); Assert.IsNotNull(AT.FindByKeyExact("first")); Assert.IsNotNull(AT.FindByKeyExact("firsts")); Assert.IsNotNull(AT.FindByKeyExact("second")); Assert.IsNotNull(AT.FindByKeyExact("seconds")); Assert.IsNotNull(AT.FindByKeyExact("secondary")); }
private void RebuildCommandTrie() { _Commands = new AlphaTrie<CommandHandler>(); AddPlayerCommands(_Commands); }
private static void AddPlayerCommands(AlphaTrie<CommandHandler> _) { _.Insert( "say", new CommandHandler( new CommandHandler.PlayerCheckDelegate[] { CheckPlayerIsAlive }, delegate(Player p, string[] words) { if (words.Length < 2) { p.SendMessage("What did you want to <say>, exactly?"); p.SendPrompt(); } else { Event.Send(new { Type = EventType.Say, Sender = p, Text = string.Join(" ", words, 1, words.Length - 1) }); } return null; })); _.Insert( "emote", new CommandHandler( new CommandHandler.PlayerCheckDelegate[] { CheckPlayerIsAlive }, delegate(Player p, string[] words) { if (words.Length < 2) { p.SendMessage("What were you trying to do?"); p.SendPrompt(); } else { Event.Send(new { Type = EventType.Emote, Sender = p, Text = string.Join(" ", words, 1, words.Length - 1) }); } return null; })); _.Insert( "tell", new CommandHandler( new CommandHandler.PlayerCheckDelegate[] { CheckPlayerIsAlive }, delegate(Player p, string[] words) { if (words.Length < 3) { p.SendMessage("Who did you want to <tell> what?"); p.SendPrompt(); } else { string name = words[1]; IEntity to = p.Location.ResolveName(name); if (to != null) { Event.Send(new { Type = EventType.Tell, Sender = p, Recipient = to, Text = string.Join(" ", words, 2, words.Length - 2) }); } else { p.SendMessage("Who do you think you're talking to? There's nobody named {0} here.", name); p.SendPrompt(); } } return null; })); _.Insert( "look", new CommandHandler( new CommandHandler.PlayerCheckDelegate[] { }, delegate(Player p, string[] words) { p.PerformLook(words); p.SendPrompt(); return null; })); _.Insert( "go", new CommandHandler( new CommandHandler.PlayerCheckDelegate[] { CheckPlayerIsAlive }, delegate(Player p, string[] words) { try { string exitText = string.Join(" ", words, 1, words.Length - 1).Trim().ToLower(); Action<Exit> go = (exit) => { if (World.Locations.ContainsKey(exit.Target.ToLower())) p.Location = World.Locations[exit.Target.ToLower()]; else { Console.WriteLine("Warning: '{0}' exit '{1}' leads to undefined location '{2}'.", p.Location.Name, exit.Description, exit.Target); p.SendMessage("Your attempt to leave via {0} is thwarted by a mysterious force.", exit.Description); p.SendPrompt(); } }; foreach (var e in p.Location.Exits) { if (e.Description.ToLower().Contains(exitText)) { go(e); break; } } } catch { p.SendMessage("You can't find that exit."); p.SendPrompt(); } return null; })); _.Insert( "kill", new CommandHandler( new CommandHandler.PlayerCheckDelegate[] { CheckPlayerIsAlive }, delegate(Player p, string[] words) { if (words.Length < 2) { p.SendMessage("Who did you want to kill?"); p.SendPrompt(); } else if (p.InCombat) { p.SendMessage("You're already busy fighting!"); p.SendPrompt(); } else { string name = words[1]; IEntity to = p.Location.ResolveName(name); if (to == p) { p.SendMessage("You don't really want to kill yourself, you're just looking for attention."); p.SendPrompt(); } else if (to != null) { if (to is CombatEntity) { CombatEntity cto = to as CombatEntity; if (cto.InCombat == false) { p.StartCombat(cto); cto.StartCombat(p); Event.Send(new { Type = EventType.CombatStart, Sender = p, Target = cto }); } else { p.SendMessage("They're already in combat, and you don't want to interfere."); p.SendPrompt(); } } else { p.SendMessage("You don't think that's such a great idea."); p.SendPrompt(); } } else { p.SendMessage("Who are you trying to kill, exactly? There's nobody named {0} here.", name); p.SendPrompt(); } } return null; })); _.Insert( "quit", new CommandHandler( new CommandHandler.PlayerCheckDelegate[] { }, delegate(Player p, string[] words) { p.Client.Dispose(); return null; })); _.Insert( "commands", new CommandHandler( new CommandHandler.PlayerCheckDelegate[] { }, delegate(Player p, string[] words) { p.SendMessage("Commands:"); foreach (var Command in p._Commands.Traverse()) p.SendMessage(" {0}", Command.Key); return null; })); _.Insert( "help", new CommandHandler( new CommandHandler.PlayerCheckDelegate[] { CheckPlayerIsAlive }, delegate(Player p, string[] words) { p.SendMessage("You can <say> things to those nearby, if you feel like chatting."); p.SendMessage("You can also <tell> somebody things if you wish to speak privately."); p.SendMessage("You can also <emote> within sight of others."); p.SendMessage("If you're feeling lost, try taking a <look> around."); p.SendMessage("To move somewhere either <go> there, or enter the name of the exit."); p.SendMessage("Looking to make trouble? Try to <kill> someone!"); p.SendMessage("If you get bored you can always <quit> the game."); p.SendPrompt(); return null; })); }
public void RemoveTest() { var AT = new AlphaTrie<string>(); AT.Insert("first", "word"); AT.Insert("firsts", "awesome"); AT.Insert("second", "time"); AT.Insert("seconds", "matter"); AT.Insert("secondary", "place"); Assert.IsTrue(AT.Remove("first")); Assert.IsTrue(AT.Remove("seconds")); Assert.IsFalse(AT.Remove("seconds")); AT.Insert("seconds", "matter"); Assert.IsTrue(AT.Remove("seconds")); Assert.IsFalse(AT.Remove("pancakes")); Assert.IsNotNull(AT.FindByKeyExact("firsts")); Assert.IsNotNull(AT.FindByKeyExact("second")); Assert.IsNotNull(AT.FindByKeyExact("secondary")); }
public void NoNullValues() { var AT = new AlphaTrie<string>(); try { AT.Insert("null", null); Assert.Fail("Inserting a Null value into the AlphaTrie succeeded."); } catch (InvalidOperationException) { } }
public void FirstInsertion() { var AT = new AlphaTrie<string>(); AT.Insert("first", "word"); Assert.IsNotNull(AT.FindByKeyExact("first")); }