Skip to content
Snippets Groups Projects
Commit a5f8c71d authored by fheinrich's avatar fheinrich
Browse files

If number of added player is more than study capacity: create new study

parent d479117e
No related branches found
No related tags found
1 merge request!62Resolve "Game Flow"
Pipeline #46955 passed
......@@ -88,16 +88,16 @@ def main(cli_args=None):
print("Start PyGame GUI:")
pygame_gui_2 = Process(target=start_pygame_gui, args=(cli_args,))
pygame_gui_2.start()
#
# print("Start PyGame GUI:")
# pygame_gui_3 = Process(target=start_pygame_gui, args=(cli_args,))
# pygame_gui_3.start()
while (
pygame_gui.is_alive()
and pygame_gui_2.is_alive()
# and pygame_gui_3.is_alive()
):
time.sleep(1)
# #
print("Start PyGame GUI:")
pygame_gui_3 = Process(target=start_pygame_gui, args=(cli_args,))
pygame_gui_3.start()
# while (
# pygame_gui.is_alive()
# and pygame_gui_2.is_alive()
# # and pygame_gui_3.is_alive()
# ):
# time.sleep(1)
while pygame_gui.is_alive():
time.sleep(1)
......
......@@ -101,9 +101,11 @@ class StudyState:
len(self.participant_id_to_player_info) == self.study_config["num_players"]
)
def can_add_participant(self, participant_id: int) -> bool:
return len(self.participant_id_to_player_info) < self.study_config["num_players"]
def can_add_participant(self, num_participants: int) -> bool:
filled = self.num_connected_players + num_participants <= self.study_config["num_players"]
print(self.num_connected_players, num_participants, self.study_config["num_players"])
print("CAN ADD", self, filled)
return filled and not self.is_full
def create_env(self, level):
with open(ROOT_DIR / "game_content" / level["item_info_path"], "r") as file:
item_info = file.read()
......@@ -239,6 +241,9 @@ class StudyState:
for websocket in self.websockets.values():
websocket.close()
def __repr__(self):
return f"Study({self.current_running_env['env_id']})"
class StudyManager:
def __init__(self):
......@@ -257,11 +262,14 @@ class StudyManager:
def add_participant(self, participant_id: str, number_players: int):
player_info = None
if all([s.is_full for s in self.running_studies]):
if not self.running_studies or all([not s.can_add_participant(number_players) for s in self.running_studies]):
self.create_study()
print("all", self.running_studies)
for study in self.running_studies:
if not study.is_full:
if study.can_add_participant(number_players):
print("connect", study)
player_info = study.add_participant(participant_id, number_players)
self.participant_id_to_study_map[participant_id] = study
return player_info
......@@ -271,6 +279,7 @@ class StudyManager:
assigned_study.player_finished_level(participant_id)
def get_participant_game_connection(self, participant_id: str):
print(self.participant_id_to_study_map)
assigned_study = self.participant_id_to_study_map[participant_id]
player_info, last_level = assigned_study.get_connection(participant_id)
return player_info, last_level
......
......@@ -20,5 +20,5 @@ levels:
name: "Level 4-2: Dark"
num_players: 6
num_players: 2
num_bots: 2
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment