Ejemplo n.º 1
0
        public void Evaluate(ExpressionInfo expression, ITaskEngine taskEngine, Action <object> callback)
        {
            IEnumerator enumerator;

            if (expression.Value is TaskInputInfo)
            {
                TaskInputInfo input = (TaskInputInfo)expression.Value;
                enumerator = (IEnumerator)taskEngine.Memory.ReadOutput(input.Scope.TaskId, input.OutputTask.TaskId, input.OutputIndex);
            }
            else
            {
                enumerator = (IEnumerator)expression.Value;
            }

            IterationResult result;

            if (enumerator.MoveNext())
            {
                result = new IterationResult(enumerator.Current, false);
            }
            else
            {
                enumerator.Reset();
                result = new IterationResult(null, true);
            }
            callback(result);
        }
Ejemplo n.º 2
0
        public T ReadInput <T>(TaskInputInfo i, T defaultValue)
        {
            object value = m_taskEngine.Memory.ReadOutput(i.Scope.TaskId, i.OutputTask.TaskId, i.OutputIndex);

            if (value == null)
            {
                return(defaultValue);
            }
            return((T)value);
        }
Ejemplo n.º 3
0
        private TaskInfo MoveToCoordinate(Coordinate[] path, TaskInputInfo unitIndexInput, TaskInputInfo playerIndexInput)
        {
            TaskInfo      pathVar   = TaskInfo.EvalExpression(ExpressionInfo.Val(path));
            TaskInputInfo pathInput = new TaskInputInfo(pathVar, 0);
            TaskInfo      moveTask  = TaskInfo.Move(unitIndexInput, pathInput);

            return(TaskInfo.Procedure(
                       pathVar,
                       moveTask,
                       TaskInfo.Return(ExpressionInfo.TaskStatus(moveTask))));
        }
Ejemplo n.º 4
0
        public void RepeatTaskTestImmediate()
        {
            TaskInputInfo input = new TaskInputInfo {
                OutputIndex = 0
            };
            TaskInfo repeatTask = new TaskInfo {
                TaskType = TaskType.TEST_MockImmediate
            };

            RepeatTaskTest(repeatTask, input, 10, 10);
        }
Ejemplo n.º 5
0
        public static TaskInfo HealMoveToCoordGrow(Coordinate[] path, TaskInputInfo unitIndexInput, TaskInputInfo playerIndexInput)
        {
            TaskInfo taskInfo = TaskInfo.Procedure
                                (
                TaskInfo.SetHealth(unitIndexInput, 64),
                MoveToCoordinate(path, unitIndexInput, playerIndexInput),
                TaskInfo.Grow(unitIndexInput),
                TaskInfo.Return(ExpressionInfo.PrimitiveVal(TaskInfo.TaskSucceded))
                                );

            taskInfo.Inputs = new TaskInputInfo[] { unitIndexInput, playerIndexInput };
            return(taskInfo);
        }
        public static TaskInfo SearchAndMoveAnyway(Coordinate[] waypoints, TaskInputInfo unitIndexInput, TaskInputInfo playerIndexInput)
        {
            TaskInfo defineGoalTask = TaskInfo.EvalExpression(ExpressionInfo.Val(waypoints));
            TaskInfo findPathTask   = TaskInfo.FindPath(unitIndexInput, new TaskInputInfo(defineGoalTask, 0));
            TaskInfo taskInfo       = TaskInfo.Procedure
                                      (
                defineGoalTask,
                findPathTask,
                TaskInfo.Move(unitIndexInput, new TaskInputInfo(findPathTask, 0)),
                TaskInfo.Return(ExpressionInfo.PrimitiveVal(TaskInfo.TaskSucceded))
                                      );

            taskInfo.Inputs = new TaskInputInfo[] { unitIndexInput, playerIndexInput };
            return(taskInfo);
        }
Ejemplo n.º 7
0
        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)));
            });
        }
