Skip to content

Commit

Permalink
[states] Make ALL_POSITIONS public
Browse files Browse the repository at this point in the history
  • Loading branch information
Prometheus3375 committed Jul 19, 2024
1 parent 8ad4bc7 commit e92816d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions solve/states/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
RIGHT: Literal['right'] = 'right'
type PositionsType = Literal['left', 'middle', 'right']

_POSITIONS = {LEFT, MIDDLE, RIGHT}
ALL_POSITIONS = {LEFT: None, MIDDLE: None, RIGHT: None}
_POSITIONS_MSG = f'{LEFT!r}, {MIDDLE!r} or {RIGHT!r}'


def is_position(s: str, /) -> TypeGuard[PositionsType]:
"""
Returns ``True`` if a string is a valid position.
"""
return s in _POSITIONS
return s in ALL_POSITIONS


class PMove(Protocol):
Expand Down Expand Up @@ -125,7 +125,7 @@ def __init__(self, /, left: S, middle: S, right: S, moves_made: tuple[M, ...] =
self.moves_made = moves_made

# region Verify that constructor and slots have POSITIONS
assert set(__slots__) >= _POSITIONS, f'encounter state must have position attributes'
assert set(__slots__) >= ALL_POSITIONS.keys(), f'encounter state must have position attributes'

signature_ = signature(__init__)
kwargs = {
Expand All @@ -134,7 +134,7 @@ def __init__(self, /, left: S, middle: S, right: S, moves_made: tuple[M, ...] =
if p.kind == p.KEYWORD_ONLY or p.kind == p.POSITIONAL_OR_KEYWORD
}

assert kwargs >= _POSITIONS, f'encounter state must have position keyword arguments'
assert kwargs >= ALL_POSITIONS.keys(), f'encounter state must have position keyword arguments'
del signature_, kwargs
# endregion

Expand Down Expand Up @@ -180,6 +180,7 @@ def __repr__(self, /) -> str:
'LEFT',
'MIDDLE',
'RIGHT',
'ALL_POSITIONS',
'PositionsType',
'is_position',
'State',
Expand Down
2 changes: 1 addition & 1 deletion solve/states/rooms.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def init_rooms_from_players(
for p in players
if p.their_shape == i
}
aliases = dict(zip((LEFT, MIDDLE, RIGHT), (inner2person[i].alias for i in inner_shapes)))
aliases = dict(zip(ALL_POSITIONS, (inner2person[i].alias for i in inner_shapes)))
other = tuple(inner2person[i].other_shape for i in inner_shapes)
state = init_rooms(
left_inner_shape=inner_shapes[0],
Expand Down

0 comments on commit e92816d

Please sign in to comment.