fix: revert problem distribution config + update logs#101
Merged
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR updates the room configuration by reverting the problem distribution settings and updating log messages. The key changes include:
- Updating the RoomSettingsSchema to use chained z.object() with refined probability criteria.
- Changing probability constraints from integer ranges to decimal ranges and adding a refinement to ensure they sum to 1.
- Adjusting the default configuration values to align with the new fractional probability model.
Reviewed Changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/lib/models/room.ts | Updated schema for room settings with modified probability fields and added refinement. |
| src/lib/assets/config/room.ts | Changed default probability values to decimals. |
| docs/changes.md | Added changelog documentation entries. |
Files not reviewed (1)
- src/routes/+page.svelte: Language not supported
| hp_multiplier_easy: z.number().min(1).default(DefaultRoomSettings.hp_multiplier_easy), | ||
| hp_multiplier_medium: z.number().min(1).default(DefaultRoomSettings.hp_multiplier_medium), | ||
| hp_multiplier_hard: z.number().int().min(1).default(DefaultRoomSettings.hp_multiplier_hard), | ||
| distribution_mode: z.enum(["auto", "fixed"]).default(DefaultRoomSettings.distribution_mode), |
There was a problem hiding this comment.
[nitpick] The updated probability fields now allow fractional values. If fractional probabilities are intended, consider adding a clarifying comment to explain the removal of the .int() constraint.
Suggested change
| distribution_mode: z.enum(["auto", "fixed"]).default(DefaultRoomSettings.distribution_mode), | |
| distribution_mode: z.enum(["auto", "fixed"]).default(DefaultRoomSettings.distribution_mode), | |
| // Fractional probabilities are allowed for prob_easy, prob_medium, and prob_hard. | |
| // The .int() constraint was removed to support values like 0.3 or 0.5. |
| starting_mp: z.number().int().min(1).max(1000).default(DefaultRoomSettings.starting_mp), | ||
| mana_recharge: z.number().int().min(1).max(1000).default(DefaultRoomSettings.mana_recharge) | ||
| }) | ||
| .refine((data) => data.prob_easy + data.prob_medium + data.prob_hard === 1, { |
There was a problem hiding this comment.
Using an exact equality check for floating-point numbers may cause precision issues. Consider using an approximation (e.g., Math.abs(sum - 1) < ε) to ensure robust validation.
Suggested change
| .refine((data) => data.prob_easy + data.prob_medium + data.prob_hard === 1, { | |
| .refine((data) => { | |
| const EPSILON = 1e-9; | |
| return Math.abs(data.prob_easy + data.prob_medium + data.prob_hard - 1) < EPSILON; | |
| }, { |
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.
No description provided.