forked from vnum/marvel-snap-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathturn.py
More file actions
40 lines (38 loc) · 1.38 KB
/
Copy pathturn.py
File metadata and controls
40 lines (38 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from utils import global_utils
import os
import cv2
import config
import random
# Give a screenshot, returns the player turn
def get_turn(screenshot, screenshot_dimensions, show_image):
start = global_utils.start_timer()
config_turn = config.turn
actual_turn = 0
turn = screenshot[
config_turn['y1']:
screenshot_dimensions[0] -
config_turn['y2'],
config_turn['x1']:
screenshot_dimensions[1] -
config_turn['x2']
]
for turn_haystack in os.listdir(config.turns_folder):
# Searching for a field in the folder.
searched_turn = global_utils.search(
config.turns_folder+"\\"+turn_haystack, turn, 1)
if searched_turn[0] == 1:
searched_turn_image = global_utils.draw(
turn, searched_turn, turn_haystack[:-4], [random.randint(100, 255), random.randint(100, 255), random.randint(100, 255)])
if show_image:
cv2.imshow('turn', searched_turn_image)
if turn_haystack[0] != 'f' and turn_haystack[0] != "c":
if int(turn_haystack[0]) > actual_turn:
actual_turn = int(turn_haystack[0])
elif turn_haystack[0] == 'f':
return -1
else:
return -2
end = global_utils.end_timer()
global_utils.log_time_elapsed(
"get_turn", end-start)
return actual_turn