Ejemplo n.º 8
0
        public void AssignPathVariableCloneTest()
        {
            TaskInfo       findPathTask       = TaskInfo.FindPath(new TaskInputInfo(), new TaskInputInfo());
            TaskInputInfo  pathVariableInput  = new TaskInputInfo(findPathTask, 0);
            ExpressionInfo assignPathVariable = ExpressionInfo.Assign(
                TaskInfo.Var(),
                ExpressionInfo.Val(pathVariableInput));
            TaskInfo task = TaskInfo.Sequence(
                findPathTask,
                TaskInfo.EvalExpression(assignPathVariable)
                );

            Assert.DoesNotThrow(() =>
            {
                SerializedTask.ToTaskInfo(m_protobufSerializer.DeepClone(SerializedTask.FromTaskInfo(task)));
            });
        }
Ejemplo n.º 9
0
        protected override void OnConstruct()
        {
            long          unitIndex  = ReadInput <long>(m_taskInfo.Inputs[0]);
            TaskInputInfo firstInput = m_taskInfo.Inputs[1];
            int           radius     = ReadInput(firstInput, 10);

            m_unit = m_taskEngine.MatchEngine.GetPlayerView(m_taskInfo.PlayerIndex).GetUnit(unitIndex);
            if (m_unit == null)
            {
                m_taskInfo.StatusCode = TaskInfo.TaskFailed;
                m_taskInfo.State      = TaskState.Completed;
                return;
            }

            Coordinate coordinate = m_unit.DataController.Coordinate;
            int        deltaCol;
            int        deltaRow;

            do
            {
                deltaCol = m_random.Next(0, radius + 1);
                deltaRow = m_random.Next(0, radius + 1);
            }while (deltaCol == 0 && deltaRow == 0);

            coordinate.Col = (m_random.Next() % 2 == 0) ?
                             coordinate.Col + deltaCol :
                             coordinate.Col - deltaCol;

            coordinate.Row = (m_random.Next() % 2 == 0) ?
                             coordinate.Row + deltaRow :
                             coordinate.Row - deltaRow;

            m_taskEngine.Memory.WriteOutput(
                firstInput.Scope.TaskId,
                firstInput.OutputTask.TaskId,
                firstInput.OutputIndex,
                new[] { m_unit.DataController.Coordinate, coordinate });

            base.OnConstruct();

            m_taskEngine.Memory.WriteOutput(
                firstInput.Scope.TaskId,
                firstInput.OutputTask.TaskId,
                firstInput.OutputIndex,
                radius);
        }
Ejemplo n.º 10
0
 public void Evaluate(ExpressionInfo expression, ITaskEngine taskEngine, Action <object> callback)
 {
     if (expression.Value is PrimitiveContract)
     {
         PrimitiveContract primitive = (PrimitiveContract)expression.Value;
         callback(primitive.ValueBase);
     }
     else if (expression.Value is TaskInputInfo)
     {
         TaskInputInfo input = (TaskInputInfo)expression.Value;
         object        value = taskEngine.Memory.ReadOutput(input.Scope.TaskId, input.OutputTask.TaskId, input.OutputIndex);
         callback(value);
     }
     else
     {
         callback(expression.Value);
     }
 }
        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)
                           )
                       ));
        }
Ejemplo n.º 12
0
        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))
                       ));
        }
