public void setup(string robotModel) { foreach (Type t in this.GetType().Assembly.GetTypes()) { if (t.IsSubclassOf(typeof(Robot))) { functionComboBox.Items.Add(t.Name); } } robot = RobotModelFactory.getRobotModel(robotModel); if (robot != null) { for (int j = 0; j < functionComboBox.Items.Count; j++) { if (functionComboBox.Items[j].ToString().Equals(robot.Name)) { functionComboBox.SelectedIndex = j; break; } } } }
private void functionComboBox_SelectedIndexChanged(object sender, EventArgs e) { robot = RobotModelFactory.getRobotModel(functionComboBox.SelectedItem.ToString()); Invalidate(); }
/// <summary> /// Initializes robot brains and positions them in the CurrentEnvironment. /// </summary> public override void initializeRobots(AgentBrain agentBrain, Environment e, float headingNoise, float sensorNoise, float effectorNoise, instance_pack ip) { double spacing = 0; int num_bots; double dx, dy; // Deltas for spacing the robots if (overrideTeamFormation) { dx = Math.Cos(group_orientation / 180.0 * 3.14) * group_spacing; dy = Math.Sin(group_orientation / 180.0 * 3.14) * group_spacing; spacing = group_spacing; } else { dx = Math.Cos(e.group_orientation / 180.0 * 3.14) * e.robot_spacing; dy = Math.Sin(e.group_orientation / 180.0 * 3.14) * e.robot_spacing; spacing = e.robot_spacing; } AgentBrain ab; List <Robot> rbts; double _timestep = 0.0; if (ip == null) { ab = agentBrain; rbts = robots; num_bots = numberRobots; _timestep = this.timestep; } else { ab = ip.agentBrain; rbts = new List <Robot>(); ip.robots = rbts; num_bots = ip.num_rbts; _timestep = ip.timestep; } rbts.Clear(); bool circle = false; bool staggered = true; double radius = (spacing) / (2.0 * Math.PI * (1.0 / num_bots)); double angleDelta = (2 * Math.PI) / num_bots; // Add robots in their formation according to CurrentEnvironment double nx, ny; for (int num = 0; num < num_bots; num++) { double heading = overrideTeamFormation ? robot_heading : e.robot_heading; Robot r; if (robotValues != null && robotValues.Count > 0 && robotValues.Count >= num) { r = RobotModelFactory.getRobotModel(robotValues[num]); } else { r = RobotModelFactory.getRobotModel(robotModelName); } if (circle) { nx = e.start_point.X + radius * Math.Cos(num * angleDelta); ny = e.start_point.Y + radius * Math.Sin(num * angleDelta); heading = num * angleDelta - Math.PI; } else { if (staggered && num % 2 == 1 && e.stagger != 0) { nx = e.start_point.X + num * dx + (staggered ? e.stagger * num : 0); } else { nx = e.start_point.X + num * dx - (staggered ? e.stagger * num : 0); } ny = e.start_point.Y + num * dy; heading = (heading / 180.0) * 3.14; } r.init(num, nx, ny, heading, ab, e, sensorNoise, effectorNoise, headingNoise, (float)_timestep); r.CollisionPenalty = collisionPenalty; ab.registerRobot(r); if (overrideDefaultSensorDensity) { r.populateSensors(sensorDensity); } else { r.populateSensors(); } if (agentBrain.ZCoordinates == null) { r.ZStack = 0; } else { r.ZStack = ab.ZCoordinates[num]; } rbts.Add(r); } ab.updateInputDensity(); }