initial commit
This commit is contained in:
commit
39f56a3b10
83 files changed
+3583
No files matched your search
@@ -0,0 +1,40 @@
|
||||
class GameServerQueue:
|
||||
def __init__(self, num_player_team: int, queue=None):
|
||||
if queue is None:
|
||||
self.queue = []
|
||||
self._num_player_team = num_player_team
|
||||
|
||||
|
||||
def enqueue(self, player_name):
|
||||
self.queue.append(player_name)
|
||||
|
||||
def dequeue(self):
|
||||
try:
|
||||
dequed_player = self.queue.pop(0)
|
||||
return dequed_player
|
||||
except IndexError:
|
||||
return None
|
||||
|
||||
|
||||
def fill_queue_with_names(self):
|
||||
player_names = ["xx_sniperLegend_xx","smorkelo","John Warframe","uriel","helldiver david"]
|
||||
for i in range(len(player_names)):
|
||||
self.enqueue(player_names[i])
|
||||
|
||||
def build_teams(self):
|
||||
teams = []
|
||||
while len(self.queue) >= 2:
|
||||
teams.append((self.dequeue(), self.dequeue()))
|
||||
return teams
|
||||
|
||||
def main():
|
||||
game = GameServerQueue(num_player_team=3)
|
||||
game.fill_queue_with_names()
|
||||
game.enqueue("the_tested_one")
|
||||
game.enqueue("the_tested_two")
|
||||
|
||||
print(game.queue)
|
||||
print(game.build_teams())
|
||||
print(game.queue)
|
||||
|
||||
main()
|
||||
@@ -0,0 +1,7 @@
|
||||
Nuremberg > Berlin
|
||||
Nuremberg > Frankfurt
|
||||
Nuremberg > Munich
|
||||
Munich > Nuremberg
|
||||
Hamburg > Berlin
|
||||
Berlin > Hamburg
|
||||
Berlin > Nuremberg
|
||||
@@ -0,0 +1,75 @@
|
||||
class Trains:
|
||||
def __init__(self):
|
||||
self.cities = []
|
||||
self.connections: dict[str, list] = dict()
|
||||
self.f_length = 0
|
||||
self.setup()
|
||||
|
||||
def add_connection(self, city, connection):
|
||||
self.connections[city] = connection
|
||||
|
||||
def setup(self):
|
||||
with open("t_connections.txt", "r") as f:
|
||||
for line in f:
|
||||
self.f_length += 1
|
||||
|
||||
f.seek(0)
|
||||
for _ in range(self.f_length):
|
||||
line = f.readline().strip()
|
||||
split_line = line.split()
|
||||
|
||||
if split_line[0] not in self.cities: self.cities.append(split_line[0])
|
||||
if split_line[2] not in self.cities: self.cities.append(split_line[2])
|
||||
|
||||
for _ in range(len(self.cities)):
|
||||
self.add_connection(self.cities[_], [])
|
||||
|
||||
f.seek(0)
|
||||
for _ in range(self.f_length):
|
||||
line = f.readline().strip()
|
||||
split_line = line.split()
|
||||
if split_line[2] not in self.connections[split_line[0]]:
|
||||
self.connections[split_line[0]].append(split_line[2])
|
||||
|
||||
def get_directions(self,origin):
|
||||
try:
|
||||
return self.connections[origin]
|
||||
except KeyError:
|
||||
return "Origin not Found"
|
||||
|
||||
|
||||
def main():
|
||||
trains = Trains()
|
||||
print(trains.cities)
|
||||
print(trains.connections)
|
||||
|
||||
print("Welcome to Route-Manager")
|
||||
print(f"Known origins {trains.cities}")
|
||||
|
||||
while True:
|
||||
print("1. Proceed to route search")
|
||||
print("2. quit")
|
||||
usr_input = input("1 / 2 ?: ")
|
||||
|
||||
if usr_input == "1":
|
||||
usr_origin = input("Set your origin: ")
|
||||
|
||||
if usr_origin in trains.cities:
|
||||
directions = trains.get_directions(usr_origin)
|
||||
l = len(directions)
|
||||
|
||||
if l != 0:
|
||||
for _ in range(l):
|
||||
print(f"{usr_origin} -> {directions[_]}")
|
||||
|
||||
else:
|
||||
print(f"No connections from {usr_origin}")
|
||||
|
||||
else:
|
||||
print("Origin not Found")
|
||||
|
||||
if usr_input == "2":
|
||||
break
|
||||
|
||||
|
||||
main()
|
||||
Reference in new issue
Block a user