Finish MOC implementation
This commit is contained in:
parent
0fa163b6ed
commit
1b4ac353fd
@ -1,3 +1,4 @@
|
|||||||
|
import os
|
||||||
import random
|
import random
|
||||||
|
|
||||||
class City:
|
class City:
|
||||||
@ -44,7 +45,7 @@ class Board:
|
|||||||
neighbors = "Detroit", "Pittsburgh", "Lewisburg", "Knoxville", "Nashville"
|
neighbors = "Detroit", "Pittsburgh", "Lewisburg", "Knoxville", "Nashville"
|
||||||
self.cities.append(City("Cincinnati", neighbors))
|
self.cities.append(City("Cincinnati", neighbors))
|
||||||
#neighbors = "Detroit", "Cincinnati", "St Louis", "Davenport", "St Paul", "Duluth"
|
#neighbors = "Detroit", "Cincinnati", "St Louis", "Davenport", "St Paul", "Duluth"
|
||||||
neighbors = "Detroit", "Cincinnati", "Davenport"
|
neighbors = "Detroit", "Cincinnati"
|
||||||
self.cities.append(City("Chicago", neighbors))
|
self.cities.append(City("Chicago", neighbors))
|
||||||
neighbors = "Pittsburgh", "Baltimore", "Norfolk", "Charlotte", "Knoxville", "Cincinnati"
|
neighbors = "Pittsburgh", "Baltimore", "Norfolk", "Charlotte", "Knoxville", "Cincinnati"
|
||||||
self.cities.append(City("Lewisburg", neighbors))
|
self.cities.append(City("Lewisburg", neighbors))
|
||||||
@ -58,8 +59,8 @@ class Board:
|
|||||||
self.cities.append(City("Savannah", neighbors))
|
self.cities.append(City("Savannah", neighbors))
|
||||||
|
|
||||||
# The South (4 cities)
|
# The South (4 cities)
|
||||||
#neighbors = "Cincinnati", "Atlanta", "New Orleans", "Little Rock", "St Louis"
|
#neighbors = "Cincinnati", "Knoxville", "Atlanta", "New Orleans", "Little Rock", "St Louis"
|
||||||
neighbors = "Cincinnati", "Atlanta", "New Orleans"
|
neighbors = "Cincinnati", "Knoxville", "Atlanta", "New Orleans"
|
||||||
self.cities.append(City("Nashville", neighbors))
|
self.cities.append(City("Nashville", neighbors))
|
||||||
neighbors = "Charlotte", "Charleston", "Savannah", "Mobile", "Nashville", "Knoxville"
|
neighbors = "Charlotte", "Charleston", "Savannah", "Mobile", "Nashville", "Knoxville"
|
||||||
self.cities.append(City("Atlanta", neighbors))
|
self.cities.append(City("Atlanta", neighbors))
|
||||||
@ -117,32 +118,46 @@ class MamaOConnel:
|
|||||||
# We need at least 3 accesses to the city, to provide hints through different axes (but even cities with 3 accesses
|
# We need at least 3 accesses to the city, to provide hints through different axes (but even cities with 3 accesses
|
||||||
# can generate a triangle (like Bangor or Tampa), hence the need for 4 accesses)
|
# can generate a triangle (like Bangor or Tampa), hence the need for 4 accesses)
|
||||||
# It could be more proper to have a dedicated method to check if a city can be the location (using distance?)
|
# 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:
|
# Moreover, due to their location and their corner neighbors, Montreal and Jacksonville can never have enough hints
|
||||||
|
# TODO Buffalo sometimes runs in an infinte loop as well; check if still the case after we finished adding cities
|
||||||
|
while len(self.location.neighbors) < 4 or self.location.name in ("Montreal", "Jacksonville"):
|
||||||
self.location = self.board.cities[random.randint(0, len(self.board.cities) - 1)]
|
self.location = self.board.cities[random.randint(0, len(self.board.cities) - 1)]
|
||||||
print("location = " + self.location.name)
|
|
||||||
|
|
||||||
hints = [], [], []
|
hints = [], [], []
|
||||||
hintsDistance = 3, 3, 2 # TODO randomize
|
hintsDistance = 3, 3, 2 # TODO randomize
|
||||||
for h in range(0, 3):
|
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]:
|
# Next hop(s) of hint
|
||||||
|
#for i in range(0, hintsDistance[h] - 1):
|
||||||
|
i = -1
|
||||||
|
while i < hintsDistance[h] - 1:
|
||||||
|
if i == -1:
|
||||||
|
# First hop of hint
|
||||||
city = self.board.getCityByName(self.location.neighbors[random.randint(0, len(self.location.neighbors) - 1)])
|
city = self.board.getCityByName(self.location.neighbors[random.randint(0, len(self.location.neighbors) - 1)])
|
||||||
if h == 2:
|
if h == 1:
|
||||||
while city in hints[0] or city in hints[1]:
|
while city in hints[0]:
|
||||||
city = self.board.getCityByName(self.location.neighbors[random.randint(0, len(self.location.neighbors) - 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)
|
if h == 2:
|
||||||
hints[h].append(city)
|
while city in hints[0] or city in hints[1]:
|
||||||
for i in range(0, hintsDistance[h] - 1):
|
city = self.board.getCityByName(self.location.neighbors[random.randint(0, len(self.location.neighbors) - 1)])
|
||||||
city = self.board.getCityByName(hints[h][i].neighbors[random.randint(0, len(hints[h][i].neighbors) - 1)])
|
hints[h].insert(0, city)
|
||||||
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]:
|
i = 0
|
||||||
|
else:
|
||||||
|
do = True
|
||||||
city = self.board.getCityByName(hints[h][i].neighbors[random.randint(0, len(hints[h][i].neighbors) - 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)
|
counter = 0
|
||||||
hints[h].append(city)
|
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]:
|
||||||
print("FINISH")
|
if counter > len(hints[h][i].neighbors) + 5: # arbitrary failsafe
|
||||||
print("Hideout was: " + self.location.name)
|
i = i - 1
|
||||||
for hint in hints:
|
do = False
|
||||||
print(hint[-1].name)
|
hints[h].pop()
|
||||||
|
break
|
||||||
|
city = self.board.getCityByName(hints[h][i].neighbors[random.randint(0, len(hints[h][i].neighbors) - 1)])
|
||||||
|
counter = counter + 1
|
||||||
|
if do:
|
||||||
|
hints[h].insert(i + 1, city)
|
||||||
|
i = i + 1
|
||||||
|
|
||||||
# at the end of generation, board and cities should be dropped (no use to keep them in saved data)
|
# at the end of generation, board and cities should be dropped (no use to keep them in saved data)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user