Formatting
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -12,7 +12,8 @@ import time
|
||||
|
||||
OFFSET = (0, 0)
|
||||
SIZE = (2560, 1440)
|
||||
NEW_BUTTON=(1900,1100)
|
||||
NEW_BUTTON = (1900, 1100)
|
||||
|
||||
|
||||
def debug_screenshot(image):
|
||||
cv2.namedWindow("Name", cv2.WINDOW_KEEPRATIO)
|
||||
@@ -21,9 +22,10 @@ def debug_screenshot(image):
|
||||
input()
|
||||
cv2.destroyAllWindows()
|
||||
|
||||
|
||||
def solve() -> None:
|
||||
screenshot_dir = Path(tempfile.mkdtemp())
|
||||
screenshot_file = screenshot_dir / 'screenshot.png'
|
||||
screenshot_file = screenshot_dir / "screenshot.png"
|
||||
screenshot = pyautogui.screenshot(region=(*OFFSET, *SIZE))
|
||||
screenshot.save(screenshot_file)
|
||||
image = cv2.imread(str(screenshot_file))
|
||||
@@ -38,10 +40,12 @@ def solve() -> None:
|
||||
time.sleep(1)
|
||||
for step in solution:
|
||||
print(step)
|
||||
#time.sleep(0.5)
|
||||
# time.sleep(0.5)
|
||||
clicker.handle_action(step, OFFSET, conf)
|
||||
clicker.click(NEW_BUTTON, OFFSET)
|
||||
time.sleep(10)
|
||||
|
||||
|
||||
def main() -> None:
|
||||
time.sleep(3)
|
||||
while True:
|
||||
|
||||
@@ -13,4 +13,3 @@ def main() -> None:
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
|
||||
@@ -15,7 +15,12 @@ def main() -> None:
|
||||
image = cv2.imread("pictures/specific/BaiShiny.jpg")
|
||||
|
||||
goal_adjustment = adjustment.adjust_squares(
|
||||
image, count_x=3, count_y=1, adjustment=adjustment.Adjustment(**{"x": 1490, "y": 310, "w": 19, "h": 21, "dx": 152, "dy": 0})
|
||||
image,
|
||||
count_x=3,
|
||||
count_y=1,
|
||||
adjustment=adjustment.Adjustment(
|
||||
**{"x": 1490, "y": 310, "w": 19, "h": 21, "dx": 152, "dy": 0}
|
||||
),
|
||||
)
|
||||
print(json.dumps(dataclasses.asdict(goal_adjustment)))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user