Ejemplo n.º 13
0
        public void RepeatContinueTaskTest()
        {
            TaskInputInfo input = new TaskInputInfo {
                OutputIndex = 0
            };
            ExpressionInfo isTrue       = ExpressionInfo.Val(PrimitiveContract.Create(true));
            TaskInfo       continueTask = new TaskInfo
            {
                TaskType = TaskType.Continue,
            };
            TaskInfo branchTask = new TaskInfo
            {
                TaskType   = TaskType.Branch,
                Expression = isTrue,
                Children   = new[]
                {
                    continueTask,
                    null
                }
            };

            int continueCounter = 0;

            RepeatTaskTest(branchTask, input, 2, 2, childTask =>
            {
                if (continueTask.TaskId == childTask.TaskId && childTask.State == TaskState.Active)
                {
                    continueCounter++;
                    if (continueCounter == 1)
                    {
                        isTrue       = TaskInfo.FindById(branchTask.TaskId, childTask.Root).Expression;
                        isTrue.Value = false;
                    }
                }
            },
                           () =>
            {
                Assert.AreEqual(1, continueCounter);
            });
        }
        public IEnumerator SearchMoveOrRandomMoveLimitedRandomSearchesFailTest()
        {
            yield return(TaskTest(1, (unitIndexInput, playerId) =>
            {
                const int maxRandLocationPicks = 10;
                const int maxRandMovements = 0;
                TaskInfo randomMovementsVar = TaskInfo.Var();
                TaskInputInfo randomMovementsInput = new TaskInputInfo(randomMovementsVar, 0);

                TaskInfo searchMoveOrRandomMove = TaskInfo.SearchMoveOrRandomMove(TaskType.SearchForFood, unitIndexInput, maxRandLocationPicks, randomMovementsInput, maxRandMovements);
                return TaskInfo.Procedure(
                    randomMovementsVar,
                    TaskInfo.EvalExpression(ExpressionInfo.Assign(randomMovementsVar, ExpressionInfo.PrimitiveVal(0))),
                    searchMoveOrRandomMove,
                    TaskInfo.Return(ExpressionInfo.TaskStatus(searchMoveOrRandomMove))
                    );
            }
                                  , true,
                                  rootTaskInfo =>
            {
                Assert.AreEqual(TaskState.Completed, rootTaskInfo.State);
                Assert.IsTrue(rootTaskInfo.IsFailed);
            }));
        }
Ejemplo n.º 15
0
        public void RepeatBreakTaskTest()
        {
            TaskInputInfo input = new TaskInputInfo {
                OutputIndex = 0
            };
            ExpressionInfo eqTo5 = ExpressionInfo.Eq(
                ExpressionInfo.Val(input),
                ExpressionInfo.Val(PrimitiveContract.Create(5)));
            TaskInfo branchTask = new TaskInfo
            {
                TaskType   = TaskType.Branch,
                Expression = eqTo5,
                Children   = new[]
                {
                    new TaskInfo
                    {
                        TaskType = TaskType.Break,
                    },
                    null
                }
            };

            RepeatTaskTest(branchTask, input, 10, 5);
        }
