public void RepeatProcedureReturnTest() { Assert.DoesNotThrow(() => { BeginTest(TestEnv0, 4); }); TaskInfo procedure = TaskInfo.Procedure( TaskInfo.Repeat( ExpressionInfo.PrimitiveVal(true), new TaskInfo(TaskType.TEST_Mock), new TaskInfo(TaskType.TEST_MockImmediate), new TaskInfo(TaskType.TEST_MockImmediate), TaskInfo.Return(ExpressionInfo.PrimitiveVal(TaskInfo.TaskSucceded)), new TaskInfo(TaskType.TEST_Fail) ) ); TaskInfo root = TaskInfo.Sequence ( procedure, TaskInfo.Branch( ExpressionInfo.TaskSucceded(procedure), new TaskInfo(TaskType.Nop), new TaskInfo(TaskType.TEST_Fail) ) ); root.SetParents(); const int playerId = 1; BeginCleanupCheck(playerId); FinializeTest(playerId, root, result => { Assert.AreEqual(root.TaskId, result.TaskId); Assert.AreEqual(TaskState.Completed, result.State); Assert.IsFalse(result.IsFailed); CleanupCheck(playerId); Assert.Pass(); }, childTask => { }); }
public void SearchForPathCloneTest2() { TaskInfo searchForTask = TaskInfo.SearchFor(TaskType.SearchForFood, new TaskInputInfo()); ExpressionInfo searchForSucceded = ExpressionInfo.TaskSucceded(searchForTask); TaskInputInfo coordinateInput = new TaskInputInfo(searchForTask, 1); TaskInfo findPathTask = TaskInfo.FindPath(new TaskInputInfo(), coordinateInput); ExpressionInfo findPathSucceded = ExpressionInfo.TaskSucceded(findPathTask); TaskInputInfo pathVariableInput = new TaskInputInfo(findPathTask, 0); ExpressionInfo assignPathVariable = ExpressionInfo.Assign( TaskInfo.Var(), ExpressionInfo.Val(pathVariableInput)); ExpressionInfo whileTrue = ExpressionInfo.PrimitiveVal(true); TaskInfo task = TaskInfo.Procedure( TaskInfo.Repeat( whileTrue, searchForTask, TaskInfo.Branch( searchForSucceded, TaskInfo.Sequence( findPathTask, TaskInfo.Branch( findPathSucceded, TaskInfo.Sequence( TaskInfo.EvalExpression(assignPathVariable), TaskInfo.Return() ), TaskInfo.Continue() ) ), TaskInfo.Return(ExpressionInfo.PrimitiveVal(TaskInfo.TaskFailed)) ) ) ); Assert.DoesNotThrow(() => { SerializedTask.ToTaskInfo(m_protobufSerializer.DeepClone(SerializedTask.FromTaskInfo(task))); }); }
private TaskInfo PathToRandomLocation(TaskInputInfo unitIndexInput, TaskInputInfo playerInput) { int radius = 3; TaskInfo radiusVar = TaskInfo.EvalExpression(ExpressionInfo.PrimitiveVal(radius)); TaskInputInfo radiusInput = new TaskInputInfo { OutputIndex = 0, OutputTask = radiusVar }; TaskInfo pathToRandomLocation = TaskInfo.PathToRandomLocation(unitIndexInput, radiusInput); TaskInputInfo pathInput = new TaskInputInfo { OutputIndex = 0, OutputTask = pathToRandomLocation }; TaskInfo assert = TaskInfo.Assert((taskBase, taskInfo) => { Coordinate[] path = taskBase.ReadInput <Coordinate[]>(taskInfo.Inputs[0]); Assert.IsNotNull(path); Assert.IsTrue(path.Length > 1); Coordinate first = path[0]; Coordinate last = path[path.Length - 1]; Assert.LessOrEqual(Mathf.Abs(first.Row - last.Row), 3); Assert.LessOrEqual(Mathf.Abs(first.Col - last.Col), 3); return(TaskState.Completed); }); assert.Inputs = new[] { pathInput }; return(TaskInfo.Sequence( radiusVar, pathToRandomLocation, TaskInfo.Branch( ExpressionInfo.TaskSucceded(pathToRandomLocation), assert, new TaskInfo(TaskType.TEST_Fail) ) )); }
private TaskInfo SearchForTestTargetAndMove(TaskInputInfo unitIndexInput, TaskInputInfo playerIndexInput) { TaskInfo pathVar = TaskInfo.Var(); TaskInfo searhForPathTask = TaskInfo.SearchForPath(TaskType.TEST_SearchForWall, pathVar, unitIndexInput); ExpressionInfo pathFound = ExpressionInfo.TaskSucceded(searhForPathTask); TaskInputInfo pathInput = new TaskInputInfo(pathVar, 0); TaskInfo moveTask = TaskInfo.Move(unitIndexInput, pathInput); return(TaskInfo.Procedure( pathVar, TaskInfo.Log("search for path started"), searhForPathTask, TaskInfo.Log( ExpressionInfo.Add( ExpressionInfo.PrimitiveVal("path found ? "), pathFound) ), moveTask, TaskInfo.Return(ExpressionInfo.TaskStatus(moveTask)) )); }