Add regions + almost finished MOC generation

This commit is contained in:
Alexandre CATTEAU 2024-05-20 14:49:21 +02:00
parent 31dee57c01
commit 0fa163b6ed

View File

@ -6,26 +6,12 @@ class City:
self.name = name
self.neighbors = neighbors
# Returns the length of the shortest way between the city and another one (target)
def distance(self, target):
if self == target:
return 0
dist = 1
cities = [self]
for city in cities:
for neighbor in city.neighbors:
depth = 1
if target in city.neighbors:
return dist
class Board:
def __init__(self):
self.cities = []
# NorthEast
# NorthEast (8 cities)
neighbors = "Quebec", "Montreal", "Boston"
self.cities.append(City("Bangor", neighbors))
neighbors = "Bangor", "Montreal"
@ -43,12 +29,85 @@ class Board:
neighbors = "Buffalo", "New York", "Norfolk", "Baltimore", "Pittsburgh"
self.cities.append(City("Philadelphia", neighbors))
# Appalachia (8 cities)
neighbors = "Buffalo", "Pittsburgh", "Cincinnati", "Chicago"
self.cities.append(City("Detroit", neighbors))
neighbors = "Buffalo", "Philadelphia", "Baltimore", "Lewisburg", "Cincinnati", "Detroit"
self.cities.append(City("Pittsburgh", neighbors))
neighbors = "Philadelphia", "Norfolk", "Lewisburg", "Pittsburgh"
self.cities.append(City("Baltimore", neighbors))
neighbors = "Norfolk", "Charleston", "Atlanta", "Knoxville", "Lewisburg"
self.cities.append(City("Charlotte", neighbors))
neighbors = "Lewisburg", "Charlotte", "Atlanta", "Nashville", "Cincinnati"
self.cities.append(City("Knoxville", neighbors))
#neighbors = "Detroit", "Pittsburgh", "Lewisburg", "Knoxville", "Nashville", "St Louis"
neighbors = "Detroit", "Pittsburgh", "Lewisburg", "Knoxville", "Nashville"
self.cities.append(City("Cincinnati", neighbors))
#neighbors = "Detroit", "Cincinnati", "St Louis", "Davenport", "St Paul", "Duluth"
neighbors = "Detroit", "Cincinnati", "Davenport"
self.cities.append(City("Chicago", neighbors))
neighbors = "Pittsburgh", "Baltimore", "Norfolk", "Charlotte", "Knoxville", "Cincinnati"
self.cities.append(City("Lewisburg", neighbors))
# Atlantic Coast (3 cities)
neighbors = "Philadelphia", "Charleston", "Charlotte", "Lewisburg", "Baltimore"
self.cities.append(City("Norfolk", neighbors))
neighbors = "Norfolk", "Savannah", "Atlanta", "Charlotte"
self.cities.append(City("Charleston", neighbors))
neighbors = "Charleston", "Jacksonville", "Mobile", "Atlanta"
self.cities.append(City("Savannah", neighbors))
# The South (4 cities)
#neighbors = "Cincinnati", "Atlanta", "New Orleans", "Little Rock", "St Louis"
neighbors = "Cincinnati", "Atlanta", "New Orleans"
self.cities.append(City("Nashville", neighbors))
neighbors = "Charlotte", "Charleston", "Savannah", "Mobile", "Nashville", "Knoxville"
self.cities.append(City("Atlanta", neighbors))
neighbors = "Atlanta", "Savannah", "Jacksonville", "Tampa", "New Orleans"
self.cities.append(City("Mobile", neighbors))
#neighbors = "Nashville", "Mobile", "Houston", "Little Rock"
neighbors = "Nashville", "Mobile"
self.cities.append(City("New Orleans", neighbors))
# Florida (3 cities)
neighbors = "Savannah", "Miami", "Tampa", "Mobile"
self.cities.append(City("Jacksonville", neighbors))
neighbors = "Jacksonville", "Tampa"
self.cities.append(City("Miami", neighbors))
neighbors = "Jacksonville", "Miami", "Mobile"
self.cities.append(City("Tampa", neighbors))
def getCityByName(self, name):
for city in self.cities:
if city.name == name:
return city
print("ERROR: city '" + name + "' is not defined")
return 0
# Returns the length of the shortest way between two cities
def distance(self, start, target):
if start == target:
return 0
dist = 1
cities = [start]
passedCities = []
#print("start = " + start.name + " ; target = " + target.name)
while True:
#print("dist = " + str(dist))
for city in cities:
#print("city = " + city.name)
if target.name in city.neighbors:
return dist
passedCities.extend(cities)
newCities = []
for city in cities:
for neighbor in city.neighbors:
if neighbor not in passedCities:
newCities.append(self.getCityByName(neighbor))
cities = newCities
dist = dist + 1
class MamaOConnel:
@ -60,35 +119,11 @@ class MamaOConnel:
# It could be more proper to have a dedicated method to check if a city can be the location (using distance?)
while len(self.location.neighbors) < 4:
self.location = self.board.cities[random.randint(0, len(self.board.cities) - 1)]
# # Set first hint
# hint1distance = 3
# hint1list = []
# hint1list.append(self.location.neighbors[random.randint(0, len(self.location.neighbors))])
# for i in range(0, hint1distance - 2):
# tmp = hint1list[i].neighbors[random.randint(0, len(hint1list[i].neighbors))]
# while tmp.distance(self.location) < i + 1:
# tmp = hint1list[i].neighbors[random.randint(0, len(hint1list[i].neighbors))]
# hint1list.append(tmp)
# self.hint1 = hint1list[hint1distance - 1]
#
# # Set second hint
# hint2distance = 3
# hint2list = []
# tmp = self.location.neighbors[random.randint(0, len(self.location.neighbors))]
# while tmp == hint1list[0]:
# tmp = self.location.neighbors[random.randint(0, len(self.location.neighbors))]
# hint2list.append(tmp)
# for i in range(0, hint2distance - 2):
# tmp = hint2list[i].neighbors[random.randint(0, len(hint2list[i].neighbors))]
# while tmp.distance(self.location) < i + 1 or tmp == hint1list[i + 1]:
# tmp = hint2list[i].neighbors[random.randint(0, len(hint2list[i].neighbors))]
# hint2list.append(tmp)
# self.hint2 = hint2list[hint2distance - 1]
print("location = " + self.location.name)
hints = [], [], []
hintsDistance = 3, 3, 2
for h in range(0, 2):
hintsDistance = 3, 3, 2 # TODO randomize
for h in range(0, 3):
city = self.board.getCityByName(self.location.neighbors[random.randint(0, len(self.location.neighbors) - 1)])
if h == 1:
while city in hints[0]:
@ -96,14 +131,18 @@ class MamaOConnel:
if h == 2:
while city in hints[0] or city in hints[1]:
city = self.board.getCityByName(self.location.neighbors[random.randint(0, len(self.location.neighbors) - 1)])
print("Hint " + str(h + 1) + ": step 1: " + city.name)
hints[h].append(city)
for i in range(0, hintsDistance[h] - 2):
for i in range(0, hintsDistance[h] - 1):
city = self.board.getCityByName(hints[h][i].neighbors[random.randint(0, len(hints[h][i].neighbors) - 1)])
while city.distance(self.location) < i + 1 or h >= 1 and city in hints[0] or h == 2 and city in hints[1]:
while self.board.distance(city, self.location) < i + 2 or h >= 1 and city in hints[0] or h == 2 and city in hints[1]:
city = self.board.getCityByName(hints[h][i].neighbors[random.randint(0, len(hints[h][i].neighbors) - 1)])
print("Hint " + str(h + 1) + ": step " + str(i + 2) + ": " + city.name)
hints[h].append(city)
print(self.location)
print(hints)
print("FINISH")
print("Hideout was: " + self.location.name)
for hint in hints:
print(hint[-1].name)
# at the end of generation, board and cities should be dropped (no use to keep them in saved data)