Skip to content

feat: scoring and time calculations - #149

Merged
manlikeHB merged 5 commits into
songifi:refac/modular-architecturefrom
emarc99:feat-scoring-and-calculations
Aug 14, 2025
Merged

feat: scoring and time calculations#149
manlikeHB merged 5 commits into
songifi:refac/modular-architecturefrom
emarc99:feat-scoring-and-calculations

Conversation

@emarc99

@emarc99 emarc99 commented Aug 13, 2025

Copy link
Copy Markdown

Scoring & Calculations Implementation

This PR implements the scoring algorithms and statistical calculations for the RoundPlayer module, adding robust functionality for scoring answers and maintaining player statistics during gameplay.

Features Added

1. Answer Scoring System (calculate_answer_score)

  • Implemented time-based scoring algorithm
  • Base score: 100 points for correct answers
  • Time bonus calculation: ((timeout - time_taken) * 100) / timeout
  • Maximum possible score: 200 points (instant answer)
  • Minimum score: 100 points (for answers just before timeout)
  • Zero points for timed-out answers

2. Running Average Time Calculation (calculate_average_time)

  • Implemented efficient running average calculation
  • First answer handling
  • Incremental average updates
  • Memory-efficient calculation without storing historical values
  • Formula: ((current_avg * total_answers) + new_time) / (total_answers + 1)

Technical Implementation Details

Scoring Algorithm

  • Efficient integer arithmetic calculations
  • Handles edge cases (timeouts, instant answers)
  • Scales properly with different timeout values
  • Maintains precision in calculations

Average Time Calculation

  • Single-pass calculation methodology
  • No array storage needed for historical values
  • Handles edge cases (first answer, zero values)
  • Safe handling of large numbers

Testing

Comprehensive test suite added covering:

Score Calculation Tests

  • ✓ Timeout scenarios
  • ✓ Instant answers
  • ✓ Mid-range response times
  • ✓ Edge cases with minimum/maximum timeouts
  • ✓ Large number handling

Average Time Calculation Tests

  • ✓ First answer scenarios
  • ✓ Sequential answer averaging
  • ✓ Same value repetition
  • ✓ Zero value handling
  • ✓ Large number calculations
  • ✓ Mixed large and small number scenarios

Performance Considerations

  • All calculations use integer arithmetic
  • No dynamic memory allocation
  • O(1) time complexity for all operations
  • Safe handling of u64 numeric boundaries

Breaking Changes

None. This PR only adds new functionality without modifying existing behavior.

Next Steps

The scoring system is now ready to be integrated with:

  • Round completion calculations
  • Leaderboard updates
  • Player statistics tracking

Testing Instructions

Run the test suite with:

sozo test

@emarc99
emarc99 changed the base branch from main to refac/modular-architecture August 13, 2025 22:37

@manlikeHB manlikeHB left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM!

@manlikeHB
manlikeHB merged commit 3f46145 into songifi:refac/modular-architecture Aug 14, 2025
1 check passed
@emarc99
emarc99 deleted the feat-scoring-and-calculations branch August 14, 2025 11:57
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.

Feat: Scoring & Calculations Implementation

2 participants