Ejemplo n.º 16
0
        public IEnumerator TaskTest(
            int playerId,
            Func <TaskInputInfo, TaskInputInfo, TaskInfo> GetTestTaskInfo,
            bool shouldTaskBeFailed,
            Action <MapRoot> testStarted,
            Action <TaskInfo> rootTaskCompleted,
            Action <TaskInfo> childTaskCompleted = null,
            int unitNumber = 0,
            string testEnv = TestEnv2)
        {
            BeginTest(testEnv, 2, 0, () =>
            {
                MapRoot map = Dependencies.Map.Map;
                testStarted(map);

                IMatchEngineCli matchEngineCli = Dependencies.MatchEngine;
                Coordinate[] coords            = map.FindDataOfType((int)KnownVoxelTypes.Eater, playerId);
                VoxelData voxel              = map.Get(coords[unitNumber]);
                TaskInfo unitIndexTask       = TaskInfo.UnitOrAssetIndex(voxel.UnitOrAssetIndex);
                TaskInfo playerIndexTask     = TaskInfo.EvalExpression(ExpressionInfo.PrimitiveVal(playerId));
                TaskInputInfo unitIndexInput = new TaskInputInfo
                {
                    OutputIndex = 0,
                    OutputTask  = unitIndexTask
                };
                TaskInputInfo playerIndexInput = new TaskInputInfo
                {
                    OutputIndex = 0,
                    OutputTask  = playerIndexTask
                };

                TaskInfo testTaskInfo = GetTestTaskInfo(unitIndexInput, playerIndexInput);
                TaskInfo rootTask     = TaskInfo.Procedure(
                    playerIndexTask,
                    unitIndexTask,
                    testTaskInfo,
                    TaskInfo.Return(ExpressionInfo.TaskStatus(testTaskInfo)));
                rootTask.SetParents();
                rootTask.Initialize(playerId);

                ITaskEngine taskEngine = matchEngineCli.GetClientTaskEngine(playerId);
                TaskEngineEvent <TaskInfo> taskStateChanged = null;
                taskStateChanged = taskInfo =>
                {
                    if (taskInfo.State == TaskState.Completed)
                    {
                        if (taskInfo.TaskId == rootTask.TaskId)
                        {
                            Assert.AreEqual(shouldTaskBeFailed, taskInfo.IsFailed, taskInfo.ToString());
                            taskEngine.TaskStateChanged -= taskStateChanged;
                            rootTaskCompleted(taskInfo);
                            EndTest();
                        }
                        else
                        {
                            if (childTaskCompleted != null)
                            {
                                childTaskCompleted(taskInfo);
                            }
                        }
                    }
                    else if (taskInfo.State != TaskState.Idle)
                    {
                        Assert.AreEqual(TaskState.Active, taskInfo.State, taskInfo.ToString());
                    }
                };
                taskEngine.TaskStateChanged += taskStateChanged;
                taskEngine.SubmitTask(rootTask);
            });


            yield return(Run());
        }
        public IEnumerator SearchForFoodTaskTest(int playerId, Action <ITaskEngine, TaskInfo, TaskInfo, Coordinate[]> callback)
        {
            BeginTest(TestEnv1, 2, 0, () =>
            {
                MapRoot map = Dependencies.Map.Map;
                IMatchEngineCli matchEngineCli = Dependencies.MatchEngine;

                Coordinate[] coords = map.FindDataOfType((int)KnownVoxelTypes.Eater, playerId);
                VoxelData voxel     = map.Get(coords[0]);

                TaskInfo searchForFoodTask = new TaskInfo(TaskType.SearchForFood)
                {
                    OutputsCount = 2
                };
                TaskInputInfo searchForFoodContext = new TaskInputInfo
                {
                    OutputIndex = 0,
                    OutputTask  = searchForFoodTask,
                };

                TaskInfo getUnitIndexTask = new TaskInfo(TaskType.EvalExpression)
                {
                    Expression   = ExpressionInfo.PrimitiveVal(voxel.UnitOrAssetIndex),
                    OutputsCount = 1
                };
                TaskInputInfo unitIndex = new TaskInputInfo
                {
                    OutputIndex = 0,
                    OutputTask  = getUnitIndexTask
                };

                searchForFoodTask.Inputs = new[] { searchForFoodContext, unitIndex };
                TaskInfo rootTask        = new TaskInfo(TaskType.Sequence)
                {
                    Children = new[] { getUnitIndexTask, searchForFoodTask }
                };

                rootTask.SetParents();
                rootTask.Initialize(playerId);

                ITaskEngine taskEngine = matchEngineCli.GetClientTaskEngine(playerId);
                TaskEngineEvent <TaskInfo> taskStateChanged = null;
                taskStateChanged = taskInfo =>
                {
                    if (taskInfo.State == TaskState.Completed)
                    {
                        if (taskInfo.TaskId == searchForFoodTask.TaskId)
                        {
                            callback(taskEngine, taskInfo, searchForFoodTask, coords);
                        }
                        else if (taskInfo.TaskId == rootTask.TaskId)
                        {
                            taskEngine.TaskStateChanged -= taskStateChanged;

                            EndTest();
                        }
                    }
                    else
                    {
                        Assert.AreEqual(TaskState.Active, taskInfo.State);
                    }
                };
                taskEngine.TaskStateChanged += taskStateChanged;
                taskEngine.SubmitTask(rootTask);
            });

            yield return(Run());
        }
