public void Can_assign_to_parameter_via_ExpressionInfo()
        {
            var sParamExpr = Parameter(typeof(string), "s");
            var expr       = ExpressionInfo.Lambda <Func <string, string> >(
                ExpressionInfo.Assign(sParamExpr, ExpressionInfo.Constant("aaa")),
                sParamExpr);

            var f = expr.TryCompile();

            Assert.IsNotNull(f);
            Assert.AreEqual("aaa", f("ignored"));
        }
Exemple #2
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)));
            });
        }
Exemple #3
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)));
            });
        }
        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);
            }));
        }
        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);
                    }
                }
            });
        }
        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;
                }
            });
        }