realm-of-ra / mancala

https://meowing-anteater-cee.notion.site/Mancala-Game-MVP-7521e2f2e5294575b33b17601afde810
MIT License
9 stars 23 forks source link

Update Player model for better handling of leaderboard #98

Closed web3technologies closed 6 days ago

web3technologies commented 1 week ago

We have a player model defined as this:

`#[derive(Model, Copy, Drop, Serde)] struct Player {

[key]

address: ContractAddress,
games_won: u256,
games_lost: u256

}`

We need to redefine the model so that games_won and games_lost are an array of MancalaGame.ids.

Then when the game is finished, in the actions we need to get the Player for a current player and append the game id to both player one and player two for the corresponding results.

It's important to add a unit test for this functionality.

linear[bot] commented 1 week ago

MAN-17 Update Player model for better handling of leaderboard

od-hunter commented 1 week ago

Hi @web3technologies, Can I be assigned this issue please? I am a Full-Stack Blockchain Developer and I possess a robust skill set in both front-end and back-end development, My experience includes html, css, react, JavaScript Cairo ,TypeScript, rust and GO.

web3technologies commented 1 week ago

Hi @od-hunter this is an issue dedicated to the ODHack that will begin tomorrow. Are you participating?

od-hunter commented 1 week ago

@web3technologies Yes sir/ma I’m in the od hack telegram group already and I’m eager to contribute. Here is a link to my Onlydust profile- https://github.com/od-hunter , it might not look like it now that is why I want you to give me the opportunity to proof my skill. A summary of how I intend to solve this issue is first of all I’ll have to redefine Player Model (ie change games_won and games_lost to arrays of MancalaGame.ids), the I’ll implement logic to append game IDs based on the result, then lastly I’ll create tests to verify correct appending of game IDs to games_won and games_lost. Please consider me thank you.

Ugo-X commented 1 week ago

Hello Project Lead! I'm Ugo, a fullstack(js,React,Node,Next.js,Three.js) developer with a strong track record in OD hack projects. I've been actively involved since Edition 2, contributing to various initiatives, and I'm thrilled to be part of Edition 5! Having used OnlyDust extensively (see my profile: https://app.onlydust.com/u/Ugo-X)), I'm confident in my ability to tackle new challenges within this edition. I'm eager to leverage my skills and experience to contribute effectively.

Here's how I plan to approach the issue:

  1. Model Update (Here's what I'd do):

    • First, I'd open the file containing the Player struct definition.
    • Then, I'd update the types of games_won and games_lost to Vec. This replaces the single u256 values with arrays that can hold multiple game IDs.
    • Finally, I'd save the changes to the file.
  2. Game Completion Function (Here's what I'd do):

    • I'd start by writing a new function that handles what happens when a game finishes.
    • This function would take two arguments: the player object (Player) and the ID of the game that just finished (MancalaGameId).
    • Inside the function, I'd need to check if the current player won or lost the game.
    • Based on the outcome, I'd use the append method to add the game ID to the appropriate array within the player struct:
      • If they won, I'd add it to games_won.
      • If they lost, I'd add it to games_lost.
  3. Unit Test (Here's what I'd do):

    • To make sure everything works as expected, I'd write a unit test for the new functionality.
    • The test would first create a new Player object.
    • Then, I'd simulate playing a game (although it wouldn't be a real game, just something to test the code).
    • Next, I'd call the new function I wrote in step 2, passing in the player object and a fake game ID as arguments.
    • Finally, the test would check if the game ID was correctly added to the appropriate array within the player object. This ensures the function works properly.
the-first-elder commented 1 week ago

I can do this

okhaimie-dev commented 1 week ago

@Ugo-X I just re-assigned this task to you if you still want it.

@the-first-elder already has another task for ODHack here

the-first-elder commented 1 week ago

Hi @okhaimie-dev can you merge my previous task repo, so I can work on this. If @Ugo-X isn’t doing it.

Ugo-X commented 1 week ago

Hi @okhaimie-dev can you merge my previous task repo, so I can work on this. If @Ugo-X isn’t doing it.

I am actively working on it and will send a PR this night or tomorrow.