Ejemplo n.º 18
0
        public void IterateRepeatTest()
        {
            Assert.DoesNotThrow(() =>
            {
                BeginTest(TestEnv0, 4);
            });

            List <int> integers = new List <int>()
            {
                1, 2, 3, 4, 5
            };
            TaskInfo iterateTask = new TaskInfo
            {
                TaskType     = TaskType.EvalExpression,
                Expression   = ExpressionInfo.Iterate(integers),
                OutputsCount = 1,
            };

            TaskInputInfo input = new TaskInputInfo
            {
                OutputIndex = 0,
                OutputTask  = iterateTask,
            };

            ExpressionInfo isTrue = ExpressionInfo.Eq(
                ExpressionInfo.Val(PrimitiveContract.Create(true)),
                ExpressionInfo.Get(
                    ExpressionInfo.Val(input),
                    ExpressionInfo.PrimitiveVal("IsLast")));

            TaskInfo breakIfCompleted = new TaskInfo
            {
                TaskType   = TaskType.Branch,
                Expression = isTrue,
                Children   = new[]
                {
                    new TaskInfo
                    {
                        TaskType = TaskType.Break,
                    },
                    null
                }
            };

            TaskInfo repeat = new TaskInfo
            {
                TaskType   = TaskType.Repeat,
                Expression = ExpressionInfo.PrimitiveVal(true),
                Children   = new[]
                {
                    iterateTask,
                    breakIfCompleted,
                }
            };

            repeat.SetParents();
            input.SetScope();

            const int playerId   = 1;
            bool      isIterated = false;
            int       counter    = 0;

            BeginCleanupCheck(playerId);

            FinializeTest(playerId, repeat, result =>
            {
                Assert.IsTrue(isIterated);

                Assert.AreEqual(TaskState.Completed, result.State);
                Assert.IsFalse(result.IsFailed);
                CleanupCheck(playerId);

                Assert.Pass();
            },
                          childTask =>
            {
                if (childTask.TaskId == iterateTask.TaskId && childTask.State == TaskState.Completed)
                {
                    counter++;
                    ITaskMemory memory         = m_engine.GetTaskEngine(playerId).Memory;
                    IterationResult iterResult = (IterationResult)memory.ReadOutput(iterateTask.Parent.TaskId, iterateTask.TaskId, 0);
                    if (iterResult.IsLast)
                    {
                        isIterated = true;
                        Assert.IsNull(iterResult.Object);
                    }
                    else
                    {
                        Assert.AreEqual(counter, (int)iterResult.Object);
                    }
                }
            });
        }
