From a77b87a351e58d88211358b7191f0b14e83a169c Mon Sep 17 00:00:00 2001
From: fheinrich <fheinrich@techfak.uni-bielefeld.de>
Date: Tue, 6 Feb 2024 17:59:29 +0100
Subject: [PATCH] Prevent wrong number of added players

---
 .../gui_2d_vis/overcooked_gui.py                | 17 ++++++++++++++++-
 overcooked_simulator/overcooked_environment.py  |  2 +-
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/overcooked_simulator/gui_2d_vis/overcooked_gui.py b/overcooked_simulator/gui_2d_vis/overcooked_gui.py
index f41fb03a..70e666a2 100644
--- a/overcooked_simulator/gui_2d_vis/overcooked_gui.py
+++ b/overcooked_simulator/gui_2d_vis/overcooked_gui.py
@@ -875,11 +875,21 @@ class PyGameGUI:
         self.number_bots_to_be_added = 0
         self.split_players = False
         self.multiple_keysets = False
+        self.player_minimum = 1
 
     def update_selection_elements(self):
+        if self.number_humans_to_be_added <= self.player_minimum:
+            self.remove_human_button.disable()
+            self.number_humans_to_be_added = self.player_minimum
+        else:
+            self.remove_human_button.enable()
+        self.number_humans_to_be_added = max(
+            self.player_minimum, self.number_humans_to_be_added
+        )
+
         text = "WASD+ARROW" if self.multiple_keysets else "WASD"
         self.multiple_keysets_button.set_text(text)
-        self.split_players_button
+        # self.split_players_button
         self.added_players_label.set_text(
             f"Humans to be added: {self.number_humans_to_be_added}"
         )
@@ -1016,6 +1026,11 @@ class PyGameGUI:
                                 self.split_players = False
                             case self.split_players_button:
                                 self.split_players = not self.split_players
+                                if self.split_players:
+                                    self.player_minimum = 2
+                                else:
+                                    self.player_minimum = 1
+
                             case self.xbox_controller_button:
                                 print("xbox_controller_button pressed.")
 
diff --git a/overcooked_simulator/overcooked_environment.py b/overcooked_simulator/overcooked_environment.py
index 1132b52b..48ff903a 100644
--- a/overcooked_simulator/overcooked_environment.py
+++ b/overcooked_simulator/overcooked_environment.py
@@ -33,7 +33,7 @@ from overcooked_simulator.utils import create_init_env_time, get_closest
 log = logging.getLogger(__name__)
 
 
-PREVENT_SQUEEZING_INTO_OTHER_PLAYERS = False
+PREVENT_SQUEEZING_INTO_OTHER_PLAYERS = True
 
 
 class ActionType(Enum):
-- 
GitLab