Compare commits

..

No commits in common. "97a90788aaa715b47f2fb20be00cf4efc94868b3" and "2fab9db01fc5ae43fec5ee4c46898c9c90e87b17" have entirely different histories.

2 changed files with 13 additions and 124 deletions

27
main.py
View File

@ -71,19 +71,19 @@ class TreasureCard:
self.state = -1 # effectively disable treasure card self.state = -1 # effectively disable treasure card
class ConcessionCard: class ConcessionCard: # name may be different in English
# Each card contains: # Each card contains:
# 6 cities to connect to the player's concession. There is no need to implement those. # 6 cities to connect to the player's concession. There is no need to implement those.
# 7 gold nuggets, as rewards when the player succefully connects a city to their concession. The player can choose # 7 gold "pepites", as rewards when the player succefully connects a city to their concession. The player can choose
# which nugget to earn, and then discovers the associated reward (between 11 and 17 coins). # which "pepite" to earn, and then discovers the associated reward (between 11 and 17 coins).
# A ConcessionCard is then composed of 7 nuggets, with the rewards randomly distributed. # A ConcessionCard is then composed of 7 pepites, with the rewards randomly distributed.
def __init__(self): def __init__(self):
availableValues = [11, 12, 13, 14, 15, 16, 17] availableValues = [11, 12, 13, 14, 15, 16, 17]
nuggetsNb = len(availableValues) - 1 pepitesNb = len(availableValues) - 1
self.nuggets = [] self.pepites = []
for n in range(0, 7): for n in range(0, 7):
choice = random.randint(0, nuggetsNb - n) choice = random.randint(0, pepitesNb - n)
self.nuggets.append(availableValues[choice]) self.pepites.append(availableValues[choice])
availableValues.pop(choice) availableValues.pop(choice)
self.taken = set() self.taken = set()
@ -95,7 +95,7 @@ class ConcessionCard:
print(str(choice) + " has already been obtained.") print(str(choice) + " has already been obtained.")
return False return False
self.taken.add(choice) self.taken.add(choice)
print("Congrats! You obtained $" + str(self.nuggets[choice])) print("Congrats! You obtained $" + str(self.pepites[choice]))
class Player: class Player:
@ -123,7 +123,6 @@ class Game:
self.players.append(Player(color)) self.players.append(Player(color))
def printStatus(self): def printStatus(self):
print("")
print("Ticket to Ride Legacy: Legends of the West") print("Ticket to Ride Legacy: Legends of the West")
print("") print("")
print("Campaign - Year: " + str(self.year)) print("Campaign - Year: " + str(self.year))
@ -132,7 +131,7 @@ class Game:
for player in self.players: for player in self.players:
print(" " + player.color) print(" " + player.color)
if self.concession: if self.concession:
print(" Concession card remaining nuggets: " + str(player.concession.getRemainingPepites())) print(" Concession card remaining pepites: " + str(player.concession.getRemainingPepites()))
print("") print("")
if self.circus.state > 0: if self.circus.state > 0:
print("Circus next sticker color: " + self.circus.getNextColor()) print("Circus next sticker color: " + self.circus.getNextColor())
@ -167,13 +166,13 @@ playersNb = 2
# Test of ConcessionCard # Test of ConcessionCard
# cc = ConcessionCard() # cc = ConcessionCard()
# userChoice = 3 # userChoice = 3
# print(cc.nuggets) # print(cc.pepites)
# cc.takeReward(userChoice - 1) # cc.takeReward(userChoice - 1)
# print(cc.nuggets) # print(cc.pepites)
# print(cc.taken) # print(cc.taken)
# print("Remaining: " + str(cc.getRemainingPepites())) # print("Remaining: " + str(cc.getRemainingPepites()))
# cc.takeReward(userChoice - 1) # cc.takeReward(userChoice - 1)
# print(cc.nuggets) # print(cc.pepites)
# print(cc.taken) # print(cc.taken)
# print("Remaining: " + str(cc.getRemainingPepites())) # print("Remaining: " + str(cc.getRemainingPepites()))

View File

@ -1,110 +0,0 @@
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()