pacai.pacman.textui
1import typing 2 3import pacai.core.board 4import pacai.core.gamestate 5import pacai.pacman.board 6import pacai.pacman.gamestate 7import pacai.ui.text 8 9MARKER_OVERRIDES: dict[pacai.core.board.Marker, str] = { 10 pacai.core.board.MARKER_WALL: '█', 11 pacai.pacman.board.MARKER_PELLET: '∙', 12 pacai.pacman.board.MARKER_CAPSULE: '⦾', 13 pacai.core.board.MARKER_AGENT_0: 'X', 14} 15 16class StdioUI(pacai.ui.text.StdioUI): 17 """ A text-based UI specifically for pacman. """ 18 19 def _translate_marker(self, marker: pacai.core.board.Marker, state: pacai.core.gamestate.GameState) -> str: 20 # Make some of the markers more visually clear. 21 state = typing.cast(pacai.pacman.gamestate.GameState, state) 22 23 if (marker.is_agent()): 24 # Note that pacman has already been checked for. 25 if (state.scared_timers.get(marker.get_agent_index(), 0) > 0): 26 # The ghost is scared. 27 return 'ᗢ' 28 29 return 'ᗣ' 30 31 return MARKER_OVERRIDES.get(marker, str(marker))
17class StdioUI(pacai.ui.text.StdioUI): 18 """ A text-based UI specifically for pacman. """ 19 20 def _translate_marker(self, marker: pacai.core.board.Marker, state: pacai.core.gamestate.GameState) -> str: 21 # Make some of the markers more visually clear. 22 state = typing.cast(pacai.pacman.gamestate.GameState, state) 23 24 if (marker.is_agent()): 25 # Note that pacman has already been checked for. 26 if (state.scared_timers.get(marker.get_agent_index(), 0) > 0): 27 # The ghost is scared. 28 return 'ᗢ' 29 30 return 'ᗣ' 31 32 return MARKER_OVERRIDES.get(marker, str(marker))
A text-based UI specifically for pacman.