Skip to content

Swap min/max and warn on invalid ranges#25

Open
eiron wants to merge 2 commits intosilasary:keymasters_keepfrom
eiron:kk-swapminandmax
Open

Swap min/max and warn on invalid ranges#25
eiron wants to merge 2 commits intosilasary:keymasters_keepfrom
eiron:kk-swapminandmax

Conversation

@eiron
Copy link

@eiron eiron commented Mar 11, 2026

When a minimum option exceeded its corresponding maximum, the code previously forced the maximum to the minimum (losing the original maximum). This change swaps the min and max values instead, preserving the intended range order, and centralizes the warning text. It also prints the warning to stdout and logs it for lock_magic_keys, area_trials, and shop_items in KeymastersKeepWorld.

When a minimum option exceeded its corresponding maximum, the code previously forced the maximum to the minimum (losing the original maximum). This change swaps the min and max values instead, preserving the intended range order, and centralizes the warning text. It also prints the warning to stdout and logs it for lock_magic_keys, area_trials, and shop_items in KeymastersKeepWorld.
Copilot AI review requested due to automatic review settings March 11, 2026 08:12
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adjusts Keymaster’s Keep world generation to handle invalid option ranges (min > max) by swapping the values instead of clamping, and emits a warning when such swaps occur.

Changes:

  • Swap min/max for lock_magic_keys, area_trials, and shop_items when the range is inverted.
  • Update warning text to indicate a swap rather than clamping to the minimum.
  • Add additional warning output paths (stdout + logging).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


if self.lock_magic_keys_minimum > self.lock_magic_keys_maximum:
self.lock_magic_keys_maximum = self.lock_magic_keys_minimum
self.lock_magic_keys_minimum, self.lock_magic_keys_maximum = self.lock_magic_keys_maximum, self.lock_magic_keys_minimum
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

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

This swap assignment line exceeds the configured 120-character line length (Ruff/Black), which can fail lint. Consider wrapping the tuple assignment across multiple lines to stay within the limit.

Copilot uses AI. Check for mistakes.
Comment on lines 210 to 213
warning_message = (
f"Keymaster's Keep: {self.player_name} has a minimum lock magic keys value greater than the maximum. "
"Using minimum value for maximum."
"Swapping minimum and maximum values."
)
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

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

The PR description mentions the warning text is centralized, but this message format is duplicated in each block. Either factor this into a small helper (e.g., a local function that formats/logs the swap warning) or update the PR description to match the implementation.

Copilot uses AI. Check for mistakes.
Comment on lines +228 to +230

print(warning_message)
logging.warning(warning_message)
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

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

print(warning_message) will violate the repo’s Ruff config (T20 bans print) and may double-log since warnings already go to stdout via the logging stream handler. Remove the print and keep the logging.warning(...).

Copilot uses AI. Check for mistakes.

if self.area_trials_minimum > self.area_trials_maximum:
self.area_trials_maximum = self.area_trials_minimum
self.area_trials_minimum, self.area_trials_maximum = self.area_trials_maximum, self.area_trials_minimum
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

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

This swap assignment line likely exceeds the configured 120-character line length (Ruff/Black) and may fail lint. Wrap the tuple assignment across multiple lines.

Suggested change
self.area_trials_minimum, self.area_trials_maximum = self.area_trials_maximum, self.area_trials_minimum
self.area_trials_minimum, self.area_trials_maximum = (
self.area_trials_maximum,
self.area_trials_minimum,
)

Copilot uses AI. Check for mistakes.
Comment on lines +245 to +247

print(warning_message)
logging.warning(warning_message)
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

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

print(warning_message) will violate the repo’s Ruff config (T20 bans print) and may double-log since warnings already go to stdout via the logging stream handler. Remove the print and keep the logging.warning(...).

Copilot uses AI. Check for mistakes.

if self.shop_items_minimum > self.shop_items_maximum:
self.shop_items_maximum = self.shop_items_minimum
self.shop_items_minimum, self.shop_items_maximum = self.shop_items_maximum, self.shop_items_minimum
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

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

This swap assignment line likely exceeds the configured 120-character line length (Ruff/Black) and may fail lint. Wrap the tuple assignment across multiple lines.

Suggested change
self.shop_items_minimum, self.shop_items_maximum = self.shop_items_maximum, self.shop_items_minimum
self.shop_items_minimum, self.shop_items_maximum = (
self.shop_items_maximum,
self.shop_items_minimum,
)

Copilot uses AI. Check for mistakes.
Comment on lines +214 to +216

print(warning_message)
logging.warning(warning_message)
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

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

print(warning_message) will violate the repo’s Ruff config (T20 bans print) and also duplicates output because generation logging is already streamed to stdout via Utils.init_logging. Drop the print and rely on logging.warning(...) (or a dedicated logger) for user-visible warnings.

Copilot uses AI. Check for mistakes.
Ensure configuration minima/required values are properly swapped with their maxima/totals when inverted instead of overwriting them. Replace earlier assignment logic (which set total to required) with tuple swaps for artifacts and magic keys, and similarly for min/max ranges. Streamline warning emission by calling logging.warning directly with clearer messages describing the swap, and remove redundant print/log duplication.
@silasary
Copy link
Owner

I'd rather throw an OptionError and tell the player that they made an invalid yaml.

Attempting to fix a typo by arbitrarily swapping values has the potential to inflict even more confusion than the current fix.

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.

3 participants