-
Notifications
You must be signed in to change notification settings - Fork 37
Fixed bug in server.rules.math::calcNewBotSpeed #85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Previously, when the currentSpeed = 0, it was possible to accelerate backwards at a limit bound by DECELERATION, rather than ACCELERATION. The condition when currentSpeed = 0 is now evaluated separately from the condition when currentSpeed > 0.
@mnbrandl Thank you for the contribution and help fixing an issue. 😊👍 Before merging this into the main branch, I will first create some tests that identifies the bug, but also suit for refactoring code later etc. So please be patient with me till I have some test ready. |
Glad to help! I suppose I should add, I was getting an error that Gradle was unable to locate the kotlin-stdlib dependency, as no repositories had been added. I'm assuming it is probably an issue to my specific build environment (I'm having other issues trying to build), but maybe not. Whatever the issue, it was fixed by adding a repositories block to the dependencyResolutionManagement block in settings.gradle.kts. Not being very Gradle saavy, I don't know if this is something that needs to be looked into. As for the tests, I have written some code that involves using the method, but did so in my own project for developing bots. The code wasn't written as a test, but it happened to function as a test find and fix the bug. I am willing to come up with some tests, but I'm not sure how to proceed given your comment about being suited for future refactoring. |
I am adding some tests very soon (work in progress) that proves that there is a bug, meaning that some of the tests will fail. |
@mnbrandl I have now added some basic tests that proves that there are several issues: The issue you found with the speed being -2 instead of -1. But also some issue when the speed is going from a positive to negative value, and vice versa, and comparing with the behaviour of the original Robocode. |
I did not think to compare behavior with the original Robocode, that would have made too much sense! I do believe you are correct, the decel time needs to be calculated (from which we can easily obtain the accel time as well). The new speed is simply acceleration * time. However, to correctly calculate the new position, the time accel and decel time is also required in the method MutableBot::moveToNewPosition. Also, in instances crossing zero from a given current speed where the target speed could result in time spent decelerating, accelerating, and traveling at constant speed (eg. -0.5, 0.5), which would also be required in moveToNewPosition. I see the original is doing things differently, relying on the distance remaining rather than a target speed to calculate movement. Target speed is now calculated in the BaseBotInternals class, and seems to be doing much of the work we are looking to implement in the server module. I'll have to look more into myself as well, let me know your thoughts once you have taken a look! |
@mnbrandl I merge you pull request now as promised. Then I will figure out how to incorporate the crossing of zero without the distance so we can fix the remaining part of the test as it would be best to let tank royale be as compatible with the original game as possible to support the bridge. Especially because they are so similar. |
…l) for fixing a major bug in server.rules.math::calcNewBotSpeed.
…. when the currentSpeed and targetSpeed have different signs.
@mnbrandl I fixed the remaining bug when speed 0 is crossed, i.e. when the current speed and target speed have different signs. 😊 |
…n server.rules.math::calcNewBotSpeed.
Previously, when the currentSpeed = 0, it was possible to accelerate backwards at a limit bound by DECELERATION, rather than ACCELERATION.
The condition when currentSpeed = 0 is now evaluated separately from the condition when currentSpeed > 0.