Formatting
This commit is contained in:
@@ -219,7 +219,7 @@ def parse_goal(image: np.ndarray, conf: Configuration) -> List[Optional[NumberCa
|
||||
parse_goal_field(square, conf.catalogue, conf.green_card)
|
||||
for square in goal_squares
|
||||
]
|
||||
|
||||
|
||||
return goal_list
|
||||
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ def get_field_squares(
|
||||
squares.append(get_square(adjustment, index_x, index_y))
|
||||
return _extract_squares(image, squares)
|
||||
|
||||
|
||||
def catalogue_cards(squares: List[np.ndarray]) -> List[Tuple[np.ndarray, Card]]:
|
||||
"""Run manual cataloging for given squares"""
|
||||
cv2.namedWindow("Catalogue", cv2.WINDOW_NORMAL)
|
||||
@@ -33,7 +34,7 @@ def catalogue_cards(squares: List[np.ndarray]) -> List[Tuple[np.ndarray, Card]]:
|
||||
result: List[Tuple[np.ndarray, Card]] = []
|
||||
print("Card ID is [B]ai, [Z]hong, [F]a, [H]ua, [R]ed, [G]reen, [B]lack")
|
||||
print("Numbercard e.g. R3")
|
||||
abort_row = 'a'
|
||||
abort_row = "a"
|
||||
special_card_map = {
|
||||
"b": SpecialCard.Bai,
|
||||
"z": SpecialCard.Zhong,
|
||||
|
||||
@@ -12,8 +12,12 @@ def drag(
|
||||
) -> None:
|
||||
|
||||
pyautogui.moveTo(x=src[0] + offset[0], y=src[1] + offset[1])
|
||||
pyautogui.dragTo(x=dst[0] + offset[0], y=dst[1] + offset[1],
|
||||
duration=0.4, tween=lambda x: 0 if x < 0.5 else 1)
|
||||
pyautogui.dragTo(
|
||||
x=dst[0] + offset[0],
|
||||
y=dst[1] + offset[1],
|
||||
duration=0.4,
|
||||
tween=lambda x: 0 if x < 0.5 else 1,
|
||||
)
|
||||
|
||||
|
||||
def click(point: Tuple[int, int], offset: Tuple[int, int] = (0, 0)) -> None:
|
||||
@@ -22,6 +26,7 @@ def click(point: Tuple[int, int], offset: Tuple[int, int] = (0, 0)) -> None:
|
||||
time.sleep(0.2)
|
||||
pyautogui.mouseUp()
|
||||
|
||||
|
||||
def handle_action(
|
||||
action: board_actions.Action,
|
||||
offset: Tuple[int, int],
|
||||
@@ -68,7 +73,10 @@ def handle_action(
|
||||
index_x=0,
|
||||
index_y=dragon_sequence.index(action.dragon),
|
||||
)
|
||||
click((field_x + (size_x - field_x) // 2, field_y + (size_y - field_y) // 2), offset)
|
||||
click(
|
||||
(field_x + (size_x - field_x) // 2, field_y + (size_y - field_y) // 2),
|
||||
offset,
|
||||
)
|
||||
time.sleep(0.5)
|
||||
return
|
||||
if isinstance(action, board_actions.GoalAction):
|
||||
|
||||
@@ -3,15 +3,12 @@ from typing import List, Iterator, Optional
|
||||
from ..board import Board
|
||||
from . import board_actions
|
||||
from .board_possibilities import possible_actions
|
||||
from .board_actions import (
|
||||
MoveAction,
|
||||
GoalAction,
|
||||
HuaKillAction,
|
||||
DragonKillAction)
|
||||
from .board_actions import MoveAction, GoalAction, HuaKillAction, DragonKillAction
|
||||
|
||||
|
||||
class ActionStack:
|
||||
"""Stack of chosen actions on the board"""
|
||||
|
||||
iterator_stack: List[Iterator[board_actions.Action]]
|
||||
action_stack: List[Optional[board_actions.Action]]
|
||||
index_stack: List[int]
|
||||
@@ -61,15 +58,13 @@ def solve(board: Board) -> Iterator[List[board_actions.Action]]:
|
||||
stack.pop()
|
||||
assert stack.action_stack[-1] is not None
|
||||
stack.action_stack[-1].undo(board)
|
||||
assert (board.state_identifier
|
||||
in state_set)
|
||||
assert board.state_identifier in state_set
|
||||
|
||||
def _backtrack_action() -> None:
|
||||
stack.pop()
|
||||
assert stack.action_stack[-1] is not None
|
||||
stack.action_stack[-1].undo(board)
|
||||
assert (board.state_identifier
|
||||
in state_set)
|
||||
assert board.state_identifier in state_set
|
||||
|
||||
def _skip_loop_move(action: board_actions.Action) -> bool:
|
||||
if isinstance(action, MoveAction):
|
||||
@@ -88,8 +83,7 @@ def solve(board: Board) -> Iterator[List[board_actions.Action]]:
|
||||
|
||||
# _limit_stack_size(80)
|
||||
|
||||
assert (board.state_identifier ==
|
||||
stack.state_stack[-1])
|
||||
assert board.state_identifier == stack.state_stack[-1]
|
||||
action = stack.get()
|
||||
|
||||
if not action:
|
||||
@@ -105,9 +99,8 @@ def solve(board: Board) -> Iterator[List[board_actions.Action]]:
|
||||
yield stack.action_stack
|
||||
stack.action_stack[-1].undo(board)
|
||||
while isinstance(
|
||||
stack.action_stack[-1], (GoalAction,
|
||||
HuaKillAction,
|
||||
DragonKillAction)):
|
||||
stack.action_stack[-1], (GoalAction, HuaKillAction, DragonKillAction)
|
||||
):
|
||||
stack.pop()
|
||||
stack.action_stack[-1].undo(board)
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user