diff --git a/README.md b/README.md index 41178079ab45f382edc3ba1c8cb9b84af288801e..a4d18ba3c632c9023e719086b710e7636be44ee3 100644 --- a/README.md +++ b/README.md @@ -20,13 +20,14 @@ the [Documentation](https://scs.pages.ub.uni-bielefeld.de/cocosy/overcooked-simu You have two options to install the environment. Either clone it and install it locally or install it in your site-packages. -You need a Python 3.10 or newer environment. Either conda or PyEnv. +You need a Python 3.10 or newer environment conda environment. ### Local Editable Installation In your `repo`, `PyCharmProjects` or similar directory with the correct environment active: ```bash +conda install -c conda-forge pygraphviz git clone https://gitlab.ub.uni-bielefeld.de/scs/cocosy/overcooked-simulator.git cd overcooked-simulator pip install -e . diff --git a/cooperative_cuisine/__init__.py b/cooperative_cuisine/__init__.py index 4ec76825b50da6103fa25529f88754827d16013a..17dfc078daff4bf21f66270c4c72fa6d2c460cbf 100644 --- a/cooperative_cuisine/__init__.py +++ b/cooperative_cuisine/__init__.py @@ -21,12 +21,14 @@ like a "real", cooperative, human partner. # Installation -You need a Python **3.10** or newer environment. +You need a Python **3.10** or newer codna environment. ```bash +conda install -c conda-forge pygraphviz pip install cooperative_cuisine@git+https://gitlab.ub.uni-bielefeld.de/scs/cocosy/overcooked-simulator@main ``` Or clone it and install it as an editable library which allows you to use all the scripts directly. ```bash +conda install -c conda-forge pygraphviz git clone https://gitlab.ub.uni-bielefeld.de/scs/cocosy/overcooked-simulator.git cd overcooked-simulator pip install -e . diff --git a/cooperative_cuisine/counter_factory.py b/cooperative_cuisine/counter_factory.py index 5232a5bf70e7df880ea7bba28e1257c5275aa130..b1aae2f6f647daa6a47eda343ab5eb56a1d44d35 100644 --- a/cooperative_cuisine/counter_factory.py +++ b/cooperative_cuisine/counter_factory.py @@ -197,8 +197,6 @@ class CounterFactory: assert self.can_map(c), f"Can't map counter char {c}" counter_class = None - # if c == "@": - # print("-") if self.layout_chars_config[c] in self.item_info: item_info = self.item_info[self.layout_chars_config[c]] if item_info.type == ItemType.Equipment and item_info.equipment: @@ -548,7 +546,6 @@ def determine_counter_orientations( [np.linalg.norm(vector_to_center - n) for n in neighbours_free] ) nearest_vec = neighbours_free[n_idx] - # print(nearest_vec, type(nearest_vec)) c.set_orientation(nearest_vec) elif grid_idx[0] == 0: diff --git a/cooperative_cuisine/pygame_2d_vis/gui.py b/cooperative_cuisine/pygame_2d_vis/gui.py index 7779b05ab7e41dab24949c513d8939b6aecebfad..28f154fd2dac1eb4bce8d603868eddc32f42ed13 100644 --- a/cooperative_cuisine/pygame_2d_vis/gui.py +++ b/cooperative_cuisine/pygame_2d_vis/gui.py @@ -67,7 +67,7 @@ class PlayerKeySet: pickup_key: pygame.key, switch_key: pygame.key, players: list[str], - joystick: int, + joystick: int | None, ): """Creates a player key set which contains information about which keyboard keys control the player. @@ -109,6 +109,8 @@ class PlayerKeySet: return self.current_player = self.controlled_players[self.current_idx] + def __repr__(self) -> str: + return f"Keyset(current={self.current_player}, players={self.controlled_players}, joy={self.joystick})" class PyGameGUI: """Visualisation of the overcooked environment and reading keyboard inputs using pygame.""" @@ -232,7 +234,7 @@ class PyGameGUI: pickup_key=pygame.K_e, switch_key=pygame.K_SPACE, players=players, - joystick=0, + joystick=None, ) key_set2 = PlayerKeySet( move_keys=[pygame.K_LEFT, pygame.K_RIGHT, pygame.K_UP, pygame.K_DOWN], @@ -240,10 +242,16 @@ class PyGameGUI: pickup_key=pygame.K_o, switch_key=pygame.K_p, players=players, - joystick=1, + joystick=None, ) key_sets = [key_set1, key_set2] + if self.joysticks: + for idx, key in enumerate(self.joysticks.keys()): + if idx >= len(key_sets): + break + key_sets[idx].joystick = key + if disjunct: key_set1.set_controlled_players(players[::2]) key_set2.set_controlled_players(players[1::2]) @@ -1452,7 +1460,7 @@ class PyGameGUI: if env_info.status_code == 403: raise ValueError(f"Forbidden Request: {env_info.json()['detail']}") elif env_info.status_code == 409: - print("CONFLICT") + log.warning("CONFLICT") env_info = env_info.json() assert isinstance(env_info, dict), "Env info must be a dictionary" self.current_env_id = env_info["env_id"] @@ -1586,7 +1594,6 @@ class PyGameGUI: if answer.status_code == 200: answer_json = answer.json() self.player_info = answer_json["player_info"]["0"] - print("TUTORIAL PLAYER INFO", self.player_info) self.level_info = answer_json["level_info"] self.player_info = {self.player_info["player_id"]: self.player_info} else: @@ -1607,7 +1614,6 @@ class PyGameGUI: if answer.status_code == 200: answer_json = answer.json() self.player_info = answer_json["player_info"] - print("GAME PLAYER INFO", self.player_info) self.level_info = answer_json["level_info"] self.last_level = self.level_info["last_level"] @@ -1861,7 +1867,7 @@ class PyGameGUI: self.get_game_connection() else: self.menu_state = MenuStates.Start - print( + log.warning( "COULD NOT START STUDY; Response:", answer.status_code, answer.json()["detail"], @@ -2020,21 +2026,28 @@ class PyGameGUI: # joystick, filling up the list without needing to create them manually. joy = pygame.joystick.Joystick(event.device_index) self.joysticks[joy.get_instance_id()] = joy - print(f"Joystick {joy.get_instance_id()} connected") + + for key_set in self.key_sets: + if key_set.joystick is None: + key_set.joystick = joy.get_instance_id() + break + log.debug(f"Joystick {joy.get_instance_id()} connected") # disconnect joystick if event.type == pygame.JOYDEVICEREMOVED: del self.joysticks[event.instance_id] - print(f"Joystick {event.instance_id} disconnected") - print("Number of joysticks:", pygame.joystick.get_count()) + for key_set in self.key_sets: + if key_set.joystick == event.instance_id: + key_set.joystick = None + log.debug(f"Joystick {event.instance_id} disconnected") + log.debug(f"Number of joysticks:"+str(pygame.joystick.get_count())) # Press enter key or controller start button instead of mouse button press if ( event.type == pygame.JOYBUTTONDOWN and any( [ - self.joysticks and self.joysticks[i].get_button(7) - for i in range(len(self.joysticks)) + joy.get_button(7) for joy in self.joysticks.values() ] ) or ( @@ -2159,4 +2172,4 @@ if __name__ == "__main__": args.manager_ids, CONNECT_WITH_STUDY_SERVER=True, debug=args.do_study, - ) + ) \ No newline at end of file diff --git a/cooperative_cuisine/study_server.py b/cooperative_cuisine/study_server.py index 55ab0275c72f08724a32f525014d258fcbff181b..ef19419279d33e8107ab8079c2262c7b12eb3f30 100644 --- a/cooperative_cuisine/study_server.py +++ b/cooperative_cuisine/study_server.py @@ -556,7 +556,6 @@ class StudyManager: match env_info.status_code: case 200: env_info = env_info.json() - print("CREATE TUTORIAL:", env_info) study_manager.running_tutorials[participant_id] = env_info case 403: raise HTTPException( diff --git a/cooperative_cuisine/utils.py b/cooperative_cuisine/utils.py index 9314a01e29c0d7abb23c90323067280460f1057f..35a5cdecae47c9e416f072f85a201be068522346 100644 --- a/cooperative_cuisine/utils.py +++ b/cooperative_cuisine/utils.py @@ -459,7 +459,6 @@ def create_layout_with_counters(w, h) -> str: else: string += "_" string += "\n" - print(string) return string