hyphi_gym.common.board#

Module Contents#

Classes#

Board

Base for grid-based games managing

Attributes#

hyphi_gym.common.board.CELLS#
hyphi_gym.common.board.CHARS#
hyphi_gym.common.board.ACTIONS#
class hyphi_gym.common.board.Board(size: tuple[int, int], layout: list[str] | None, bound=None, **kwargs)#

Bases: hyphi_gym.common.base.Base

Base for grid-based games managing • A layout of a variable size • Containing CELLS[WALL, FIELD, AGENT, TARGET, HOLE] • Navigable with ACTIONS[UP, RIGHT, DOWN,LEFT]

board: numpy.ndarray#
size: tuple[int, int]#
layout: numpy.ndarray | None#
ascii(grid: numpy.ndarray | None = None) list[str]#

Transform 2D-INT Array to list of strings

_grid(ascii: list[str]) numpy.ndarray#

Transform 1D string to 2D-INT Array

getpos(board: numpy.ndarray | None = None, cell: str = AGENT) numpy.ndarray#

Position helper for finding the vector position of cell on the board or internal board

newpos(position: numpy.ndarray | tuple[int, int], action: int, n=1) tuple[int, int]#

Action helper mutating a position tuple by appying action n-times

iterate_actions(p: tuple[int, int], n=1, condition=lambda act, pos, n: ...) dict[int, tuple[int, int]]#

Return possible n actions in a bounded box given a position p and their mutated positions

action_possible(act: int, pos: tuple[int, int], n=1) bool#

Return possible n actions act in a bounded box given a position pos

_generate()#

Random generator for flat grids, creating a grid of size

_validate(board, error=True, setup=False)#

Overwrite this function to validate layout return steps to solution

_update(key: str, oldpos, newpos)#
_randomize(board: numpy.ndarray, key: str)#

Mutation function to randomize the position of cell on board

reset(**kwargs) tuple[gymnasium.spaces.Space, dict]#

Gymnasium compliant function to reset the environment