Skip to content

Commit

Permalink
[states] Add solving method
Browse files Browse the repository at this point in the history
  • Loading branch information
Prometheus3375 committed Jul 19, 2024
1 parent 14e90b8 commit 14fdb6d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 41 deletions.
41 changes: 0 additions & 41 deletions solve/solver.py

This file was deleted.

32 changes: 32 additions & 0 deletions solve/states/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,38 @@ def next_states(self, /, is_doing_triumph: bool) -> Iterator[Self]:
"""
raise NotImplementedError

def solve(self, /, is_doing_triumph: bool, last_position_touched: str | None) -> Self:
"""
Makes moves starting from this state until one of the next states is done,
then returns that done state.
"""
# region First cycle
if is_doing_triumph and last_position_touched:
states = [
next_state
for next_state in self.next_states(is_doing_triumph)
if last_position_touched != next_state.first_position
]
else:
states = list(self.next_states(is_doing_triumph))

# endregion

for _ in range(self.max_cycles - 1):
states = [
next_state
for state in states
for next_state in state.next_states(is_doing_triumph)
]
for state in states:
if state.is_done:
return state
else:
raise ValueError(
f'cannot solve encounter with initial {self} '
f'within {self.max_cycles} cycles'
)

def __repr__(self, /) -> str:
return (
f'{self.__class__.__name__}('
Expand Down

0 comments on commit 14fdb6d

Please sign in to comment.