private void Pursuit(IdleNode node, TankCollisionNode target) { var path = node.ai.GetPath(node.position.position, target.position.position, gameField, cellSize); node.ai.path = path; node.ai.target = target; }
private NodeBunch BuildItem(Element item) { var car = item.GetCarSymbolName(); NodeBunch buildResult; INode node; NodeBox nodeBox; switch (car) { case "BLOCK": buildResult = this.BuildBlock(item); break; case "ALT": buildResult = this.BuildAlt(item); break; case "OPT": buildResult = this.BuildOpt(item); break; case "SEQ": buildResult = this.BuildSeq(item); break; case "IDLE": node = new IdleNode( _nodeFactory.NodeFamily, item.GetItemName()); nodeBox = new NodeBox(node, item.GetItemLinks()); buildResult = new NodeBunch(nodeBox, nodeBox); break; case "END": node = EndNode.Instance; nodeBox = new NodeBox(node); buildResult = new NodeBunch(nodeBox, nodeBox); break; default: buildResult = this.BuildCustomItem(item); break; } return(buildResult); }
public void Parse_Concurrency_ThrowsNodeConcurrencyException() { // Arrange INodeFamily nodeFamily = new NodeFamily("family"); INode idle = new IdleNode(nodeFamily, null); INode exactText = new ExactTextNode( "foo", new[] { WordTextClass.Instance, }, false, (node, token, arg3) => { }, nodeFamily, null); INode someText = new TextNode( new ITextClass[] { WordTextClass.Instance, }, null, nodeFamily, null); idle.EstablishLink(someText); idle.EstablishLink(exactText); someText.EstablishLink(EndNode.Instance); exactText.EstablishLink(EndNode.Instance); IParser parser = new Parser(); var tokens = new List <IToken> { new TextToken( WordTextClass.Instance, NoneTextDecoration.Instance, "foo", Position.Zero, 3), }; // Act parser.Root = idle; var ex = Assert.Throws <NodeConcurrencyException>(() => parser.Parse(tokens)); // Assert Assert.That(ex.Message, Is.EqualTo("More than one node accepted the token.")); Assert.That(ex.ConcurrentNodes, Has.Length.EqualTo(2)); Assert.That(ex.ConcurrentNodes, Does.Contain(exactText)); Assert.That(ex.ConcurrentNodes, Does.Contain(someText)); Assert.That(ex.Token, Is.SameAs(tokens.Single())); }
protected virtual INode BuildNode() { var node = new IdleNode(_nodeFamily, "Idle root of empty host"); return(node); }
private void Attack(IdleNode node, TankCollisionNode target) { node.ai.target = target; node.ai.path.Clear(); node.position.nextDirection = node.ai.GetDirectionToTarget(node.position.position, target.position.position); }
public void Parse_ValidInput_ParsesCorrectly() { // Arrange var connectionString = "Server=.;Database=econera.diet.tracking;Trusted_Connection=True;"; var provider = "sqlserver"; var filePath = "c:/temp/mysqlite.json"; var commandText = $"sd --connection \"{connectionString}\" --provider {provider} -f {filePath}"; var lexer = new Lexer { Producers = new ILexicalTokenProducer[] { new WhiteSpaceProducer(), new CliKeyProducer(), new CliWordProducer(), new JsonStringProducer(), new FilePathProducer(), }, }; var root = new TermNode("sd"); var idleNode = new IdleNode(); var connectionKeyNode = new KeyNode(new[] { "-c", "--connection" }, "connection", true); var connectionValueNode = new KeyValueNode("connection"); var providerKeyNode = new KeyNode(new[] { "-p", "--provider" }, "provider", true); var providerValueNode = new KeyValueNode("provider"); var fileKeyNode = new KeyNode(new[] { "-f", "--file" }, "file", true); var fileValueNode = new KeyValueNode("file"); var endNode = EndNode.Instance; root.AddLink(idleNode); idleNode.AddLink(connectionKeyNode); idleNode.AddLink(providerKeyNode); idleNode.AddLink(fileKeyNode); connectionKeyNode.AddLink(connectionValueNode); providerKeyNode.AddLink(providerValueNode); fileKeyNode.AddLink(fileValueNode); connectionValueNode.AddLink(idleNode); connectionValueNode.AddLink(endNode); providerValueNode.AddLink(idleNode); providerValueNode.AddLink(endNode); fileValueNode.AddLink(idleNode); fileValueNode.AddLink(endNode); var parser = new Parser { Root = root, }; // Act var tokens = lexer.Tokenize(commandText.AsMemory()); var result = new CliParsingResult(); parser.Parse(tokens, result); // Assert Assert.That(result.Command, Is.EqualTo("sd")); Assert.That(result.KeyValues, Has.Count.EqualTo(3)); Assert.That(result.KeyValues, Does.ContainKey("connection")); Assert.That(result.KeyValues["connection"].Single(), Is.EqualTo(connectionString)); Assert.That(result.KeyValues, Does.ContainKey("provider")); Assert.That(result.KeyValues["provider"].Single(), Is.EqualTo(provider)); Assert.That(result.KeyValues, Does.ContainKey("file")); Assert.That(result.KeyValues["file"].Single(), Is.EqualTo(filePath)); }
protected override INode CreateNodeTree() { var addIns = this.CreateAddIns(); if (addIns == null) { throw new CliException($"'{nameof(CreateAddIns)}' must not return null."); } if (addIns.Count == 0) { _addInList = new List <ICliAddIn>(); var dummyRoot = new IdleNode(_nodeFamily, $"Dummy root node of empty host '{this.Name}'"); dummyRoot.EstablishLink(EndNode.Instance); return(dummyRoot); } var validTypes = addIns.All(x => x is CliAddInBase); if (!validTypes) { throw new CliException($"'{nameof(CreateAddIns)}' must return instances of type '{typeof(CliAddInBase).FullName}'."); } if (addIns.Any(x => x.Name == null)) { if (addIns.Count > 1) { throw new CliException($"'{nameof(CreateAddIns)}' must return either all add-ins having non-null name, or exactly one add-in with null name."); } var singleUnnamedAddIn = addIns.Single(); _singleUnnamedAddInRecord = new AddInRecord(singleUnnamedAddIn, singleUnnamedAddIn.GetExecutors()); } foreach (var addIn in addIns) { ((CliAddInBase)addIn).Host = this; } var root = new IdleNode(_nodeFamily, $"Root node of host '{this.Name}'"); if (_singleUnnamedAddInRecord == null) { // all add-ins are named foreach (var addIn in addIns) { root.EstablishLink(addIn.Node); var record = new AddInRecord( addIn, addIn.GetExecutors()); _addInRecords.Add(addIn.Name, record); } _addInList = _addInRecords .Values .Select(x => x.AddIn) .ToList(); } else { root.EstablishLink(_singleUnnamedAddInRecord.AddIn.Node); _addInList = new List <ICliAddIn> { _singleUnnamedAddInRecord.AddIn, }; } return(root); }
public override INode CreateNode(PseudoList item) { var car = item.GetCarSymbolName().ToLowerInvariant(); if (car == "executor") { INode executorNode; var executorName = item.GetSingleKeywordArgument <Symbol>(":executor-name", true)?.Name; if (executorName == null) { executorNode = new IdleNode(this.NodeFamily, $"Root node for unnamed executor of type {this.GetType().FullName}"); } else { executorNode = new MultiTextNode( new string[] { item.GetSingleKeywordArgument <StringAtom>(":verb").Value }, new ITextClass[] { TermTextClass.Instance, }, true, ExecutorAction, this.NodeFamily, $"Executor Node. Name: [{executorName}]"); executorNode.Properties["executor-name"] = executorName; } return(executorNode); } var node = base.CreateNode(item); if (node == null) { throw new CliException($"Could not build node for item '{car}'."); } if (node is FallbackNode) { return(node); } if (!(node is ActionNode)) { throw new CliException($"'{typeof(ActionNode).Name}' instance was expected to be created."); } var baseResult = (ActionNode)node; var action = item.GetSingleKeywordArgument <Symbol>(":action", true)?.Name?.ToLowerInvariant(); string alias; switch (action) { case "key": baseResult.Action = KeyAction; alias = item.GetSingleKeywordArgument <Symbol>(":alias").Name; baseResult.Properties["alias"] = alias; break; case "value": baseResult.Action = ValueAction; break; case "option": baseResult.Action = OptionAction; alias = item.GetSingleKeywordArgument <Symbol>(":alias").Name; baseResult.Properties["alias"] = alias; break; case "argument": baseResult.Action = ArgumentAction; alias = item.GetSingleKeywordArgument <Symbol>(":alias").Name; baseResult.Properties["alias"] = alias; break; default: throw new CliException($"Keyword ':action' is missing or invalid for item '{car}'."); } return(baseResult); }