feat: Added an Elo Rating Sytem to the game#8
Open
Cyber-Mitch wants to merge 1 commit intoLearnWeb3DAO:mainfrom
Open
feat: Added an Elo Rating Sytem to the game#8Cyber-Mitch wants to merge 1 commit intoLearnWeb3DAO:mainfrom
Cyber-Mitch wants to merge 1 commit intoLearnWeb3DAO:mainfrom
Conversation
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.
PR: Added on-chain ELO rating system to Tic-Tac-Toe
Summary
Changes
contracts/tic-tac-toe.clarratingsmapprincipal => uint.ELO_DEFAULT(u1200),ELO_K(u32),ELO_SCALE(u1000),ELO_TABLE(expected-score lookup).elo-expected-high(diff): bucketed expected score for the higher-rated player.update-elo(p1, p2, winner): computes and persists rating updates for both players.get-rating(who) -> uint: stored rating orELO_DEFAULTif unseen.play(...): after a winning move, pays out STX and callsupdate-elowith(player-one, player-two, winner).frontend/lib/contract.tsgetRating(address)calls the contract’sget-rating.How it works
1200viadefault-toinget-ratingandupdate-elo.diff = |r1 - r2|, bucket by 100:bucket = diff / 100, clamp to[0, 8].ELO_TABLE(scaled by 1000):[500, 640, 760, 850, 910, 947, 969, 983, 990].e1/e2: ifr1 >= r2,e1 = e_high, elsee1 = 1000 - e_high;e2 = 1000 - e1.ELO_K = 32,ELO_SCALE = 1000):rating += floor(K * (1 - e/1000)).rating -= floor(K * (e/1000)).0.Game flow interaction
play()oncehas-won(board)is true.update-elo(...)→ persist game → logprint.play()after turn validation using storedplayer-oneandplayer-two.Public API
get-rating(who principal) -> uint.create-game,join-game,playsignatures;playnow updates Elo on wins.Tests
tests/tic-tac-toe.test.tsget-ratingreturns1200for new players.1200/1200to1216/1184(K=32, expected=0.5 ⇒ ±16).get-ratingbefore/after.Frontend integration
frontend/lib/contract.ts#getRating(address)for UI display via read-only call.Migration
ratingsis lazily populated; unseen principals read as1200.