Implemented Elo Function Algorithm for Player Skils Measurement.#13
Closed
Cyber-Mitch wants to merge 0 commit intoNetwalls:mainfrom
Closed
Implemented Elo Function Algorithm for Player Skils Measurement.#13Cyber-Mitch wants to merge 0 commit intoNetwalls:mainfrom
Cyber-Mitch wants to merge 0 commit intoNetwalls:mainfrom
Conversation
Contributor
Author
|
Hello @GoSTEAN I've made I'm done and I've made a PR now. |
Contributor
Author
|
What error is that exactly? Everything worked from my end before i pused. SO i don't think that is coming from my end @GoSTEAN |
Contributor
Author
|
@GoSTEAN I checked. The previous code you merged actually failed before you merged, the somehow the ci.yml file was change when the person pushed. You can check the PR yourself, and see the changes the previous person made changed the CI from what it was. |
Contributor
Author
|
Hey @GoSTEAN I have check change back the what the first person changed in the CI.yml. I took back to the original. |
Contributor
|
@Cyber-Mitch resolve conflict |
Contributor
Author
Okay on it @GoSTEAN |
7f61849 to
7b98350
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Elo Rating System Features and Unit Tests
This section describes the newly implemented Elo rating system features for the Snooket game smart contract, a Dojo-based project on StarkNet that enhances competitive gameplay by tracking player skill levels. It covers the Elo rating functionality, its integration into the game, and the unit tests added to verify correctness. The features are implemented in
src/systems/Snooknet.cairoandsrc/model/game_model.cairo, with tests insrc/tests/test_world.cairo. Fixes for issues likeu32_sub Overflowand model registration errors are also included.Implemented Features
1. PlayerRating Model
src/model/game_model.cairo:ContractAddressas the key and au32rating (default: 1500)."Snooknet"to align with the Dojo world configuration.2. Rating Initialization
ensure_player_ratingfunction insrc/systems/Snooknet.cairo:create_matchto ensure both players have valid ratings before the game starts.3. Elo Rating Calculation
src/systems/Snooknet.cairowithin theInternalImplblock:elo_function: Calculates new ratings for win/loss scenarios.PlayerRatingmodels.calculate_expected.K = 32, scaling deltas by 1000 for integer arithmetic.safe_subtractto prevent underflow whenscore < expected_score.elo_function_draw: Handles rating updates for draws.safe_subtractand clamping to 100.u32underflow by returning 0 whena < b.4. RatingUpdated Event
RatingUpdatedevent whenever a player's rating changes after a match.src/systems/Snooknet.cairo:end_matchafter updating ratings for both players.5. Integration with
end_matchend_matchfunction to incorporate Elo rating updates after a game concludes.src/systems/Snooknet.cairoto callelo_functionfor wins/losses orelo_function_drawfor draws:Fixes and Optimizations
1. Model Registration Issue
"Resource ... is registered but not as model"due to missing namespace specification for thePlayerRatingmodel.namespace = "Snooknet"to thePlayerRatingmodel insrc/model/game_model.cairo:test_world.cairoto registerPlayerRatingandRatingUpdated:ENTRYPOINT_FAILEDerrors by ensuring proper model registration in the Dojo world.2. u32_sub Overflow Error
test_end_gameandtest_rating_update_after_winfailed withu32_sub Overflowdue to unsafe subtractions inelo_function(e.g.,score1 - expected1whenscore1 = 0).safe_subtractand modifiedelo_functionandelo_function_drawto handle negative adjustments:safe_subtractto compute deltas without underflow.Unit Tests
The following unit tests were added to
src/tests/test_world.cairoto verify the Elo rating system features, covering initialization, rating updates, and edge cases.Test Setup
src/tests/test_world.cairoPlayerRatingmodel registration:TestResource::Model(m_PlayerRating::TEST_CLASS_HASH).RatingUpdatedevent registration:TestResource::Event(Snooknet::e_RatingUpdated::TEST_CLASS_HASH)."Snooknet"for consistency.namespace_defsnippet:Tests Added
Test:
test_player_rating_initializationTest:
test_rating_update_after_winTest:
test_rating_update_after_drawTest:
test_end_game_already_endedTest:
test_invalid_winnerTesting Instructions
To run the tests and verify the Elo rating system:
scarb).sozo testSummary
The new
Elo algorithm rating system featurefunction implemented enhances the Snooket game by introducing skill-based player rankings, implemented through thePlayerRatingmodel,elo_function,elo_function_draw, andRatingUpdatedevent. The system handles Cairo’s unsigned integer constraints withsafe_subtractand minimum rating clamping. Fixes for model registration andu32overflow issues ensure reliability, and the test suite validates initialization, rating updates, and edge cases, ensuring a robust competitive experience.This Closes #9