public SerializedTask(PrimitiveTask t, SerializedTask p) { type = "Primitive"; parent = p; name = t.name; cost = t.cost; preconditions = t.preconditions; cuncurrentTasks = t.cuncurrentTasks; effects = t.effects; arguments = t.arguments; arguments.Capacity = 3; actionType = t.actionType; groundData.name = t.groundData.name; groundData.radius = t.groundData.radius; groundData.speed = t.groundData.speed; groundData.animationState = t.groundData.animationState; loop = t.loop; logicalOperator = t.logicalOperator; }
private SerializedTask[] CreateDefaultTaskTemplates() { List <SerializedTask> taskTemplates = new List <SerializedTask>(); taskTemplates.Add(SerializedTask.FromTaskInfo(TaskInfo.EatGrowSplit4())); return(taskTemplates.ToArray()); }
public SerializedMethod(Method m, SerializedTask p) { name = m.name; parent = p; preference = m.preference; preconditions = m.preconditions; logicalOperator = m.logicalOperator; subtasks = new List <SerializedTask> (); foreach (Task t in m.subtasks) { if (t.GetType() == typeof(CompoundTask)) { subtasks.Add(new SerializedTask((CompoundTask)t, parent)); } else if (t.GetType() == typeof(PrimitiveTask)) { subtasks.Add(new SerializedTask((PrimitiveTask)t, parent)); } } }
protected void FinializeTest(int playerIndex, TaskInfo task, TaskEngineEvent <TaskInfo> callback, TaskEngineEvent <TaskInfo> childTaskCallback = null) { long identity = 0; TaskEngine.GenerateIdentitifers(task, ref identity); TaskEngineEvent <TaskInfo> taskStateChangedEventHandler = null; taskStateChangedEventHandler = taskInfo => { if (taskInfo.TaskId == task.TaskId) { if (taskInfo.State != TaskState.Active) { m_engine.GetTaskEngine(playerIndex).TaskStateChanged -= taskStateChangedEventHandler; callback(taskInfo); } } else { if (childTaskCallback != null) { childTaskCallback(taskInfo); } } }; m_engine.GetTaskEngine(playerIndex).TaskStateChanged += taskStateChangedEventHandler; m_engine.Submit(playerIndex, new TaskCmd(SerializedTask.FromTaskInfo(task))); RunEngine(); Assert.Fail(); }
public void Submit(int playerIndex, Cmd cmd) { if (cmd.Code == CmdCode.ExecuteTask) { TaskCmd executeTaskCmd = (TaskCmd)cmd; TaskInfo task = SerializedTask.ToTaskInfo(executeTaskCmd.Task); task.PlayerIndex = playerIndex; m_taskEngines[playerIndex].SubmitTask(task); } else { if (playerIndex >= 0 && playerIndex < m_players.Length) { IMatchPlayerController player = m_players[playerIndex]; if (player != null) { player.Submit(cmd); } } } if (OnSubmitted != null) { OnSubmitted(playerIndex, cmd); } }
public void FindPathCloneTest() { TaskInfo task = TaskInfo.FindPath(new TaskInputInfo(), new TaskInputInfo()); Assert.DoesNotThrow(() => { SerializedTask.ToTaskInfo(m_protobufSerializer.DeepClone(SerializedTask.FromTaskInfo(task))); }); }
public void SearchForCloneTest() { TaskInfo task = TaskInfo.SearchFor(TaskType.SearchForFood, new TaskInputInfo()); Assert.DoesNotThrow(() => { SerializedTask.ToTaskInfo(m_protobufSerializer.DeepClone(SerializedTask.FromTaskInfo(task))); }); }
public void SearchMoveOrRandomMoveCloneTest() { TaskInfo task = TaskInfo.SearchMoveOrRandomMove(TaskType.SearchForFood, new TaskInputInfo()); Assert.DoesNotThrow(() => { byte[] b = m_protobufSerializer.Serialize(SerializedTask.FromTaskInfo(task)); SerializedTask.ToTaskInfo(m_protobufSerializer.Deserialize <SerializedTask>(b)); }); }
public void EatGrowSplitCloneTest() { TaskInfo task = TaskInfo.EatGrowSplit4(new TaskInputInfo(), new TaskInputInfo()); Assert.DoesNotThrow(() => { byte[] b = m_protobufSerializer.Serialize(SerializedTask.FromTaskInfo(task)); SerializedTask.ToTaskInfo(m_protobufSerializer.Deserialize <SerializedTask>(b)); }); }
public void SaveTaskTemplate(Guid clientId, Guid playerId, SerializedTask taskTemplate, SerializedNamedTaskLaunchInfo TaskTemplateData, ServerEventHandler callback) { RemoteCall rpc = new RemoteCall( RemoteCall.Proc.SaveTaskTemplate, clientId, RemoteArg.Create(playerId), RemoteArg.Create(taskTemplate), RemoteArg.Create(TaskTemplateData)); Call(rpc, (error, result) => callback(error)); }
public void ExpressionSerializationDeserialization() { ExpressionInfo expression = new ExpressionInfo(); expression.Code = ExpressionCode.And; expression.Children = new[] { new ExpressionInfo { Code = ExpressionCode.Eq, Children = new[] { new ExpressionInfo { Code = ExpressionCode.Value, Value = PrimitiveContract.Create(new Coordinate(1, 1, 1, 1)) }, new ExpressionInfo { Code = ExpressionCode.Value, Value = PrimitiveContract.Create(new Coordinate(1, 1, 1, 1)) }, } }, new ExpressionInfo { Code = ExpressionCode.Value, Value = PrimitiveContract.Create(true), } }; ExpressionInfo clone = null; Assert.DoesNotThrow(() => { TaskInfo task = new TaskInfo { Expression = expression }; clone = SerializedTask.ToTaskInfo(m_protobufSerializer.DeepClone(SerializedTask.FromTaskInfo(task))).Expression; }); Assert.IsNotNull(clone); Assert.AreEqual(expression.Code, clone.Code); Assert.IsNotNull(clone.Children); Assert.AreNotSame(expression.Children, clone.Children); Assert.AreEqual(expression.Children.Length, clone.Children.Length); Assert.IsNotNull(clone.Children[0].Children); Assert.AreEqual(expression.Children[0].Children.Length, clone.Children[0].Children.Length); Assert.AreEqual(expression.Children[0].Children[0].Code, clone.Children[0].Children[0].Code); Assert.AreEqual(expression.Children[0].Children[0].Value, clone.Children[0].Children[0].Value); Assert.AreEqual(expression.Children[1].Code, clone.Children[1].Code); Assert.AreEqual(expression.Children[1].Value, clone.Children[1].Value); }
public void TaskInfoSerializationDeserialization() { TaskInfo taskInfo = new TaskInfo(TaskType.Branch, TaskState.Active); taskInfo.TaskId = 1234; taskInfo.Expression = new ExpressionInfo(ExpressionCode.FoodVisible, new PrimitiveContract <bool>(true)); taskInfo.Children = new[] { new TaskInfo(new Cmd(CmdCode.RotateLeft), TaskState.Active, new ExpressionInfo(ExpressionCode.EnemyVisible, new PrimitiveContract <bool>(true)), taskInfo), new TaskInfo { TaskId = 1236, TaskType = TaskType.Command, Cmd = new MovementCmd(CmdCode.Move, 10, 10), Parent = taskInfo, State = TaskState.Idle } }; TaskInfo clone = null; Assert.DoesNotThrow(() => { clone = SerializedTask.ToTaskInfo(m_protobufSerializer.DeepClone(SerializedTask.FromTaskInfo(taskInfo))); }); Assert.IsNotNull(clone); Assert.AreEqual(taskInfo.TaskId, 1234); Assert.AreEqual(taskInfo.TaskId, clone.TaskId); Assert.AreEqual(taskInfo.TaskType, TaskType.Branch); Assert.AreEqual(taskInfo.TaskType, clone.TaskType); Assert.AreEqual(taskInfo.State, clone.State); Assert.AreEqual(taskInfo.Parent, clone.Parent); Assert.IsNotNull(clone.Expression); Assert.AreEqual(taskInfo.Expression.Code, clone.Expression.Code); Assert.IsNotNull(clone.Children); Assert.AreEqual(taskInfo.Children.Length, clone.Children.Length); Assert.AreSame(taskInfo.Children[0].Parent, taskInfo); Assert.AreSame(clone.Children[0].Parent, clone); Assert.IsNotNull(clone.Children[0].Expression); Assert.AreEqual(clone.Children[0].Expression.Code, ExpressionCode.EnemyVisible); Assert.AreEqual(taskInfo.Children[0].Expression.Code, clone.Children[0].Expression.Code); Assert.AreSame(taskInfo.Children[1].Parent, taskInfo); Assert.AreSame(clone.Children[1].Parent, clone); Assert.AreEqual(taskInfo.Children[1].TaskId, clone.Children[1].TaskId); Assert.IsNotNull(taskInfo.Children[1].Cmd); Assert.AreEqual(taskInfo.Children[1].Cmd.Code, clone.Children[1].Cmd.Code); Assert.AreEqual(taskInfo.Children[1].State, clone.Children[1].State); }
public void ExpreessionInfoCloneTest2() { ExpressionInfo canRun = ExpressionInfo.Eq( ExpressionInfo.PrimitiveVal(CmdResultCode.Success), ExpressionInfo.Val(new TaskInputInfo())); Assert.DoesNotThrow(() => { TaskInfo task = new TaskInfo { Expression = canRun }; byte[] b = m_protobufSerializer.Serialize(SerializedTask.FromTaskInfo(task)); SerializedTask.ToTaskInfo(m_protobufSerializer.Deserialize <SerializedTask>(b)); }); }
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)) )); }); }
public void SaveTaskTemplate(Guid clientId, Guid playerId, SerializedTask taskTemplate, SerializedNamedTaskLaunchInfo TaskTemplateData, ServerEventHandler callback) { Error error = new Error(StatusCode.OK); if (!m_initialized) { error.Code = StatusCode.NotAllowed; error.Message = "Match was not initialized"; } else { SerializedTask[] templates; if (!m_tasks.TryGetValue(playerId, out templates)) { templates = new SerializedTask[1]; } else { Array.Resize(ref templates, templates.Length + 1); } SerializedNamedTaskLaunchInfo[] templateInfos; if (!m_serializedTaskTemplates.TryGetValue(playerId, out templateInfos)) { templateInfos = new SerializedNamedTaskLaunchInfo[1]; } else { Array.Resize(ref templateInfos, templateInfos.Length + 1); } templates[templates.Length - 1] = taskTemplate; templateInfos[templateInfos.Length - 1] = TaskTemplateData; } if (m_lag == 0) { callback(error); } else { m_job.Submit(() => { Thread.Sleep(m_lag); return(null); }, result => { callback(error); }); } }
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))); }); }
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 FindPathClientSidePreprocessingTest() { BeginTest(TestEnv0, 4, 0, () => { MapRoot map = Dependencies.Map.Map; IMatchEngineCli matchEngineCli = Dependencies.MatchEngine; const int playerId = 3; Coordinate[] coords = map.FindDataOfType((int)KnownVoxelTypes.Eater, playerId); VoxelData data = map.Get(coords[0]); Coordinate targetCoordinate = coords[0].Add(-1, -1); MovementCmd moveCmd = new MovementCmd(CmdCode.Move, data.UnitOrAssetIndex, 0); moveCmd.Coordinates = new[] { coords[0], targetCoordinate }; MatchEngineCliEvent <long, CommandsBundle> eventHandler = null; eventHandler = (e, tick, commandsBundle) => { if (commandsBundle.TasksStateInfo != null) { TaskStateInfo taskStateInfo = commandsBundle.TasksStateInfo[0]; Assert.AreEqual(taskStateInfo.PlayerId, playerId); if (taskStateInfo.State == TaskState.Completed) { matchEngineCli.ExecuteCommands -= eventHandler; Coordinate[] newCoords = map.FindDataOfType((int)KnownVoxelTypes.Eater, playerId); Assert.AreEqual(targetCoordinate, newCoords[0]); EndTest(); } else { Assert.AreEqual(TaskState.Active, taskStateInfo.State); } } }; matchEngineCli.ExecuteCommands += eventHandler; TaskInfo taskInfo = new TaskInfo(moveCmd); taskInfo.RequiresClientSidePreprocessing = true; matchEngineCli.GetClientTaskEngine(playerId).GenerateIdentitifers(taskInfo); matchEngineCli.Submit(playerId, new TaskCmd(SerializedTask.FromTaskInfo(taskInfo))); }); yield return(Run()); }
public SerializedTask(CompoundTask t, SerializedTask p) { type = "Compound"; parent = p; name = t.name; methods = new List <SerializedMethod> (); foreach (Method m in t.methods) { methods.Add(new SerializedMethod(m, this)); } cost = 0; effects = null; preconditions = null; cuncurrentTasks = null; }
public void ProcedureRepeatBranchSearchCloneTest() { ExpressionInfo whileTrue = ExpressionInfo.PrimitiveVal(true); TaskInfo searchForTask = TaskInfo.SearchFor(TaskType.SearchForFood, new TaskInputInfo()); TaskInfo task = TaskInfo.Procedure( TaskInfo.Repeat( whileTrue, searchForTask, TaskInfo.Branch( whileTrue, new TaskInfo() ) ) ); Assert.DoesNotThrow(() => { SerializedTask.ToTaskInfo(m_protobufSerializer.DeepClone(SerializedTask.FromTaskInfo(task))); }); }
protected void SubmitCommand() { if (m_taskEngine.IsClient) { TaskInfo taskInfo = new TaskInfo(m_taskInfo, true); TaskCmd taskCmd = new TaskCmd(SerializedTask.FromTaskInfo(taskInfo)); taskCmd.UnitIndex = m_taskInfo.Cmd.UnitIndex; m_taskEngine.MatchEngine.Submit(m_taskInfo.PlayerIndex, taskCmd); } else { if (m_taskInfo.RequiresClientSidePreprocessing) { m_taskEngine.MatchEngine.Submit(m_taskInfo.PlayerIndex, m_taskInfo.PreprocessedCmd); } else { m_taskEngine.MatchEngine.Submit(m_taskInfo.PlayerIndex, m_taskInfo.Cmd); } } }
public void SaveTaskTemplate(Guid clientId, Guid playerId, SerializedTask taskTemplate, SerializedNamedTaskLaunchInfo templateInfo, ServerEventHandler callback) { throw new NotImplementedException(); }
public TaskCmd(SerializedTask task) { Code = CmdCode.ExecuteTask; Task = task; }