forked from ArchipelagoMW/Archipelago
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Tentative Distance code (not finished)
- Loading branch information
1 parent
eaf1af6
commit 5dfe3c0
Showing
8 changed files
with
385 additions
and
36 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import math | ||
from typing import Union | ||
|
||
from . import Trip | ||
from .Options import MinimumDistance, MaximumDistance | ||
|
||
|
||
def get_current_distance(trip: Trip, distance_reductions: int, | ||
minimum_distance: Union[int, MinimumDistance], | ||
maximum_distance: Union[int, MaximumDistance], | ||
expected_number_of_reductions: int, | ||
expected_number_of_tiers: int) -> int: | ||
distance_tier = trip.template.distance_tier | ||
|
||
reduction_percent = 1 / (expected_number_of_reductions + 4) | ||
remainder_percent = 1 - reduction_percent | ||
|
||
distance_range = maximum_distance - minimum_distance | ||
if distance_range <= 0: | ||
return minimum_distance | ||
smallest_distance_multiplier = math.pow(remainder_percent, expected_number_of_reductions) | ||
distance_range_out_of_logic = distance_range / smallest_distance_multiplier | ||
distance_range_per_tier_out_of_logic = distance_range_out_of_logic / expected_number_of_tiers | ||
|
||
distance_multiplier = math.pow(remainder_percent, distance_reductions) | ||
|
||
reduced_range_per_tier = distance_range_per_tier_out_of_logic * distance_multiplier | ||
extra_distance = distance_tier * reduced_range_per_tier | ||
final_distance = minimum_distance + int(extra_distance) | ||
return final_distance | ||
|
||
|
||
def get_reductions_needed_to_be_reachable(trip: Trip, | ||
minimum_distance: Union[int, MinimumDistance], | ||
maximum_distance: Union[int, MaximumDistance], | ||
expected_number_of_reductions: int, | ||
expected_number_of_tiers: int) -> int: | ||
distance_tier = trip.template.distance_tier | ||
|
||
reduction_percent = 1 / (expected_number_of_reductions + 4) | ||
remainder_percent = 1 - reduction_percent | ||
|
||
distance_range = maximum_distance - minimum_distance | ||
if distance_range <= 0: | ||
return 0 | ||
smallest_distance_multiplier = math.pow(remainder_percent, expected_number_of_reductions) | ||
distance_range_out_of_logic = distance_range / smallest_distance_multiplier | ||
distance_range_per_tier_out_of_logic = distance_range_out_of_logic / expected_number_of_tiers | ||
|
||
# Initial distance without reductions | ||
initial_distance = minimum_distance + int(distance_tier * distance_range_per_tier_out_of_logic) | ||
|
||
if initial_distance <= maximum_distance: | ||
return 0 # No reductions needed if initial distance is already within max distance. | ||
|
||
# Calculate reductions needed using the formula derived above | ||
required_ratio = distance_range / (distance_tier * distance_range_per_tier_out_of_logic) | ||
|
||
if required_ratio <= 0: | ||
return int('inf') # Infinite reductions needed if the ratio is invalid (shouldn't happen in normal cases) | ||
|
||
reductions_needed = math.log(required_ratio) / math.log(remainder_percent) | ||
|
||
return math.ceil(reductions_needed) # Round up to ensure we meet or exceed the target reduction | ||
|
||
# distance_range_per_tier_in_logic = distance_range / expected_number_of_tiers | ||
# required_multiplier = distance_range_per_tier_in_logic / distance_range_per_tier_out_of_logic | ||
|
||
# distance_reductions = math.log(required_multiplier, remainder_percent) | ||
# return math.ceil(distance_reductions) | ||
|
||
# reduced_range_per_tier = distance_range_per_tier_out_of_logic * distance_multiplier | ||
# extra_distance = distance_tier * reduced_range_per_tier | ||
# final_distance = minimum_distance + int(extra_distance) | ||
# return distance_reductions |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import math | ||
|
||
from BaseClasses import ItemClassification | ||
from worlds.generic.Rules import add_rule, item_name_in_locations, set_rule | ||
from . import Options, ItemName | ||
|
||
|
||
def set_rules(world, player: int, world_options: Options.APGOOptions): | ||
set_key_rules(world, player, world_options) | ||
set_distance_rules(world, player, world_options) | ||
|
||
|
||
def set_key_rules(world, player: int, world_options: Options.APGOOptions): | ||
if world_options.number_of_locks <= 0: | ||
return | ||
|
||
for lock in range(1, world_options.number_of_locks+1): | ||
set_rule(world.get_entrance(f"Area {lock-1} -> Area {lock}", player), lambda state: state.has(ItemName.key, player, lock)) | ||
|
||
|
||
def set_distance_rules(world, player: int, world_options: Options.APGOOptions): | ||
if not world_options.enable_distance_reductions: | ||
return | ||
|
||
for trip_name, trip in world.trips.items(): | ||
set_rule(world.get_entrance(f"Area {lock-1} -> Area {lock}", player), lambda state: state.has(ItemName.key, player, lock)) |
Oops, something went wrong.