✨
This commit is contained in:
2
main.py
2
main.py
@ -22,7 +22,7 @@ def main():
|
|||||||
|
|
||||||
start = time.time()
|
start = time.time()
|
||||||
solution = solve_game(game)
|
solution = solve_game(game)
|
||||||
print(f"\rFound solution with {len(solution)} steps.")
|
print(f"\rFound solution with {len(solution)} steps. {' '*20}")
|
||||||
print(format_instructions(solution, start))
|
print(format_instructions(solution, start))
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
@ -31,14 +31,16 @@ def solve_game(starting_state: Game):
|
|||||||
|
|
||||||
while len(states) > 0:
|
while len(states) > 0:
|
||||||
(current_state, moves), value = states.extract_min()
|
(current_state, moves), value = states.extract_min()
|
||||||
if len(moves) > moves_amount:
|
|
||||||
moves_amount = len(moves)
|
|
||||||
print(f"{len(states) + 1} ({len(attempted_states)})")
|
|
||||||
|
|
||||||
if amount_done + 0.00125 < len(moves)/value:
|
if amount_done + 0.00125 < len(moves)/value:
|
||||||
amount_done = (len(moves)/value)
|
amount_done = (len(moves)/value)
|
||||||
print_progress(amount_done)
|
print_progress(amount_done)
|
||||||
|
|
||||||
|
if len(moves) > moves_amount:
|
||||||
|
moves_amount = len(moves)
|
||||||
|
print(f"{len(states) + 1} ({len(attempted_states)}){' '*20}",
|
||||||
|
end="\r")
|
||||||
|
|
||||||
last_to_vial = moves[-1][1] if len(moves) > 1 else None
|
last_to_vial = moves[-1][1] if len(moves) > 1 else None
|
||||||
possible_moves = current_state.possible_moves(last_to_vial)
|
possible_moves = current_state.possible_moves(last_to_vial)
|
||||||
for from_vial, to_vial in possible_moves:
|
for from_vial, to_vial in possible_moves:
|
||||||
@ -57,7 +59,6 @@ def solve_game(starting_state: Game):
|
|||||||
new_state_value = new_state.min_moves + len(new_state_moves)
|
new_state_value = new_state.min_moves + len(new_state_moves)
|
||||||
states.insert((new_state, new_state_moves), new_state_value)
|
states.insert((new_state, new_state_moves), new_state_value)
|
||||||
|
|
||||||
print("\r", end="")
|
|
||||||
raise NoSolutions()
|
raise NoSolutions()
|
||||||
|
|
||||||
def format_instructions(instructions, start_time):
|
def format_instructions(instructions, start_time):
|
||||||
|
Reference in New Issue
Block a user