Formatting
This commit is contained in:
@@ -26,6 +26,7 @@ def get_field_squares(
|
|||||||
squares.append(get_square(adjustment, index_x, index_y))
|
squares.append(get_square(adjustment, index_x, index_y))
|
||||||
return _extract_squares(image, squares)
|
return _extract_squares(image, squares)
|
||||||
|
|
||||||
|
|
||||||
def catalogue_cards(squares: List[np.ndarray]) -> List[Tuple[np.ndarray, Card]]:
|
def catalogue_cards(squares: List[np.ndarray]) -> List[Tuple[np.ndarray, Card]]:
|
||||||
"""Run manual cataloging for given squares"""
|
"""Run manual cataloging for given squares"""
|
||||||
cv2.namedWindow("Catalogue", cv2.WINDOW_NORMAL)
|
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]] = []
|
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("Card ID is [B]ai, [Z]hong, [F]a, [H]ua, [R]ed, [G]reen, [B]lack")
|
||||||
print("Numbercard e.g. R3")
|
print("Numbercard e.g. R3")
|
||||||
abort_row = 'a'
|
abort_row = "a"
|
||||||
special_card_map = {
|
special_card_map = {
|
||||||
"b": SpecialCard.Bai,
|
"b": SpecialCard.Bai,
|
||||||
"z": SpecialCard.Zhong,
|
"z": SpecialCard.Zhong,
|
||||||
|
|||||||
@@ -12,8 +12,12 @@ def drag(
|
|||||||
) -> None:
|
) -> None:
|
||||||
|
|
||||||
pyautogui.moveTo(x=src[0] + offset[0], y=src[1] + offset[1])
|
pyautogui.moveTo(x=src[0] + offset[0], y=src[1] + offset[1])
|
||||||
pyautogui.dragTo(x=dst[0] + offset[0], y=dst[1] + offset[1],
|
pyautogui.dragTo(
|
||||||
duration=0.4, tween=lambda x: 0 if x < 0.5 else 1)
|
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:
|
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)
|
time.sleep(0.2)
|
||||||
pyautogui.mouseUp()
|
pyautogui.mouseUp()
|
||||||
|
|
||||||
|
|
||||||
def handle_action(
|
def handle_action(
|
||||||
action: board_actions.Action,
|
action: board_actions.Action,
|
||||||
offset: Tuple[int, int],
|
offset: Tuple[int, int],
|
||||||
@@ -68,7 +73,10 @@ def handle_action(
|
|||||||
index_x=0,
|
index_x=0,
|
||||||
index_y=dragon_sequence.index(action.dragon),
|
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)
|
time.sleep(0.5)
|
||||||
return
|
return
|
||||||
if isinstance(action, board_actions.GoalAction):
|
if isinstance(action, board_actions.GoalAction):
|
||||||
|
|||||||
@@ -3,15 +3,12 @@ from typing import List, Iterator, Optional
|
|||||||
from ..board import Board
|
from ..board import Board
|
||||||
from . import board_actions
|
from . import board_actions
|
||||||
from .board_possibilities import possible_actions
|
from .board_possibilities import possible_actions
|
||||||
from .board_actions import (
|
from .board_actions import MoveAction, GoalAction, HuaKillAction, DragonKillAction
|
||||||
MoveAction,
|
|
||||||
GoalAction,
|
|
||||||
HuaKillAction,
|
|
||||||
DragonKillAction)
|
|
||||||
|
|
||||||
|
|
||||||
class ActionStack:
|
class ActionStack:
|
||||||
"""Stack of chosen actions on the board"""
|
"""Stack of chosen actions on the board"""
|
||||||
|
|
||||||
iterator_stack: List[Iterator[board_actions.Action]]
|
iterator_stack: List[Iterator[board_actions.Action]]
|
||||||
action_stack: List[Optional[board_actions.Action]]
|
action_stack: List[Optional[board_actions.Action]]
|
||||||
index_stack: List[int]
|
index_stack: List[int]
|
||||||
@@ -61,15 +58,13 @@ def solve(board: Board) -> Iterator[List[board_actions.Action]]:
|
|||||||
stack.pop()
|
stack.pop()
|
||||||
assert stack.action_stack[-1] is not None
|
assert stack.action_stack[-1] is not None
|
||||||
stack.action_stack[-1].undo(board)
|
stack.action_stack[-1].undo(board)
|
||||||
assert (board.state_identifier
|
assert board.state_identifier in state_set
|
||||||
in state_set)
|
|
||||||
|
|
||||||
def _backtrack_action() -> None:
|
def _backtrack_action() -> None:
|
||||||
stack.pop()
|
stack.pop()
|
||||||
assert stack.action_stack[-1] is not None
|
assert stack.action_stack[-1] is not None
|
||||||
stack.action_stack[-1].undo(board)
|
stack.action_stack[-1].undo(board)
|
||||||
assert (board.state_identifier
|
assert board.state_identifier in state_set
|
||||||
in state_set)
|
|
||||||
|
|
||||||
def _skip_loop_move(action: board_actions.Action) -> bool:
|
def _skip_loop_move(action: board_actions.Action) -> bool:
|
||||||
if isinstance(action, MoveAction):
|
if isinstance(action, MoveAction):
|
||||||
@@ -88,8 +83,7 @@ def solve(board: Board) -> Iterator[List[board_actions.Action]]:
|
|||||||
|
|
||||||
# _limit_stack_size(80)
|
# _limit_stack_size(80)
|
||||||
|
|
||||||
assert (board.state_identifier ==
|
assert board.state_identifier == stack.state_stack[-1]
|
||||||
stack.state_stack[-1])
|
|
||||||
action = stack.get()
|
action = stack.get()
|
||||||
|
|
||||||
if not action:
|
if not action:
|
||||||
@@ -105,9 +99,8 @@ def solve(board: Board) -> Iterator[List[board_actions.Action]]:
|
|||||||
yield stack.action_stack
|
yield stack.action_stack
|
||||||
stack.action_stack[-1].undo(board)
|
stack.action_stack[-1].undo(board)
|
||||||
while isinstance(
|
while isinstance(
|
||||||
stack.action_stack[-1], (GoalAction,
|
stack.action_stack[-1], (GoalAction, HuaKillAction, DragonKillAction)
|
||||||
HuaKillAction,
|
):
|
||||||
DragonKillAction)):
|
|
||||||
stack.pop()
|
stack.pop()
|
||||||
stack.action_stack[-1].undo(board)
|
stack.action_stack[-1].undo(board)
|
||||||
continue
|
continue
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ OFFSET = (0, 0)
|
|||||||
SIZE = (2560, 1440)
|
SIZE = (2560, 1440)
|
||||||
NEW_BUTTON = (1900, 1100)
|
NEW_BUTTON = (1900, 1100)
|
||||||
|
|
||||||
|
|
||||||
def debug_screenshot(image):
|
def debug_screenshot(image):
|
||||||
cv2.namedWindow("Name", cv2.WINDOW_KEEPRATIO)
|
cv2.namedWindow("Name", cv2.WINDOW_KEEPRATIO)
|
||||||
cv2.imshow("Name", image)
|
cv2.imshow("Name", image)
|
||||||
@@ -21,9 +22,10 @@ def debug_screenshot(image):
|
|||||||
input()
|
input()
|
||||||
cv2.destroyAllWindows()
|
cv2.destroyAllWindows()
|
||||||
|
|
||||||
|
|
||||||
def solve() -> None:
|
def solve() -> None:
|
||||||
screenshot_dir = Path(tempfile.mkdtemp())
|
screenshot_dir = Path(tempfile.mkdtemp())
|
||||||
screenshot_file = screenshot_dir / 'screenshot.png'
|
screenshot_file = screenshot_dir / "screenshot.png"
|
||||||
screenshot = pyautogui.screenshot(region=(*OFFSET, *SIZE))
|
screenshot = pyautogui.screenshot(region=(*OFFSET, *SIZE))
|
||||||
screenshot.save(screenshot_file)
|
screenshot.save(screenshot_file)
|
||||||
image = cv2.imread(str(screenshot_file))
|
image = cv2.imread(str(screenshot_file))
|
||||||
@@ -42,6 +44,8 @@ def solve() -> None:
|
|||||||
clicker.handle_action(step, OFFSET, conf)
|
clicker.handle_action(step, OFFSET, conf)
|
||||||
clicker.click(NEW_BUTTON, OFFSET)
|
clicker.click(NEW_BUTTON, OFFSET)
|
||||||
time.sleep(10)
|
time.sleep(10)
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
time.sleep(3)
|
time.sleep(3)
|
||||||
while True:
|
while True:
|
||||||
|
|||||||
@@ -13,4 +13,3 @@ def main() -> None:
|
|||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,12 @@ def main() -> None:
|
|||||||
image = cv2.imread("pictures/specific/BaiShiny.jpg")
|
image = cv2.imread("pictures/specific/BaiShiny.jpg")
|
||||||
|
|
||||||
goal_adjustment = adjustment.adjust_squares(
|
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)))
|
print(json.dumps(dataclasses.asdict(goal_adjustment)))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user