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)))); }
void IBotSubmitTask.RegisterTask(TaskTemplateType type, SerializedTask serializedTask) { m_state.TaskTemplates[type] = new TaskInfoPool(() => { TaskInfo coreTaskInfo = SerializedTask.ToTaskInfo(serializedTask); return(TaskInfo.Procedure ( null, null, coreTaskInfo, TaskInfo.Return(ExpressionInfo.TaskStatus(coreTaskInfo)) )); }); }
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)) )); }
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 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()); }