freechat / games_generated_camel /planet_data.py
K00B404's picture
Add application file
368a861
import yaml
class PlanetData:
def __init__(self, planet_data_file):
self.planets = self.load_planet_data(planet_data_file)
def load_planet_data(self, planet_data_file):
try:
with open(planet_data_file, 'r') as file:
return yaml.safe_load(file)
except FileNotFoundError:
print("Planet data file not found. Make sure it exists.")
return {}
def get_planet_names(self):
# Return a list of planet names from loaded data
return list(self.planets.keys())
def get_distance(self, source_planet, destination_planet):
# Get the distance between two planets from loaded data
if source_planet in self.planets and destination_planet in self.planets:
return abs(self.planets[source_planet] - self.planets[destination_planet])
else:
return 0
def calculate_travel_cost(self, source_planet, destination_planet):
# Calculate travel cost based on distance from loaded data
distance = self.get_distance(source_planet, destination_planet)
travel_cost = distance * 10 # Replace with your own calculation
return travel_cost