public static void TestBearingShouldMakeYouMoveToRightPosition() { Random rand; double x1, y1, x2, y2; rand = new Random(); x1 = rand.NextDouble(); y1 = rand.NextDouble(); x2 = rand.NextDouble(); y2 = rand.NextDouble(); Point2D orig = new Point2D(x1, y1); Point2D dest = new Point2D(x2, y2); double angle = orig.AbsoluteBearing(dest); MyRobot r = new MyRobot(orig, angle); double distance = orig.Norm(dest); r.MoveRobot(r.CalculateRobotNextPositionPolar(orig, angle, distance)); r.Position.X.Should().BeApproximately(x2, 0.001); r.Position.Y.Should().BeApproximately(y2, 0.001); }
private bool EvitarParedes() { if ((MyRobot.X >= MyRobot.BattleFieldWidth - (margin + MyRobot.Height))) { MyRobot.TurnRight(Utils.NormalRelativeAngleDegrees(-MyRobot.Heading - 90)); MyRobot.Ahead(dist - 20); return(true); } else if (MyRobot.Y >= MyRobot.BattleFieldHeight - (margin + MyRobot.Height)) { MyRobot.TurnRight(Utils.NormalRelativeAngleDegrees(-MyRobot.Heading - 180)); MyRobot.Ahead(dist - 20); return(true); } else if (MyRobot.Y <= (margin + MyRobot.Height)) { MyRobot.TurnRight(Utils.NormalRelativeAngleDegrees(-MyRobot.Heading)); MyRobot.Ahead(dist - 20); return(true); } else if (MyRobot.X <= (margin + MyRobot.Height)) { MyRobot.TurnRight(Utils.NormalRelativeAngleDegrees(-MyRobot.Heading + 90)); MyRobot.Ahead(dist - 20); return(true); } return(false); }
public static void Test_robot_should_follow_trajectory() { Random rand; double x, y; rand = new Random(); int numberWayPoints = rand.Next(5, 10); List <Point2D> WayPoints = new List <Point2D>(); for (int i = 0; i < numberWayPoints; i++) { x = rand.NextDouble() * 10000; y = rand.NextDouble() * 10000; Point2D wayPoint = new Point2D(x, y); WayPoints.Add(wayPoint); } MyRobot robot = new MyRobot(WayPoints[0], 0); List <Point2D> trajectory = robot.CalculateIntermediatePointsBetweenWayPoints(WayPoints, 1.55); robot.Trajectory = WayPoints; robot.Speed = 1; for (int i = 0; i < 100; i++) { robot.MoveRobot(new Point2D(robot.Position.X + 1, robot.Position.Y + 1)); } }
public static void Test_robot_acceleration_inferior_1g() { Random rand; double x, y; rand = new Random(); int numberWayPoints = rand.Next(5, 10); List <Point2D> WayPoints = new List <Point2D>(); for (int i = 0; i < numberWayPoints; i++) { x = rand.NextDouble() * 10000; y = rand.NextDouble() * 10000; Point2D wayPoint = new Point2D(x, y); WayPoints.Add(wayPoint); } MyRobot robot = new MyRobot(WayPoints[0], WayPoints[0].AbsoluteBearing(WayPoints[1])); List <Point2D> trajectory = robot.CalculateIntermediatePointsBetweenWayPoints(WayPoints, 1.55); robot.Trajectory = WayPoints; robot.Speed = 0; double lastSpeed = 0; for (int i = 0; i < 100; i++) { robot.MoveRobot(new Point2D(robot.Position.X + 100, robot.Position.Y)); (robot.Speed - lastSpeed).Should().BeLessThan(9.81); lastSpeed = robot.Speed; } }
public override void ActionMove() { MyRobot.IsAdjustGunForRobotTurn = true; MyRobot.IsAdjustRadarForGunTurn = true; MyRobot.IsAdjustRadarForRobotTurn = true; MyRobot.SetTurnRadarRight(double.PositiveInfinity); if (MyRobot.Heading % 90 > 0) { MyRobot.TurnRight(-MyRobot.Heading); } if (Utils.IsNear(MyRobot.HeadingRadians, 5D) || Utils.IsNear(MyRobot.HeadingRadians, Math.PI)) { MyRobot.Ahead((Math.Max(MyRobot.BattleFieldHeight - MyRobot.Y, MyRobot.Y) - margin) * dir); } else { MyRobot.Ahead((Math.Max(MyRobot.BattleFieldWidth - MyRobot.X, MyRobot.X) - margin) * dir); } MyRobot.TurnRight(90 * dir); //if (!EvitarParedes()) //{ // dir *= -1; // MyRobot.SetTurnRight(ang * dir); // MyRobot.SetAhead(dist); //} }
private void DoFire(Enemy e) { if (e.distance < 100 && MyRobot.Energy > 50) { MyRobot.SetFire(Rules.MAX_BULLET_POWER); } else if (e.distance < 200 && MyRobot.Energy > 50) { MyRobot.SetFire(2); } else { MyRobot.SetFire(1); } }
public override void ActionFire(Enemy e) { Random randonGen = new Random(); MyRobot.BodyColor = Color.FromArgb(randonGen.Next(255), randonGen.Next(255), randonGen.Next(255)); MyRobot.BulletColor = Color.FromArgb(randonGen.Next(255), randonGen.Next(255), randonGen.Next(255)); MyRobot.GunColor = Color.FromArgb(randonGen.Next(255), randonGen.Next(255), randonGen.Next(255)); MyRobot.RadarColor = Color.FromArgb(randonGen.Next(255), randonGen.Next(255), randonGen.Next(255)); MyRobot.ScanColor = Color.FromArgb(randonGen.Next(255), randonGen.Next(255), randonGen.Next(255)); MyRobot.IsAdjustGunForRobotTurn = true; if (NearTarget == null || (NearTarget.name != e.name && NearTarget.distance > e.distance) || (NearTarget.name == e.name)) { this.NearTarget = e; } else { return; } double absBearing = Utils.ToRadians(NearTarget.bearing) + MyRobot.HeadingRadians; double radarTurn = absBearing - MyRobot.RadarHeadingRadians; MyRobot.MaxVelocity = Rules.MAX_VELOCITY; MyRobot.SetTurnGunRightRadians(Utils.NormalRelativeAngle(absBearing - MyRobot.GunHeadingRadians)); Shots++; DoFire(NearTarget); //MyRobot.SetTurnRadarRightRadians(Utils.NormalRelativeAngle(radarTurn)*2); if (MyRobot.Others == 1) { MyRobot.SetTurnRadarRightRadians(Utils.NormalRelativeAngle(radarTurn) * 2); // make the radar lock on } else { MyRobot.SetTurnRadarRight(double.PositiveInfinity); } }
private void DoFire(Enemy e) { if (e.distance < 100 && MyRobot.Energy > 50) { MyRobot.SetFire(Rules.MAX_BULLET_POWER); shots++; } else if (e.distance < 200 && MyRobot.Energy > 50) { MyRobot.SetFire(2); shots++; } else if (shots % hits < 2 || e.distance < 200 || e.speed == 0) { MyRobot.SetFire(1); shots++; } }
public override void ActionFire(Enemy e) { Random randonGen = new Random(); MyRobot.BodyColor = Color.FromArgb(randonGen.Next(255), randonGen.Next(255), randonGen.Next(255)); MyRobot.BulletColor = Color.FromArgb(randonGen.Next(255), randonGen.Next(255), randonGen.Next(255)); MyRobot.GunColor = Color.FromArgb(randonGen.Next(255), randonGen.Next(255), randonGen.Next(255)); MyRobot.RadarColor = Color.FromArgb(randonGen.Next(255), randonGen.Next(255), randonGen.Next(255)); MyRobot.ScanColor = Color.FromArgb(randonGen.Next(255), randonGen.Next(255), randonGen.Next(255)); MyRobot.SetTurnGunRight(Utils.NormalRelativeAngleDegrees(MyRobot.Heading + e.bearing - MyRobot.GunHeading)); DoFire(e); }
public void TestFunctions() { MyRobot myRobot = new MyRobot(); myRobot.ProcessRequest("PlaCE 0,0,NOrtH"); myRobot.ProcessRequest(" MovE"); Assert.AreEqual(myRobot.ProcessReportReq(), "Output: 0,1,NORTH"); myRobot.ProcessRequest(" PLACE 0,0,NORTH"); myRobot.ProcessRequest("left "); Assert.AreEqual(myRobot.ProcessReportReq(), "Output: 0,0,WEST"); myRobot.ProcessRequest("PLACE 1,2,EAST "); myRobot.ProcessRequest("MOVE"); myRobot.ProcessRequest("MOVE"); myRobot.ProcessRequest("LEFT"); myRobot.ProcessRequest("MOVE"); Assert.AreEqual(myRobot.ProcessReportReq(), "Output: 3,3,NORTH"); }
public override void ActionMove() { MyRobot.IsAdjustGunForRobotTurn = true; MyRobot.IsAdjustRadarForGunTurn = true; MyRobot.IsAdjustRadarForRobotTurn = true; if (EvitarParedes()) { return; } if (Math.Abs(currentHeading - MyRobot.Heading) < 10 && Math.Abs(currentHeading - MyRobot.Heading) > 1) { dir = -dir; currentHeading = MyRobot.Heading; MyRobot.TurnRight(ang * dir); } MyRobot.SetTurnRight(ang * dir); MyRobot.SetAhead(desplazar); MyRobot.Execute(); }
/// <summary> /// Turns the robot 90 degrees to the right /// </summary> public void Right() => MyRobot.Right();
/// <summary> /// Turns the robot 90 degrees to the left /// </summary> public void Left() => MyRobot.Left();
/// <summary> /// Reports the robot's x,y co-ordinates and the direction it's facing /// </summary> public string Report() => MyRobot.Report();
public void TestExceptions5() { MyRobot myRobot = new MyRobot(); myRobot.ProcessRequest("PLACE 1 , 2 , EAST"); }
public void TestExceptions4() { MyRobot myRobot = new MyRobot(); myRobot.ProcessRequest("REPORT"); }
public void TestExceptions3() { MyRobot myRobot = new MyRobot(); myRobot.ProcessRequest("RIGHT"); }
public void TestExceptions2() { MyRobot myRobot = new MyRobot(); myRobot.ProcessRequest("LEFT"); }
public void TestExceptions1() { MyRobot myRobot = new MyRobot(); myRobot.ProcessRequest("MOVE"); }
public override void ActionHitByBullet(HitByBulletEvent ev) { MyRobot.TurnRadarRight(360); }
static void Main() { MyRobot myRobot = new MyRobot(); myRobot.ReadUserInput(); }
public override void ActionMoveRadar() { MyRobot.SetTurnRadarRight(360); }