@@ -697,7 +697,6 @@ def run_match(agent_1: Agent | partial,
697697
698698 return match_stats
699699
700-
701700# # SUBMISSION: Additional Imports
702701# Note that all the imports up to this point (for the Malachite Env, WarehouseBrawl, etc...) will be automatically included in the submission, so you need not write them.
703702#
@@ -911,7 +910,7 @@ def __init__(
911910
912911 def predict (self , obs ):
913912 action = self .act_helper .zeros ()
914-
913+
915914 keys = pygame .key .get_pressed ()
916915 if keys [pygame .K_w ]:
917916 action = self .act_helper .press_keys (['w' ], action )
@@ -934,6 +933,11 @@ def predict(self, obs):
934933 action = self .act_helper .press_keys (['l' ], action )
935934 if keys [pygame .K_g ]:
936935 action = self .act_helper .press_keys (['g' ], action )
936+
937+ if keys [pygame .K_q ]:
938+ action = self .act_helper .press_keys (['q' ], action )
939+ if keys [pygame .K_v ]:
940+ action = self .act_helper .press_keys (['v' ], action )
937941 return action
938942
939943
@@ -1395,6 +1399,78 @@ def gen_reward_manager():
13951399 }
13961400 return RewardManager (reward_functions , signal_subscriptions )
13971401
1402+ ## Run Human vs AI match function
1403+ import pygame
1404+ from pygame .locals import QUIT
1405+
1406+ def run_real_time_match (agent_1 : UserInputAgent , agent_2 : Agent , max_timesteps = 30 * 90 , resolution = CameraResolution .LOW ):
1407+ pygame .init ()
1408+ screen = pygame .display .set_mode ((1920 , 1080 )) # Set screen dimensions
1409+ pygame .display .set_caption ("AI Squared - Player vs AI Demo" )
1410+ clock = pygame .time .Clock ()
1411+
1412+ # Initialize environment
1413+ env = WarehouseBrawl (resolution = resolution , train_mode = False )
1414+ observations , _ = env .reset ()
1415+ obs_1 = observations [0 ]
1416+ obs_2 = observations [1 ]
1417+
1418+ if not agent_1 .initialized : agent_1 .get_env_info (env )
1419+ if not agent_2 .initialized : agent_2 .get_env_info (env )
1420+
1421+ # Run the match loop
1422+ running = True
1423+ timestep = 0
1424+ while running and timestep < max_timesteps :
1425+ # Pygame event to handle real-time user input
1426+ for event in pygame .event .get ():
1427+ if event .type == QUIT :
1428+ running = False
1429+
1430+ # User input
1431+ action_1 = agent_1 .predict (obs_1 )
1432+
1433+ # AI input
1434+ action_2 = agent_2 .predict (obs_2 )
1435+
1436+ # Sample action space
1437+ full_action = {0 : action_1 , 1 : action_2 }
1438+ observations , rewards , terminated , truncated , info = env .step (full_action )
1439+ obs_1 = observations [0 ]
1440+ obs_2 = observations [1 ]
1441+
1442+ # Render the game
1443+ img = env .render ()
1444+ screen .blit (pygame .surfarray .make_surface (img ), (0 , 0 ))
1445+ pygame .display .flip ()
1446+
1447+ # Control frame rate (30 fps)
1448+ clock .tick (30 )
1449+
1450+ # If the match is over (either terminated or truncated), stop the loop
1451+ if terminated or truncated :
1452+ running = False
1453+
1454+ timestep += 1
1455+
1456+ # Clean up pygame after match
1457+ pygame .quit ()
1458+
1459+ # Return match stats
1460+ player_1_stats = env .get_stats (0 )
1461+ player_2_stats = env .get_stats (1 )
1462+ match_stats = MatchStats (
1463+ match_time = timestep / 30.0 ,
1464+ player1 = player_1_stats ,
1465+ player2 = player_2_stats ,
1466+ player1_result = Result .WIN if player_1_stats .lives_left > player_2_stats .lives_left else Result .LOSS
1467+ )
1468+
1469+ # Close environment
1470+ env .close ()
1471+
1472+ return match_stats
1473+
13981474if __name__ == '__main__' :
13991475 # Create agent
14001476 # Start here if you want to train from scratch
0 commit comments