Skip to content

Commit

Permalink
[states] Rename properties and attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
Prometheus3375 committed Jul 17, 2024
1 parent a832e1f commit fca7d3b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
22 changes: 11 additions & 11 deletions solve/states/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class State:
"""
Base class for any state.
"""
__slots__ = 'position', 'own_shape', 'shapes_to_give', 'shapes_to_receive'
__slots__ = 'position', 'own_shape', '_shapes_to_give', '_shapes_to_receive'

def __init__(
self,
Expand All @@ -53,37 +53,37 @@ def __init__(
f'position of a state must be {_POSITIONS_MSG}, got {position!r}'
self.position = position
self.own_shape = own_shape
self.shapes_to_give = shapes_to_give
self.shapes_to_receive = shapes_to_receive
self._shapes_to_give = shapes_to_give
self._shapes_to_receive = shapes_to_receive

@property
def is_done(self, /) -> bool:
"""
Whether this state is done.
"""
return len(self.shapes_to_give) == 0 and len(self.shapes_to_receive) == 0
return len(self._shapes_to_give) == 0 and len(self._shapes_to_receive) == 0

@property
def shapes_available(self, /) -> Multiset[Shape2D]:
def shapes_to_give(self, /) -> Multiset[Shape2D]:
"""
List of shapes available in this state.
The multiset of shapes which should be given to other states.
"""
return self.shapes_to_give
return self._shapes_to_give

def is_shape_required(self, shape: Shape2D, /) -> bool:
"""
Return ``True`` if to be done this state requires passed shape.
Return ``True`` if the given shape is required for this state to be done.
"""
return shape in self.shapes_to_receive
return shape in self._shapes_to_receive

def __repr__(self, /) -> str:
attrs = ', '.join(f'{attr}={getattr(self, attr)}' for attr in self.__slots__)
return (
f'{self.__class__.__name__}('
f'{self.position.upper()}, '
f'own_shape={self.own_shape}, '
f'shapes_to_give={self.shapes_to_give}, '
f'shapes_to_receive={self.shapes_to_receive}, '
f'shapes_to_give={self._shapes_to_give}, '
f'shapes_to_receive={self._shapes_to_receive}, '
f'{attrs}'
f')'
)
Expand Down
10 changes: 5 additions & 5 deletions solve/states/rooms.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ def pass_shape(self, shape: Shape2D, other: Self, /) -> [Self, Self]:
self.position,
self.own_shape,
dropping_shapes=self.dropping_shapes.remove_copy(shape),
shapes_to_give=self.shapes_to_give.remove_copy(shape),
shapes_to_receive=self.shapes_to_receive,
shapes_to_give=self._shapes_to_give.remove_copy(shape),
shapes_to_receive=self._shapes_to_receive,
)
new_other = RoomState(
other.position,
other.own_shape,
dropping_shapes=other.dropping_shapes.add_copy(shape),
shapes_to_give=other.shapes_to_give,
shapes_to_receive=other.shapes_to_receive.remove_copy(shape),
shapes_to_give=other._shapes_to_give,
shapes_to_receive=other._shapes_to_receive.remove_copy(shape),
)
return new_self, new_other

Expand All @@ -91,7 +91,7 @@ def make_all_moves(self, /, is_doing_triumph: bool) -> Iterator[Self]:
# Do nothing if either state is done.
if s1.is_done or s2.is_done: continue

for shape in s1.shapes_available:
for shape in s1.shapes_to_give:
if s2.is_shape_required(shape):
new_s1, new_s2 = s1.pass_shape(shape, s2)
move = PassMove(departure=s1.position, shape=shape, destination=s2.position)
Expand Down
10 changes: 5 additions & 5 deletions solve/states/statues.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ def dissect(self, shape1: Shape2D, other: Self, shape2: Shape2D, /) -> [Self, Se
self.position,
self.own_shape,
self.shape_held - shape1 + shape2,
shapes_to_give=self.shapes_to_give.remove_copy(shape1),
shapes_to_receive=self.shapes_to_receive.remove_copy(shape2),
shapes_to_give=self._shapes_to_give.remove_copy(shape1),
shapes_to_receive=self._shapes_to_receive.remove_copy(shape2),
)
new_other = StatueState(
other.position,
other.own_shape,
other.shape_held - shape2 + shape1,
shapes_to_give=other.shapes_to_give.remove_copy(shape2),
shapes_to_receive=other.shapes_to_receive.remove_copy(shape1),
shapes_to_give=other._shapes_to_give.remove_copy(shape2),
shapes_to_receive=other._shapes_to_receive.remove_copy(shape1),
)

return new_self, new_other
Expand All @@ -86,7 +86,7 @@ def make_all_moves(self, /, is_doing_triumph: bool) -> Iterator[Self]:
# Do nothing if either state is done.
if s1.is_done or s2.is_done: continue

for shape1, shape2 in product(s1.shapes_available, s2.shapes_available):
for shape1, shape2 in product(s1.shapes_to_give, s2.shapes_to_give):
if s2.is_shape_required(shape1) and s1.is_shape_required(shape2):
new_s1, new_s2 = s1.dissect(shape1, s2, shape2)
move1 = DissectMove(shape=shape1, destination=s1.position)
Expand Down

0 comments on commit fca7d3b

Please sign in to comment.