Skip to content

Commit

Permalink
[states] Update init functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Prometheus3375 committed Jul 18, 2024
1 parent dcb8bc2 commit 02c86c5
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 34 deletions.
46 changes: 28 additions & 18 deletions solve/states/rooms.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,20 +116,27 @@ def next_states(self, /, is_doing_triumph: bool) -> Iterator[Self]:
yield StateOfAllRooms(**kwargs)


class InitRoomsKwargs(TypedDict):
left_inner_shape: Shape2D
left_other_shape: Shape2D
middle_inner_shape: Shape2D
middle_other_shape: Shape2D
right_inner_shape: Shape2D
right_other_shape: Shape2D


def init_rooms(**kw: Unpack[InitRoomsKwargs]) -> StateOfAllRooms:
def init_rooms(
*,
left_inner_shape: Shape2D,
left_other_shape: Shape2D,
middle_inner_shape: Shape2D,
middle_other_shape: Shape2D,
right_inner_shape: Shape2D,
right_other_shape: Shape2D,
key_set: KeySetType,
) -> StateOfAllRooms:
"""
A convenience function to specify the initial state of all solo rooms.
"""
shapes = kw.values()
shapes = (
left_inner_shape,
left_other_shape,
middle_inner_shape,
middle_other_shape,
right_inner_shape,
right_other_shape,
)
assert all(isinstance(f, Shape2D) for f in shapes), f'all shapes must be 2D shapes'

c = Counter(shapes)
Expand All @@ -138,20 +145,23 @@ def init_rooms(**kw: Unpack[InitRoomsKwargs]) -> StateOfAllRooms:
return StateOfAllRooms(
left=RoomState(
LEFT,
kw['left_inner_shape'],
Multiset((kw['left_inner_shape'], kw['left_other_shape'])),
left_inner_shape,
dropping_shapes=Multiset((left_inner_shape, left_other_shape)),
final_dropping_shapes=key_set[left_inner_shape].terms,
),
middle=RoomState(
MIDDLE,
kw['middle_inner_shape'],
Multiset((kw['middle_inner_shape'], kw['middle_other_shape'])),
middle_inner_shape,
dropping_shapes=Multiset((middle_inner_shape, middle_other_shape)),
final_dropping_shapes=key_set[middle_inner_shape].terms,
),
right=RoomState(
RIGHT,
kw['right_inner_shape'],
Multiset((kw['right_inner_shape'], kw['right_other_shape'])),
right_inner_shape,
dropping_shapes=Multiset((right_inner_shape, right_other_shape)),
final_dropping_shapes=key_set[right_inner_shape].terms,
),
)


__all__ = 'PassMove', 'StateOfAllRooms', 'InitRoomsKwargs', 'init_rooms'
__all__ = 'PassMove', 'StateOfAllRooms', 'init_rooms'
47 changes: 31 additions & 16 deletions solve/states/statues.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,22 +110,22 @@ def next_states(self, /, is_doing_triumph: bool) -> Iterator[Self]:
yield StateOfAllStatues(**kwargs)


class InitStatuesKwargs(TypedDict):
left_inner_shape: Shape2D
left_held_shape: Shape3D
middle_inner_shape: Shape2D
middle_held_shape: Shape3D
right_inner_shape: Shape2D
right_held_shape: Shape3D


def init_statues(**kw: Unpack[InitStatuesKwargs]) -> StateOfAllStatues:
def init_statues(
*,
left_inner_shape: Shape2D,
left_held_shape: Shape3D,
middle_inner_shape: Shape2D,
middle_held_shape: Shape3D,
right_inner_shape: Shape2D,
right_held_shape: Shape3D,
key_set: KeySetType,
) -> StateOfAllStatues:
"""
A convenience function to specify the initial state of all statues in the main room.
"""
inner = kw['left_inner_shape'], kw['middle_inner_shape'], kw['right_inner_shape']
inner = left_inner_shape, middle_inner_shape, right_inner_shape
assert all(isinstance(s, Shape2D) for s in inner), f'all inner shapes must be 2D'
held = kw['left_held_shape'], kw['middle_held_shape'], kw['right_held_shape']
held = left_held_shape, middle_held_shape, right_held_shape
assert all(isinstance(s, Shape3D) for s in held), f'all held shapes must be 3D'
assert all(d2 in d3.terms for d2, d3 in zip(inner, held)), \
f'every held shape must contain respective inner shape at least once'
Expand All @@ -137,10 +137,25 @@ def init_statues(**kw: Unpack[InitStatuesKwargs]) -> StateOfAllStatues:
f'the number of all 2D terms of held 3D shapes must be 2, got {c2}'

return StateOfAllStatues(
left=StatueState(LEFT, kw['left_inner_shape'], kw['left_held_shape']),
middle=StatueState(MIDDLE, kw['middle_inner_shape'], kw['middle_held_shape']),
right=StatueState(RIGHT, kw['right_inner_shape'], kw['right_held_shape']),
left=StatueState(
LEFT,
left_inner_shape,
shape_held=left_held_shape,
final_shape_held=key_set[left_inner_shape],
),
middle=StatueState(
MIDDLE,
middle_inner_shape,
shape_held=middle_held_shape,
final_shape_held=key_set[middle_inner_shape],
),
right=StatueState(
RIGHT,
right_inner_shape,
shape_held=right_held_shape,
final_shape_held=key_set[right_inner_shape],
),
)


__all__ = 'DissectMove', 'StateOfAllStatues', 'InitStatuesKwargs', 'init_statues'
__all__ = 'DissectMove', 'StateOfAllStatues', 'init_statues'

0 comments on commit 02c86c5

Please sign in to comment.