Elo.cairo is a library that allow you to integrate easily a ranking system to your project. The algorithm is based on the classic chest ranking system
run :
protostar install FabienCoutant/Elo.cairo
Copy/paste the library file into your project.
Import the library file into your logic file
from src.Elo.library import ELO
Add a getter in order to get the current Elo for a specfic address :
@view
func getScore{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(
player_address: felt
) -> (score: Uint256) {
let (score) = ELO.getScore(player_address);
return (score,);
}
Add a function to record game result :
@external
func recordResult{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(
playerA_Address: felt, playerB_Address: felt, winner_Address: felt
) -> () {
ELO.recordResult(playerA_Address, playerB_Address, winner_Address);
return ();
}
Enjoy your ranking system 😉