Skip to content
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

feat: Implement Dynamic Daily Reset for DailyPlayerStat #268

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

kcmikee
Copy link
Contributor

@kcmikee kcmikee commented Mar 4, 2025

Pull Request

Description

This PR introduces a mechanism to track each player's last attempt timestamp using last_attempt_timestamp inside the DailyPlayerStat struct. This ensures that player stats reset dynamically on their first attempt of a new day. The submit_guess function now checks if last_attempt_timestamp is from a previous day—if so, it resets DailyPlayerStat; otherwise, it proceeds normally. Additionally, last_attempt_timestamp updates on every guess submission. Unit tests have been added to verify correct behavior.

Related Issue

Closes #234

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

  • New feature (non-breaking change which adds functionality)

  • Breaking change (fix or feature that would cause existing functionality to not work as expected)Update your CONTRIBUTING.md to reference the template

  • Documentation update

  • Code refactoring

  • Performance improvement

  • Test update

  • Build/CI pipeline change

  • Other (please describe):

Checklist

  • I have read the CONTRIBUTING document.

  • My code follows the code style of this project.

  • I have commented my code, particularly in hard-to-understand areas.

  • I have made corresponding changes to the documentation.

  • My changes generate no new warnings.

  • I have added tests that prove my fix is effective or that my feature works.

  • New and existing unit tests pass locally with my changes.

  • Any dependent changes have been merged and published in downstream modules.

Screenshots/Recordings

Screenshot 2025-03-04 at 9 55 43 AM

Additional Context

Testing Instructions

Run "scarb test" while in the onchain directory

Copy link

vercel bot commented Mar 4, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
de-wordle ❌ Failed (Inspect) Mar 5, 2025 2:47pm

Comment on lines 162 to 174
let current_timestamp = get_block_timestamp();
let last_attempt_timestamp = daily_stat.last_attempt_timestamp;

if last_attempt_timestamp < self.end_of_day_timestamp.read() - SECONDS_IN_A_DAY {
daily_stat =
DailyPlayerStat {
player: caller,
attempt_remaining: 6,
has_won: false,
won_at_attempt: 0,
last_attempt_timestamp: current_timestamp,
};
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move this to the top of the submit_guess function, also you're not updating the daily player stat when it's a new day.

Comment on lines 498 to 513
#[test]
fn test_get_player_daily_stat_new_player() {
let contract_address = deploy_contract();
let dewordle = IDeWordleDispatcher { contract_address };

// Get stats for a player that hasn't played yet
let random_player = starknet::contract_address_const::<0x456>();
let daily_stat = dewordle.get_player_daily_stat(random_player);

// Verify default values
assert(daily_stat.player == random_player, 'Wrong player address');
assert(daily_stat.attempt_remaining == 6, 'Should have 6 attempts');
assert(!daily_stat.has_won, 'has_won should be false');
assert(daily_stat.won_at_attempt == 0, 'won_at_attempt should be 0');
assert(daily_stat.last_attempt_timestamp == 0, 'Timestap should be 0');
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for this too

};
self.daily_player_stat.write(caller, new_daily_stat);
Option::None
return Option::None;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return Option::None;
Option::None

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[CONTRACT] feat: Implement Dynamic Daily Reset for DailyPlayerStat
2 participants