Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added comments and cleanup of tests

  • Loading branch information...
commit b805e6802e5419567d4d83026a4a102e5e3d25ac 1 parent eb29da5
Jeremy Fabre authored
Showing with 439 additions and 25 deletions.
  1. +439 −5 MonSuperRobot/Base/TestableRobot.cs
  2. +0 −20 MonSuperRobotTest/GivenMadMax.cs
444 MonSuperRobot/Base/TestableRobot.cs
View
@@ -26,11 +26,17 @@ public TestableRobot(ITestableRobot robot)
_testableRobot = robot;
}
+ /// <summary>
+ /// Setup the first moves of the robot before it starts doing things
+ /// </summary>
public virtual void Init()
{
}
+ /// <summary>
+ /// This method is called infinitely, it is where you will do your things
+ /// </summary>
public abstract void DoRobotThings();
public void Run()
{
@@ -278,6 +284,53 @@ public virtual void TurnLeft(double degree)
_myRobot.TurnLeft(degree);
}
}
+
+
+ /// <summary>
+ /// Immediately fires a bullet. The bullet will travel in the direction the
+ /// gun is pointing.
+ /// <p />
+ /// The specified bullet power is an amount of energy that will be taken from
+ /// the robot's energy. Hence, the more power you want to spend on the
+ /// bullet, the more energy is taken from your robot.
+ /// <p />
+ /// The bullet will do (4 * power) damage if it hits another robot. If power
+ /// is greater than 1, it will do an additional 2 * (power - 1) damage.
+ /// You will get (3 * power) back if you hit the other robot. You can call
+ /// <see cref="Rules.GetBulletDamage(double)" />
+ /// for getting the damage that a
+ /// bullet with a specific bullet power will do.
+ /// <p />
+ /// The specified bullet power should be between <see cref="Rules.MIN_BULLET_POWER" />
+ /// and <see cref="Rules.MAX_BULLET_POWER" />.
+ /// <p />
+ /// Note that the gun cannot Fire if the gun is overheated, meaning that
+ /// <see cref="GunHeat" />
+ /// returns a value &gt; 0.
+ /// <p />
+ /// A event is generated when the bullet hits a robot (<see cref="BulletHitEvent" />),
+ /// wall (<see cref="BulletMissedEvent" />), or another bullet
+ /// (<see cref="BulletHitBulletEvent" />).
+ /// <p />
+ /// <example>
+ /// <code>
+ /// // Fire a bullet with maximum power if the gun is ready
+ /// if (GetGunHeat() == 0)
+ /// {
+ /// Fire(Rules.MAX_BULLET_POWER);
+ /// }
+ /// </code>
+ /// </example>
+ /// <seealso cref="FireBullet(double)" />
+ /// <seealso cref="GunHeat" />
+ /// <seealso cref="GunCoolingRate" />
+ /// <seealso cref="OnBulletHit(BulletHitEvent)" />
+ /// <seealso cref="OnBulletHitBullet(BulletHitBulletEvent)" />
+ /// <seealso cref="OnBulletMissed(BulletMissedEvent)" />
+ /// </summary>
+ /// <param name="power">
+ /// The amount of energy given to the bullet, and subtracted from the robot's energy.
+ /// </param>
public virtual void Fire(double power)
{
if (_onTest)
@@ -289,6 +342,64 @@ public virtual void Fire(double power)
_myRobot.Fire(power);
}
}
+
+ ///
+ ///<summary>
+ /// Immediately fires a bullet. The bullet will travel in the direction the
+ /// gun is pointing.
+ /// <p />
+ /// The specified bullet power is an amount of energy that will be taken from
+ /// the robot's energy. Hence, the more power you want to spend on the
+ /// bullet, the more energy is taken from your robot.
+ /// <p />
+ /// The bullet will do (4 * power) damage if it hits another robot. If power
+ /// is greater than 1, it will do an additional 2 * (power - 1) damage.
+ /// You will get (3 * power) back if you hit the other robot. You can call
+ /// <see cref="Rules.GetBulletDamage(double)" />
+ /// for getting the damage that a
+ /// bullet with a specific bullet power will do.
+ /// <p />
+ /// The specified bullet power should be between <see cref="Rules.MIN_BULLET_POWER" />
+ /// and <see cref="Rules.MAX_BULLET_POWER" />.
+ /// <p />
+ /// Note that the gun cannot Fire if the gun is overheated, meaning that
+ /// <see cref="GunHeat" /> returns a value &gt; 0.
+ /// <p />
+ /// A event is generated when the bullet hits a robot (<see cref="BulletHitEvent" />),
+ /// wall (<see cref="BulletMissedEvent" />), or another bullet
+ /// (<see cref="BulletHitBulletEvent" />).
+ /// <p />
+ /// <example>
+ /// <code>
+ /// // Fire a bullet with maximum power if the gun is ready
+ /// if (GetGunHeat() == 0)
+ /// {
+ /// Bullet bullet = FireBullet(Rules.MAX_BULLET_POWER);
+ ///
+ /// // Get the velocity of the bullet
+ /// if (bullet != null)
+ /// {
+ /// double bulletVelocity = bullet.Velocity;
+ /// }
+ /// }
+ /// </code>
+ /// </example>
+ /// Returns a
+ /// <see cref="Bullet" />
+ /// That contains information about the bullet if it was actually fired,
+ /// which can be used for tracking the bullet after it has been fired.
+ /// If the bullet was not fired, null is returned.
+ /// <seealso cref="Fire(double)" />
+ /// <seealso cref="Bullet" />
+ /// <seealso cref="GunHeat" />
+ /// <seealso cref="GunCoolingRate" />
+ /// <seealso cref="OnBulletHit(BulletHitEvent)" />
+ /// <seealso cref="OnBulletHitBullet(BulletHitBulletEvent)" />
+ /// <seealso cref="OnBulletMissed(BulletMissedEvent)" />
+ ///</summary>
+ ///<param name="power">
+ /// power the amount of energy given to the bullet, and subtracted from the robot's energy.
+ ///</param>
public virtual void FireBullet(double power)
{
if (_onTest)
@@ -300,7 +411,35 @@ public virtual void FireBullet(double power)
_myRobot.FireBullet(power);
}
}
-
+
+ ///
+ ///<summary>
+ /// Scans for other robots. This method is called automatically by the game,
+ /// as long as the robot is moving, turning its body, turning its gun, or
+ /// turning its radar.
+ /// <p />
+ /// Scan will cause <see cref="OnScannedRobot(ScannedRobotEvent)" />
+ /// to be called if you see a robot.
+ /// <p />
+ /// There are 2 reasons to call <see cref="Scan()" /> manually:
+ /// <ol>
+ /// <li>
+ /// You want to scan after you stop moving.
+ /// </li>
+ /// <li>
+ /// You want to interrupt the <see cref="OnScannedRobot(ScannedRobotEvent)" />
+ /// event. This is more likely. If you are in
+ /// <see cref="OnScannedRobot(ScannedRobotEvent)" /> and call
+ /// <see cref="Scan()" />, and you still see a robot, then the system will interrupt your
+ /// <see cref="OnScannedRobot(ScannedRobotEvent)" /> event immediately and start it
+ /// from the top.
+ /// </li>
+ /// </ol>
+ /// <p />
+ /// This call executes immediately.
+ /// <seealso cref="OnScannedRobot(ScannedRobotEvent)" />
+ /// <seealso cref="ScannedRobotEvent" />
+ ///</summary>
public virtual void Scan()
{
if (_onTest)
@@ -312,6 +451,38 @@ public virtual void Scan()
_myRobot.Scan();
}
}
+
+ /// <summary>
+ /// Sets all the robot's color to the same color in the same time, i.e. the
+ /// color of the body, gun, radar, bullet, and scan arc.
+ /// <p />
+ /// You may only call this method one time per battle. A <em>null</em>
+ /// indicates the default (blue) color for the body, gun, radar, and scan
+ /// arc, but white for the bullet color.
+ /// <p />
+ /// <example>
+ /// <code>
+ /// // Don't forget to using System.Drawing at the top...
+ /// using System.Drawing;
+ /// ...
+ ///
+ /// public void Run()
+ /// {
+ /// SetAllColors(Color.Red);
+ /// ...
+ /// }
+ /// </code>
+ /// </example>
+ /// <seealso cref="SetColors(Color, Color, Color)" />
+ /// <seealso cref="SetColors(Color, Color, Color, Color, Color)" />
+ /// <seealso cref="BodyColor" />
+ /// <seealso cref="GunColor" />
+ /// <seealso cref="RadarColor" />
+ /// <seealso cref="BulletColor" />
+ /// <seealso cref="ScanColor" />
+ /// <seealso cref="Color" />
+ /// </summary>
+ /// <param name="color">The new color for all the colors of the robot</param>
public virtual void SetAllColors(Color color)
{
if (_onTest)
@@ -324,22 +495,22 @@ public virtual void SetAllColors(Color color)
}
}
- public IRunnable GetRobotRunnable()
+ IRunnable IRunnable.GetRobotRunnable()
{
return this;
}
- public IBasicEvents GetBasicEventListener()
+ IBasicEvents IBasicRobot.GetBasicEventListener()
{
return this;
}
- public void SetPeer(IBasicRobotPeer peer)
+ void IBasicRobot.SetPeer(IBasicRobotPeer peer)
{
((IBasicRobot) _myRobot).SetPeer(peer);
}
- public void SetOut(TextWriter output)
+ void IBasicRobot.SetOut(TextWriter output)
{
((IBasicRobot)_myRobot).SetOut(output);
}
@@ -534,6 +705,39 @@ public virtual void TurnRadarLeft(double degrees)
}
}
+ ///
+ ///<summary>
+ /// Immediately turns the robot's gun to the right by degrees.
+ /// This call executes immediately, and does not return until it is complete,
+ /// i.e. when the angle remaining in the gun's turn is 0.
+ /// <p />
+ /// Note that both positive and negative values can be given as input,
+ /// where negative values means that the robot's gun is set to turn left
+ /// instead of right.
+ /// <p />
+ /// <example>
+ /// <code>
+ /// // Turn the robot's gun 180 degrees to the right
+ /// TurnGunRight(180);
+ ///
+ /// // Afterwards, turn the robot's gun 90 degrees to the left
+ /// TurnGunRight(-90);
+ /// </code>
+ /// </example>
+ ///
+ /// <seealso cref="TurnGunLeft(double)" />
+ /// <seealso cref="TurnLeft(double)" />
+ /// <seealso cref="TurnRight(double)" />
+ /// <seealso cref="TurnRadarLeft(double)" />
+ /// <seealso cref="TurnRadarRight(double)" />
+ /// <seealso cref="IsAdjustGunForRobotTurn" />
+ ///</summary>
+ ///<param name="degrees">
+ /// The amount of degrees to turn the robot's gun to the right.
+ /// If degrees &gt; 0 the robot's gun will turn right.
+ /// If degrees &lt; 0 the robot's gun will turn left.
+ /// If degrees = 0 the robot's gun will not turn, but execute.
+ ///</param>
public virtual void TurnGunRight(double degrees)
{
if (_onTest)
@@ -546,6 +750,40 @@ public virtual void TurnGunRight(double degrees)
}
}
+ ///
+ ///<summary>
+ /// Immediately turns the robot's gun to the left by degrees.
+ /// <p />
+ /// This call executes immediately, and does not return until it is complete,
+ /// i.e. when the angle remaining in the gun's turn is 0.
+ /// <p />
+ /// Note that both positive and negative values can be given as input,
+ /// where negative values means that the robot's gun is set to turn right
+ /// instead of left.
+ /// <p />
+ /// <example>
+ /// <code>
+ /// // Turn the robot's gun 180 degrees to the left
+ /// TurnGunLeft(180);
+ ///
+ /// // Afterwards, turn the robot's gun 90 degrees to the right
+ /// TurnGunLeft(-90);
+ /// </code>
+ /// </example>
+ ///
+ /// <seealso cref="TurnGunRight(double)" />
+ /// <seealso cref="TurnLeft(double)" />
+ /// <seealso cref="TurnRight(double)" />
+ /// <seealso cref="TurnRadarLeft(double)" />
+ /// <seealso cref="TurnRadarRight(double)" />
+ /// <seealso cref="IsAdjustGunForRobotTurn" />
+ ///</summary>
+ ///<param name="degrees">
+ /// The amount of degrees to turn the robot's gun to the left.
+ /// If degrees &gt; 0 the robot's gun will turn left.
+ /// If degrees &lt; 0 the robot's gun will turn right.
+ /// If degrees = 0 the robot's gun will not turn, but execute.
+ ///</param>
public virtual void TurnGunLeft(double degrees)
{
if (_onTest)
@@ -558,6 +796,15 @@ public virtual void TurnGunLeft(double degrees)
}
}
+ ///
+ ///<summary>
+ /// Immediately stops all movement, and saves it for a call to <see cref="Resume()" />.
+ /// If there is already movement saved from a previous stop, this will have no effect.
+ /// <p />
+ /// This method is equivalent to <see cref="Stop(bool)">Stop(false)</see>.
+ /// <seealso cref="Resume()" />
+ /// <seealso cref="Stop(bool)" />
+ ///</summary>
public virtual void Stop()
{
if (_onTest)
@@ -651,6 +898,17 @@ public virtual double Energy
return _onTest ? _testableRobot.Energy : _myRobot.Energy;
}
}
+
+ /// <summary>
+ /// Returns the rate at which the gun will cool down, i.e. the amount of heat
+ /// the gun heat will drop per turn.
+ /// <p />
+ /// The gun cooling rate is default 0.1 / turn, but can be changed by the
+ /// battle setup. So don't count on the cooling rate being 0.1!
+ /// <seealso cref="GunHeat" />
+ /// <seealso cref="Fire(double)" />
+ /// <seealso cref="FireBullet(double)" />
+ /// </summary>
public virtual double GunCoolingRate
{
get
@@ -659,6 +917,15 @@ public virtual double GunCoolingRate
}
}
+ /// <summary>
+ /// Returns the direction that the robot's gun is facing, in degrees.
+ /// The value returned will be between 0 and 360 (is excluded).
+ /// <p />
+ /// Note that the heading in Robocode is like a compass, where 0 means North,
+ /// 90 means East, 180 means South, and 270 means West.
+ /// <seealso cref="Heading" />
+ /// <seealso cref="RadarHeading" />
+ /// </summary>
public virtual double GunHeading
{
get
@@ -667,6 +934,20 @@ public virtual double GunHeading
}
}
+ /// <summary>
+ /// Returns the current heat of the gun. The gun cannot Fire unless this is
+ /// 0. (Calls to Fire will succeed, but will not actually Fire unless
+ /// GetGunHeat() == 0).
+ /// <p />
+ /// The amount of gun heat generated when the gun is fired is 1 + (firePower / 5).
+ /// Each turn the gun heat drops by the amount returned by <see cref="GunCoolingRate" />,
+ /// which is a battle setup.
+ /// <p />
+ /// Note that all guns are "hot" at the start of each round, where the gun heat is 3.
+ /// <seealso cref="GunCoolingRate" />
+ /// <seealso cref="Fire(double)" />
+ /// <seealso cref="FireBullet(double)" />
+ /// </summary>
public virtual double GunHeat
{
get
@@ -675,6 +956,15 @@ public virtual double GunHeat
}
}
+ /// <summary>
+ /// Returns the direction that the robot's body is facing, in degrees.
+ /// The value returned will be between 0 and 360 (is excluded).
+ /// <p />
+ /// Note that the heading in Robocode is like a compass, where 0 means North,
+ /// 90 means East, 180 means South, and 270 means West.
+ /// <seealso cref="GunHeading" />
+ /// <seealso cref="RadarHeading" />
+ /// </summary>
public virtual double Heading
{
get
@@ -690,6 +980,11 @@ public string Name
return _onTest ? _testableRobot.Name : _myRobot.Name;
}
}
+
+ /// <summary>
+ /// Returns the number of rounds in the current battle.
+ /// <seealso cref="RoundNum" />
+ /// </summary>
public int NumRounds
{
get
@@ -697,8 +992,14 @@ public int NumRounds
return _onTest ? _testableRobot.NumRounds : _myRobot.NumRounds;
}
}
+
+
+ /// <summary>
+ /// Returns how many opponents that are left in the current round.
+ /// </summary>
public int Others { get { return _onTest ? _testableRobot.Others : _myRobot.Others; } }
+
public Color RadarColor
{
get
@@ -720,6 +1021,47 @@ public Color RadarColor
public double Height { get { return _onTest ? _testableRobot.Height : _myRobot.Height; } }
+
+ /// <summary>
+ /// Sets the gun to turn independent from the robot's turn.
+ /// <p />
+ /// Ok, so this needs some explanation: The gun is mounted on the robot's
+ /// body. So, normally, if the robot turns 90 degrees to the right, then the
+ /// gun will turn with it as it is mounted on top of the robot's body. To
+ /// compensate for this, you can call
+ /// <see cref="IsAdjustGunForRobotTurn" />.
+ /// When this is set, the gun will turn independent from the robot's turn,
+ /// i.e. the gun will compensate for the robot's body turn.
+ /// <p />
+ /// Note: This method is additive until you reach the maximum the gun can
+ /// turn. The "adjust" is added to the amount you set for turning the robot,
+ /// then capped by the physics of the game. If you turn infinite, then the
+ /// adjust is ignored (and hence overridden).
+ /// <p />
+ /// <example>
+ /// Assuming both the robot and gun start Out facing up (0 degrees):
+ /// <code>
+ /// // Set gun to turn with the robot's turn
+ /// setAdjustGunForRobotTurn(false); // This is the default
+ /// TurnRight(90);
+ /// // At this point, both the robot and gun are facing right (90 degrees)
+ /// TurnLeft(90);
+ /// // Both are back to 0 degrees
+ /// </code>
+ /// -- or --
+ /// <code>
+ /// // Set gun to turn independent from the robot's turn
+ /// setAdjustGunForRobotTurn(true);
+ /// TurnRight(90);
+ /// // At this point, the robot is facing right (90 degrees), but the gun is still facing up.
+ /// TurnLeft(90);
+ /// // Both are back to 0 degrees.
+ /// </code>
+ /// </example>
+ /// <p />
+ /// Note: The gun compensating this way does count as "turning the gun".
+ /// <seealso cref="IsAdjustRadarForGunTurn" />
+ /// </summary>
public bool IsAdjustGunForRobotTurn
{
get
@@ -739,6 +1081,44 @@ public bool IsAdjustGunForRobotTurn
}
}
+ /// <summary>
+ /// Sets the radar to turn independent from the gun's turn.
+ /// <p />
+ /// Ok, so this needs some explanation: The radar is mounted on the robot's
+ /// gun. So, normally, if the gun turns 90 degrees to the right, then the
+ /// radar will turn with it as it is mounted on top of the gun. To compensate
+ /// for this, you can call <see cref="IsAdjustRadarForGunTurn" /> = (true).
+ /// When this is set, the radar will turn independent from the robot's turn,
+ /// i.e. the radar will compensate for the gun's turn.
+ /// <p />
+ /// Note: This method is additive until you reach the maximum the radar can
+ /// turn. The "adjust" is added to the amount you set for turning the gun,
+ /// then capped by the physics of the game. If you turn infinite, then the
+ /// adjust is ignored (and hence overridden).
+ /// <p />
+ /// <example>
+ /// Assuming both the gun and radar start Out facing up (0 degrees):
+ /// <code>
+ /// // Set radar to turn with the gun's turn
+ /// SetAdjustRadarForGunTurn(false); // This is the default
+ /// TurnGunRight(90);
+ /// // At this point, both the radar and gun are facing right (90 degrees);
+ /// </code>
+ /// -- or --
+ /// <code>
+ /// // Set radar to turn independent from the gun's turn
+ /// SetAdjustRadarForGunTurn(true);
+ /// TurnGunRight(90);
+ /// // At this point, the gun is facing right (90 degrees), but the radar is still facing up.
+ /// </code>
+ /// </example>
+ /// Note: Calling <see cref="IsAdjustRadarForGunTurn" /> will automatically call
+ /// <see cref="IsAdjustRadarForRobotTurn" /> with the same value, unless you have
+ /// already called it earlier. This behavior is primarily for backward compatibility
+ /// with older Robocode robots.
+ /// <seealso cref="IsAdjustRadarForRobotTurn" />
+ /// <seealso cref="IsAdjustGunForRobotTurn" />
+ /// </summary>
public bool IsAdjustRadarForGunTurn
{
get
@@ -758,6 +1138,43 @@ public bool IsAdjustRadarForGunTurn
}
}
+ /// <summary>
+ /// Sets the radar to turn independent from the robot's turn.
+ /// <p />
+ /// Ok, so this needs some explanation: The radar is mounted on the gun, and
+ /// the gun is mounted on the robot's body. So, normally, if the robot turns
+ /// 90 degrees to the right, the gun turns, as does the radar. Hence, if the
+ /// robot turns 90 degrees to the right, then the gun and radar will turn
+ /// with it as the radar is mounted on top of the gun. To compensate for
+ /// this, you can call <see cref="IsAdjustRadarForRobotTurn" /> = true.
+ /// When this is set, the radar will turn independent from the robot's turn,
+ /// i.e. the radar will compensate for the robot's turn.
+ /// <p />
+ /// Note: This method is additive until you reach the maximum the radar can
+ /// turn. The "adjust" is added to the amount you set for turning the robot,
+ /// then capped by the physics of the game. If you turn infinite, then the
+ /// adjust is ignored (and hence overridden).
+ /// <p />
+ /// <example>
+ /// Assuming the robot, gun, and radar all start Out facing up (0
+ /// degrees):
+ /// <code>
+ /// // Set radar to turn with the robots's turn
+ /// setAdjustRadarForRobotTurn(false); // This is the default
+ /// TurnRight(90);
+ /// // At this point, the body, gun, and radar are all facing right (90 degrees);
+ /// </code>
+ /// -- or --
+ /// <code>
+ /// // Set radar to turn independent from the robot's turn
+ /// setAdjustRadarForRobotTurn(true);
+ /// TurnRight(90);
+ /// // At this point, the robot and gun are facing right (90 degrees), but the radar is still facing up.
+ /// </code>
+ /// </example>
+ /// <seealso cref="IsAdjustGunForRobotTurn" />
+ /// <seealso cref="IsAdjustRadarForGunTurn" />
+ /// </summary>
public bool IsAdjustRadarForRobotTurn
{
get
@@ -776,7 +1193,13 @@ public bool IsAdjustRadarForRobotTurn
}
}
}
+
+ /// <summary>
+ /// Returns the current round number (0 to <see cref="NumRounds" /> - 1) of the battle.
+ /// <seealso cref="NumRounds" />
+ /// </summary>
public int RoundNum { get { return _onTest ? _testableRobot.RoundNum : _myRobot.RoundNum; } }
+
public Color ScanColor
{
get { return _onTest ? _testableRobot.ScanColor : _myRobot.ScanColor; }
@@ -792,9 +1215,20 @@ public Color ScanColor
}
}
}
+
+ /// <summary>
+ /// Returns the velocity of the robot measured in pixels/turn.
+ /// <p />
+ /// The maximum velocity of a robot is defined by <see cref="Rules.MAX_VELOCITY" />
+ /// (8 pixels / turn).
+ /// <seealso cref="Rules.MAX_VELOCITY" />
+ /// </summary>
public double Velocity { get { return _onTest ? _testableRobot.Velocity : _myRobot.Velocity; } }
+
public double Width { get { return _onTest ? _testableRobot.Width : _myRobot.Width; } }
+
public double X { get { return _onTest ? _testableRobot.X : _myRobot.X; } }
+
public double Y { get { return _onTest ? _testableRobot.Y : _myRobot.Y; } }
}
}
20 MonSuperRobotTest/GivenMadMax.cs
View
@@ -19,25 +19,5 @@ public void Init()
_mock = new Mock<ITestableRobot>();
_sut = new MadMax(_mock.Object);
}
-
- [Test]
- public void When_my_robot_scans_another_robot_Then_it_should_fire_a_bullet()
- {
- var evt = new ScannedRobotEvent("name", 1, 0, 20, 30, 10);
-
- _sut.OnScannedRobot(evt);
-
- _mock.Verify(x => x.FireBullet(It.IsAny<double>()), Times.Once());
- }
-
- [Test]
- public void My_robot_should_try_to_keep_track_of_enemy_by_changing_the_direction_to_the_enemy_direction_when_scanned()
- {
- var evt = new ScannedRobotEvent("name", 1, 0, 20, 30, 10);
-
- _sut.OnScannedRobot(evt);
-
-
- }
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.