Ejemplo n.º 19
0
        public void RepeatTaskTest(TaskInfo repeatChildTask, TaskInputInfo input, int iterations, int expectedIterations, TaskEngineEvent <TaskInfo> childTaskCallback = null, Action pass = null)
        {
            Assert.DoesNotThrow(() =>
            {
                BeginTest(TestEnv0, 4);
            });

            ExpressionInfo setToZero = ExpressionInfo.Val(PrimitiveContract.Create(0));
            ExpressionInfo add       = ExpressionInfo.Add(
                ExpressionInfo.Val(input),
                ExpressionInfo.Val(PrimitiveContract.Create(1)));
            ExpressionInfo lessThanValue = ExpressionInfo.Lt(
                ExpressionInfo.Val(input),
                ExpressionInfo.Val(PrimitiveContract.Create(iterations)));

            TaskInfo setToZeroTask = new TaskInfo
            {
                TaskType     = TaskType.EvalExpression,
                OutputsCount = 1,
                Expression   = setToZero,
            };

            input.OutputTask = setToZeroTask;

            ExpressionInfo increment     = ExpressionInfo.Assign(setToZeroTask, add);
            TaskInfo       incrementTask = new TaskInfo
            {
                TaskType     = TaskType.EvalExpression,
                Expression   = increment,
                OutputsCount = 1,
                Inputs       = new[] { input },
            };

            TaskInfo repeatTask = new TaskInfo();

            repeatTask.TaskType   = TaskType.Repeat;
            repeatTask.Expression = lessThanValue;

            repeatTask.Children = new[]
            {
                repeatChildTask,
                incrementTask
            };

            TaskInfo task = new TaskInfo
            {
                TaskType = TaskType.Sequence,
                Children = new[]
                {
                    setToZeroTask,
                    repeatTask
                }
            };

            task.SetParents();
            const int playerId = 1;

            task.Initialize(playerId);

            //
            //input.SetScope();

            bool isIncremented = false;

            BeginCleanupCheck(playerId);
            FinializeTest(playerId, task, result =>
            {
                Assert.IsTrue(isIncremented);
                Assert.AreEqual(TaskState.Completed, result.State);
                Assert.IsFalse(result.IsFailed);
                CleanupCheck(playerId);
                if (pass != null)
                {
                    pass();
                }
                Assert.Pass();
            },
                          childTask =>
            {
                if (childTask.TaskId == repeatTask.TaskId && childTask.State == TaskState.Completed)
                {
                    ITaskMemory memory = m_engine.GetTaskEngine(playerId).Memory;
                    Assert.AreEqual(expectedIterations, memory.ReadOutput(setToZeroTask.Parent.TaskId, setToZeroTask.TaskId, 0));
                    isIncremented = true;
                }
                else
                {
                    if (childTaskCallback != null)
                    {
                        childTaskCallback(childTask);
                    }
                }
            });
        }
Ejemplo n.º 20
0
        public void IncrementTaskTest()
        {
            Assert.DoesNotThrow(() =>
            {
                BeginTest(TestEnv0, 4);
            });

            TaskInputInfo input = new TaskInputInfo
            {
                OutputIndex = 0
            };

            ExpressionInfo setToZero = ExpressionInfo.Val(PrimitiveContract.Create(0));
            ExpressionInfo add       = ExpressionInfo.Add(
                ExpressionInfo.Val(input),
                ExpressionInfo.Val(PrimitiveContract.Create(1)));

            TaskInfo setToZeroTask = new TaskInfo
            {
                TaskType     = TaskType.EvalExpression,
                OutputsCount = 1,
                Expression   = setToZero,
            };

            ExpressionInfo increment     = ExpressionInfo.Assign(setToZeroTask, add);
            TaskInfo       incrementTask = new TaskInfo
            {
                TaskType     = TaskType.EvalExpression,
                Expression   = increment,
                OutputsCount = 1,
                Inputs       = new[] { input },
            };

            TaskInfo task = new TaskInfo
            {
                TaskType = TaskType.Sequence,
                Children = new[]
                {
                    setToZeroTask,
                    incrementTask
                }
            };

            task.SetParents();

            input.OutputTask = setToZeroTask;
            input.SetScope();

            bool      isIncremented = false;
            const int playerId      = 1;

            BeginCleanupCheck(playerId);
            FinializeTest(playerId, task, result =>
            {
                Assert.IsTrue(isIncremented);
                Assert.AreEqual(TaskState.Completed, result.State);
                Assert.IsFalse(result.IsFailed);
                CleanupCheck(playerId);
                Assert.Pass();
            },
                          childTask =>
            {
                if (childTask.TaskId == incrementTask.TaskId && childTask.State == TaskState.Completed)
                {
                    ITaskMemory memory = m_engine.GetTaskEngine(playerId).Memory;
                    Assert.AreEqual(1, memory.ReadOutput(setToZeroTask.Parent.TaskId, setToZeroTask.TaskId, 0));
                    isIncremented = true;
                }
            });
        }
Ejemplo n.º 21
0
 public T ReadInput <T>(TaskInputInfo i)
 {
     return((T)m_taskEngine.Memory.ReadOutput(i.Scope.TaskId, i.OutputTask.TaskId, i.OutputIndex));
 }