Add Mama OConnel tracking (not functional yet)

This commit is contained in:
Alexandre CATTEAU 2024-05-19 17:44:10 +02:00
parent 227040e507
commit 97a90788aa

110
src/moc-tracking.py Normal file
View File

@ -0,0 +1,110 @@
import random
class City:
def __init__(self, name, neighbors):
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
neighbors = "Quebec", "Montreal", "Boston"
self.cities.append(City("Bangor", neighbors))
neighbors = "Bangor", "Montreal"
self.cities.append(City("Quebec", neighbors))
neighbors = "Quebec", "Bangor", "Boston", "Albany", "Buffalo"
self.cities.append(City("Montreal", neighbors))
neighbors = "Bangor", "Montreal", "Albany", "New York"
self.cities.append(City("Boston", neighbors))
neighbors = "Buffalo", "Montreal", "Boston", "New York"
self.cities.append(City("Albany", neighbors))
neighbors = "Detroit", "Montreal", "Albany", "New York", "Philadelphia", "Pittsburgh"
self.cities.append(City("Buffalo", neighbors))
neighbors = "Buffalo", "Albany", "Boston", "Philadelphia"
self.cities.append(City("New York", neighbors))
neighbors = "Buffalo", "New York", "Norfolk", "Baltimore", "Pittsburgh"
self.cities.append(City("Philadelphia", neighbors))
def getCityByName(self, name):
for city in self.cities:
if city.name == name:
return city
return 0
class MamaOConnel:
def __init__(self):
self.board = Board() # TODO Board should be a "static" or "constant" class, see what we can do
self.location = self.board.cities[random.randint(0, len(self.board.cities) - 1)]
# 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:
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]
hints = [], [], []
hintsDistance = 3, 3, 2
for h in range(0, 2):
city = self.board.getCityByName(self.location.neighbors[random.randint(0, len(self.location.neighbors) - 1)])
if h == 1:
while city in hints[0]:
city = self.board.getCityByName(self.location.neighbors[random.randint(0, len(self.location.neighbors) - 1)])
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)])
hints[h].append(city)
for i in range(0, hintsDistance[h] - 2):
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]:
city = self.board.getCityByName(hints[h][i].neighbors[random.randint(0, len(hints[h][i].neighbors) - 1)])
hints[h].append(city)
print(self.location)
print(hints)
# at the end of generation, board and cities should be dropped (no use to keep them in saved data)
myMama = MamaOConnel()