Finish MOC implementation
This commit is contained in:
parent
0fa163b6ed
commit
1b4ac353fd
@ -1,3 +1,4 @@
|
||||
import os
|
||||
import random
|
||||
|
||||
class City:
|
||||
@ -44,7 +45,7 @@ class Board:
|
||||
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"
|
||||
neighbors = "Detroit", "Cincinnati"
|
||||
self.cities.append(City("Chicago", neighbors))
|
||||
neighbors = "Pittsburgh", "Baltimore", "Norfolk", "Charlotte", "Knoxville", "Cincinnati"
|
||||
self.cities.append(City("Lewisburg", neighbors))
|
||||
@ -58,8 +59,8 @@ class Board:
|
||||
self.cities.append(City("Savannah", neighbors))
|
||||
|
||||
# The South (4 cities)
|
||||
#neighbors = "Cincinnati", "Atlanta", "New Orleans", "Little Rock", "St Louis"
|
||||
neighbors = "Cincinnati", "Atlanta", "New Orleans"
|
||||
#neighbors = "Cincinnati", "Knoxville", "Atlanta", "New Orleans", "Little Rock", "St Louis"
|
||||
neighbors = "Cincinnati", "Knoxville", "Atlanta", "New Orleans"
|
||||
self.cities.append(City("Nashville", neighbors))
|
||||
neighbors = "Charlotte", "Charleston", "Savannah", "Mobile", "Nashville", "Knoxville"
|
||||
self.cities.append(City("Atlanta", neighbors))
|
||||
@ -117,13 +118,22 @@ class MamaOConnel:
|
||||
# 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)
|
||||
# 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)]
|
||||
print("location = " + self.location.name)
|
||||
|
||||
hints = [], [], []
|
||||
hintsDistance = 3, 3, 2 # TODO randomize
|
||||
for h in range(0, 3):
|
||||
|
||||
|
||||
# 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)])
|
||||
if h == 1:
|
||||
while city in hints[0]:
|
||||
@ -131,18 +141,23 @@ 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] - 1):
|
||||
hints[h].insert(0, city)
|
||||
i = 0
|
||||
else:
|
||||
do = True
|
||||
city = self.board.getCityByName(hints[h][i].neighbors[random.randint(0, len(hints[h][i].neighbors) - 1)])
|
||||
counter = 0
|
||||
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]:
|
||||
if counter > len(hints[h][i].neighbors) + 5: # arbitrary failsafe
|
||||
i = i - 1
|
||||
do = False
|
||||
hints[h].pop()
|
||||
break
|
||||
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("FINISH")
|
||||
print("Hideout was: " + self.location.name)
|
||||
for hint in hints:
|
||||
print(hint[-1].name)
|
||||
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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user