mirror of
				https://github.com/illiumst/marl-factory-grid.git
				synced 2025-10-31 12:37:27 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			29 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			29 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
| from typing import Union
 | |
| 
 | |
| from environment.actions import Action
 | |
| from environment.utils.results import ActionResult
 | |
| 
 | |
| from modules.doors import constants as d, rewards as r
 | |
| from environment import constants as c
 | |
| 
 | |
| 
 | |
| class DoorUse(Action):
 | |
| 
 | |
|     def __init__(self):
 | |
|         super().__init__(d.ACTION_DOOR_USE)
 | |
| 
 | |
|     def do(self, entity, state) -> Union[None, ActionResult]:
 | |
|         # Check if agent really is standing on a door:
 | |
|         e = state.entities.get_near_pos(entity.pos)
 | |
|         try:
 | |
|             door = next(x for x in e if x.name.startswith(d.DOOR))
 | |
|             valid = door.use()
 | |
|             state.print(f'{entity.name} just used a {door.name} at {door.pos}')
 | |
|             return ActionResult(entity=entity, identifier=self._identifier, validity=valid, reward=r.USE_DOOR_VALID)
 | |
| 
 | |
|         except StopIteration:
 | |
|             # When he doesn't...
 | |
|             state.print(f'{entity.name} just tried to use a door at {entity.pos}, but there is none.')
 | |
|             return ActionResult(entity=entity, identifier=self._identifier,
 | |
|                                 validity=c.NOT_VALID, reward=r.USE_DOOR_FAIL)
 | 
