-
Notifications
You must be signed in to change notification settings - Fork 67
Implement cell decay system and add game mechanics test suite #10
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other comments: 0 Blocking, 3 Optional, 2 Nit, 0 FYI
-
Optional: static/js/utils.js (57-59)
Using `Date.now()` directly in the function makes testing difficult and can lead to non-deterministic behavior. Consider accepting the current time as a parameter:
// Apply starvation decay if the entity hasn't eaten recently if (entity.lastFoodTime !== undefined) { const currentTime = Date.now(); const timeSinceFood = (currentTime - entity.lastFoodTime) / 1000; // in seconds if (timeSinceFood > DECAY_STARVATION_THRESHOLD) {Or better yet, pass the current time as a parameter to the function to make it more testable.
Optional
2
The comment suggests improving the testability of the code by making the function accept the current time as a parameter rather than using Date.now() directly. This is a valid software engineering practice that would make the code more testable and deterministic.
-
Optional: static/js/config.js (13-13)
The comment for DECAY_THRESHOLD doesn't fully explain the behavior. Does decay stop completely when score falls below 50, or does it continue at a reduced rate? Consider clarifying this in the comment.
Optional
3
The comment suggests that the documentation for DECAY_THRESHOLD is unclear about whether decay stops completely or continues at a reduced rate. Looking at the implementation in utils.js (lines 39-41), decay does stop completely when the score is below or equal to the threshold. The comment is suggesting an improvement to the documentation to make this behavior clearer.
-
Optional: static/js/utils.js (39-72)
This function both modifies `entity.score` directly and returns the updated score value. This mixed approach can be confusing. Consider either:
- Modifying the entity in-place and not returning anything (void function)
- Returning the new score without modifying the entity (pure function)
The current implementation could lead to bugs if a caller ignores the return value but expects the entity to be updated, or vice versa.
Optional
3
The comment critiques the design of the applyDecay function in utils.js (lines 39-72), noting that it both modifies the entity in-place and returns the updated score. This mixed approach could lead to confusion about how the function should be used. This is a valid design concern.
-
Nit: .windsurf/rules/code-style-guide.md (26-26)
Consider adding a newline at the end of the file to follow the common convention of ending files with a newline character.
Nit
1
The comment suggests adding a newline at the end of the code-style-guide.md file to follow common conventions. Looking at the diff, the file indeed ends without a newline. This is a very minor style issue.
-
Nit: static/js/__tests__/utils.test.js (2-2)
The `DECAY_ENABLED` constant is imported but not used in any of the tests. Consider removing unused imports.
Nit
2
The comment notes that
DECAY_ENABLEDis imported but not used in any of the tests. Looking at the imports on line 2 of the test file, I can see that DECAY_ENABLED is indeed imported, but scanning through the tests, I don't see it being used. This is a valid observation about unused imports that could be cleaned up.
| test('should decay proportionally to time passed', () => { | ||
| const entity = { score: 100 }; | ||
| // Update to use power function instead of sqrt | ||
| const expectedDecayFactor = Math.pow(entity.score, DECAY_SIZE_FACTOR) / 10; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test is using DECAY_SIZE_FACTOR on line 83, but this constant is not imported from the config file. This will cause a reference error when running the test.
Internal-only debug info
- Category: Blocking
- Subjectivity Score: 1
- Thoughts:
The comment points out thatDECAY_SIZE_FACTORis used on line 83 of the test file but is not imported from the config file. Looking at the diff, I can see that in static/js/tests/utils.test.js on line 83, there is indeed a reference toDECAY_SIZE_FACTORin a test, but this constant is not imported at the top of the file (only DECAY_ENABLED, DECAY_RATE, and DECAY_THRESHOLD are imported). This is a clear reference error that would cause the test to fail.
| // Advanced decay mechanics | ||
| export const DECAY_MOVEMENT_MULTIPLIER = 1.5; // Decay multiplier when moving (higher = more decay when moving) | ||
| export const DECAY_SIZE_FACTOR = 0.2; // How much size affects decay (higher = larger cells decay faster) | ||
| export const DECAY_STARVATION_THRESHOLD = 10; // Seconds without food before starvation decay kicks in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's an inconsistency in time units: DECAY_STARVATION_THRESHOLD is in seconds while DECAY_INTERVAL is in milliseconds. Consider using consistent time units or explicitly noting the units in the variable names (e.g., DECAY_STARVATION_THRESHOLD_SECONDS).
Internal-only debug info
- Category: Optional
- Subjectivity Score: 2
- Thoughts:
The comment points out an inconsistency in time units between DECAY_STARVATION_THRESHOLD (in seconds) and DECAY_INTERVAL (in milliseconds). Looking at the code in config.js and how these values are used in utils.js and game.js, this is a valid observation. The inconsistency could lead to confusion or bugs.
| const deltaTime = currentTime - lastFrameTime; | ||
| lastFrameTime = currentTime; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The deltaTime variable is calculated but not used in the main game loop. Consider using this for time-based movement and updates to ensure consistent game speed regardless of frame rate.
Internal-only debug info
- Category: Optional
- Subjectivity Score: 2
- Thoughts:
The comment points out thatdeltaTimeis calculated but not used in the main game loop in game.js. Looking at lines 59-60, deltaTime is indeed calculated but not used in the subsequent code. This is a valid observation about potentially unused code.
|
Abhay Aggarwal seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
- Fix missing DECAY_SIZE_FACTOR import in utils.test.js - Fix inconsistent decay calculation in tests (use power function instead of sqrt) - Remove unused DECAY_ENABLED import from utils.test.js - Improve DECAY_THRESHOLD documentation for clarity
|
🔧 Automated remediation applied:
Ready for re-review! |
Summary
This PR adds a comprehensive test suite for the game mechanics, implements a new decay system, and adds a code style guide for the project. The decay system causes player and AI cells to gradually lose mass over time, with additional decay factors like movement and starvation.
Changes
Test Plan
N/A
Deployment Plan
N/A
Rollback Plan
N/A
!changelog