public bool ResolveAction(AGENT_ACTIONS action) { MyMovingObject agent = w.GetAgent(); Tale[,] tales = w.GetTales(); bool navigation = this.ResolveNavigation(agent, tales, action); navigation |= this.ResolveCustomActions(agent, tales, action); return(navigation); }
protected bool ResolveNavigation( MyMovingObject agent, Tale[,] tales, AGENT_ACTIONS action) { int2 pos = agent.GetPosition(); if (action == AGENT_ACTIONS.UP && pos.y < w.GetHeight() - 1) { if (CanMakeStepTo(pos.x, pos.y + 1, tales, agent.GetWeight())) { agent.MoveUp(); return(true); } } else if (action == AGENT_ACTIONS.DOWN && agent.GetPosition().y > 0) { if (CanMakeStepTo(pos.x, pos.y - 1, tales, agent.GetWeight())) { agent.MoveDown(); return(true); } } else if (action == AGENT_ACTIONS.LEFT && agent.GetPosition().x > 0) { if (CanMakeStepTo(pos.x - 1, pos.y, tales, agent.GetWeight())) { agent.MoveLeft(); return(true); } } else if (action == AGENT_ACTIONS.RIGHT && agent.GetPosition().x < w.GetWidth() - 1) { if (CanMakeStepTo(pos.x + 1, pos.y, tales, agent.GetWeight())) { agent.MoveRight(); return(true); } } return(false); }
public static bool IsNavigationAction(AGENT_ACTIONS action) { return action == AGENT_ACTIONS.LEFT || action == AGENT_ACTIONS.RIGHT || action == AGENT_ACTIONS.UP || action == AGENT_ACTIONS.DOWN; }
protected bool ResolveNavigation( MyMovingObject agent, Tale[,] tales, AGENT_ACTIONS action) { int2 pos = agent.GetPosition(); if (action == AGENT_ACTIONS.UP && pos.y < w.GetHeight() - 1) { if (CanMakeStepTo(pos.x, pos.y + 1, tales, agent.GetWeight())) { agent.MoveUp(); return true; } } else if (action == AGENT_ACTIONS.DOWN && agent.GetPosition().y > 0) { if (CanMakeStepTo(pos.x, pos.y - 1, tales, agent.GetWeight())) { agent.MoveDown(); return true; } } else if (action == AGENT_ACTIONS.LEFT && agent.GetPosition().x > 0) { if (CanMakeStepTo(pos.x - 1, pos.y, tales, agent.GetWeight())) { agent.MoveLeft(); return true; } } else if (action == AGENT_ACTIONS.RIGHT && agent.GetPosition().x < w.GetWidth() - 1) { if (CanMakeStepTo(pos.x + 1, pos.y, tales, agent.GetWeight())) { agent.MoveRight(); return true; } } return false; }
protected bool ResolveCustomActions(MyMovingObject agent, Tale[,] tales, AGENT_ACTIONS action) { bool result = false; Tale t; if (action == AGENT_ACTIONS.BASIC) { t = tales[agent.GetPosition().x, agent.GetPosition().y]; for (int i = 0; i < t.Objects.Count; i++) { if (t.Objects[i] is TwoStateObjectControl) { if (t.Objects[i] is DoorControl) { if (!pars.ForceDoorSwitches) { ((DoorControl)t.Objects[i]).applyPressAction(); result = true; } } else if (t.Objects[i] is LightsControl) { if (!pars.ForceLightSwitches) { ((LightsControl)t.Objects[i]).applyPressAction(); result = true; } } else { ((TwoStateObjectControl)t.Objects[i]).applyPressAction(); result = true; } } } } if (pars.ForceDoorSwitches || pars.ForceLightSwitches) { for (int i = 0; i < tales.GetLength(0); i++) { for (int j = 0; j < tales.GetLength(1); j++) { t = tales[i, j]; if (t.Objects != null) { for (int k = 0; k < t.Objects.Count; k++) { if (t.Objects[k] is DoorControl && pars.ForceDoorSwitches) { DoorControl dc = (DoorControl)t.Objects[k]; if (dc.IsOn() != pars.ForceDoorSwitchesState) { dc.applyPressAction(); } } else if (t.Objects[k] is LightsControl && pars.ForceLightSwitches) { LightsControl lc = (LightsControl)t.Objects[k]; if (lc.IsOn() != pars.ForceLightSwitchesState) { lc.applyPressAction(); } } } } } } } return result; }
public bool ResolveAction(AGENT_ACTIONS action) { MyMovingObject agent = w.GetAgent(); Tale[,] tales = w.GetTales(); bool navigation = this.ResolveNavigation(agent, tales, action); navigation |= this.ResolveCustomActions(agent, tales, action); return navigation; }
protected bool ResolveCustomActions(MyMovingObject agent, Tale[,] tales, AGENT_ACTIONS action) { bool result = false; Tale t; if (action == AGENT_ACTIONS.BASIC) { t = tales[agent.GetPosition().x, agent.GetPosition().y]; for (int i = 0; i < t.Objects.Count; i++) { if (t.Objects[i] is TwoStateObjectControl) { if (t.Objects[i] is DoorControl) { if (!pars.ForceDoorSwitches) { ((DoorControl)t.Objects[i]).applyPressAction(); result = true; } } else if (t.Objects[i] is LightsControl) { if (!pars.ForceLightSwitches) { ((LightsControl)t.Objects[i]).applyPressAction(); result = true; } } else { ((TwoStateObjectControl)t.Objects[i]).applyPressAction(); result = true; } } } } if (pars.ForceDoorSwitches || pars.ForceLightSwitches) { for (int i = 0; i < tales.GetLength(0); i++) { for (int j = 0; j < tales.GetLength(1); j++) { t = tales[i, j]; if (t.Objects != null) { for (int k = 0; k < t.Objects.Count; k++) { if (t.Objects[k] is DoorControl && pars.ForceDoorSwitches) { DoorControl dc = (DoorControl)t.Objects[k]; if (dc.IsOn() != pars.ForceDoorSwitchesState) { dc.applyPressAction(); } } else if (t.Objects[k] is LightsControl && pars.ForceLightSwitches) { LightsControl lc = (LightsControl)t.Objects[k]; if (lc.IsOn() != pars.ForceLightSwitchesState) { lc.applyPressAction(); } } } } } } } return(result); }
public static bool IsNavigationAction(AGENT_ACTIONS action) { return(action == AGENT_ACTIONS.LEFT || action == AGENT_ACTIONS.RIGHT || action == AGENT_ACTIONS.UP || action == AGENT_ACTIONS.DOWN); }