void Start() { _robot_controller = GetComponent <RobotCarController>(); _robot_controller.Driver = new GoalieDriver(_robot_controller); _robot_controller.transform.rotation = Quaternion.Euler(0f, 90f, 0f); _robot_controller.IsGoalie = true; Ball = GameObject.Find("Soccer Ball"); Goal = (_robot_controller.Team.Team == TeamController.TEAM.RED) ? GameObject.Find("LeftRing") : GameObject.Find("RightRing"); Config = GameObject.Find("ConfigurationHolder").GetComponent <ConfigurationHolder>(); GoalieOutputYDistance yOutput = null; var category = new GoalieCategory(6); float goalOffset; switch (Config.c.NumberOfRobots) { case 3: _goalie_x_distance = new SmallGoalieXDistance(1); _goalie_y_distance = new SmallGoalieInputYDistance(2); _ball_x_distance = new SmallGoalieXDistance(3); _ball_y_distance = new SmallGoalieInputYDistance(4); yOutput = new SmallGoalieOutputYDistance(5); goalOffset = 15f; break; case 5: _goalie_x_distance = new MiddleGoalieXDistance(1); _goalie_y_distance = new MiddleGoalieInputYDistance(2); _ball_x_distance = new MiddleGoalieXDistance(3); _ball_y_distance = new MiddleGoalieInputYDistance(4); yOutput = new MiddleGoalieOutputYDistance(5); goalOffset = 20f; break; case 11: _goalie_x_distance = new LargeGoalieXDistance(1); _goalie_y_distance = new LargeGoalieInputYDistance(2); _ball_x_distance = new LargeGoalieXDistance(3); _ball_y_distance = new LargeGoalieInputYDistance(4); yOutput = new LargeGoalieOutputYDistance(5); goalOffset = 25f; break; default: goalOffset = 15f; break; } _strategizer = new GoalieStrategizer(_ball_x_distance, _goalie_x_distance, category); _strategy_1 = new GoalieStrategy(1, _ball_y_distance, _goalie_y_distance, yOutput); _strategy_2 = new GoalieStrategy(2, _ball_y_distance, _goalie_y_distance, yOutput); _strategy_3 = new GoalieStrategy(3, _ball_y_distance, _goalie_y_distance, yOutput); _strategy_4 = new GoalieStrategy(4, _ball_y_distance, _goalie_y_distance, yOutput); float goalX = Goal.transform.position.z; FixedX = goalX < 0 ? goalX + goalOffset : goalX - goalOffset; }
// Update is called once per frame void FixedUpdate() { NearestBlue = BlueTeam.GetClosestFromBall(); NearestRed = RedTeam.GetClosestFromBall(); var blueState = GetStateBlue(); var redState = GetStateRed(); RedTeam.UpdateStrategy((redState > blueState) ? TeamController.STRATEGY.OFFENSE : TeamController.STRATEGY.DEFENSE, NearestRed); BlueTeam.UpdateStrategy((blueState > redState) ? TeamController.STRATEGY.OFFENSE : TeamController.STRATEGY.DEFENSE, NearestBlue); //Debug.Log("Blue : " + blueState + " |||| Red : " + redState); }
public void UpdateStrategy(STRATEGY strategy, RobotCarController nearestRobot) { Strategy = strategy; if (Strategy == STRATEGY.OFFENSE) { ArbiterController.ArbiterRobot = nearestRobot; switch (NoOfRobots) { case 3: if (nearestRobot != Defenders[0]) { Defenders[0].GetComponent <RobotCarController>().DestY = (Team == TEAM.BLUE) ? League.Small.Offense.OffensiveWait : League.Small.Offense.OffensiveWait * -1; Defenders[0].GetComponent <RobotCarController>().DestX = 0; } else { Forward[0].GetComponent <RobotCarController>().DestY = (Team == TEAM.BLUE) ? League.Small.Offense.OffensiveWait : League.Small.Offense.OffensiveWait * -1; Forward[0].GetComponent <RobotCarController>().DestX = 0; } break; case 5: break; case 11: break; } } else { switch (NoOfRobots) { case 3: Defenders[0].GetComponent <RobotCarController>().DestY = (Team == TEAM.BLUE) ? League.Small.Defense.DefenderLineAction : League.Small.Defense.DefenderLineAction * -1; Defenders[0].GetComponent <RobotCarController>().DestX = Ball.transform.position.x; Forward[0].GetComponent <RobotCarController>().DestX = Ball.transform.position.x; Forward[0].GetComponent <RobotCarController>().DestY = Ball.transform.position.z; break; case 5: break; case 11: break; } } }
public Driver(RobotCarController robot) { Robot = robot; RightFls = new RightWheelFLS(); LeftFls = new LeftWheelFLS(); }
public GoalieDriver(RobotCarController robot) { Robot = robot; RightFls = new GoalieRightWheelFLS(); LeftFls = new GoalieLeftWheelFLS(); }