-
Notifications
You must be signed in to change notification settings - Fork 4
/
my_rules.py
70 lines (51 loc) · 1.57 KB
/
my_rules.py
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
from common import Point, Debugger, repr_direction
debug = Debugger(enable_log=False)
class StragiticStatus:
def __init__(self):
self.a = 0
self.a_point = []
self.b = 0
self.b_point = []
# 8방향
DIRECTIONS = [
(1, 0),
(1, 1),
(1, -1),
(0, 1),
(0, -1),
(-1, 0),
(-1, 1),
(-1, -1)
]
def reverse_of(dir):
dx, dy = dir
return (-dx, -dy)
def is_outta_range(x, y):
return x < 0 or x >= 19 or y < 0 or y >= 19
def track(board, start_x, start_y, dir_func):
pass
def scan_from_last(board, last_points, player):
for point in last_points:
x, y = point
# check 8 directions and start backtracking.
for dir in DIRECTIONS:
dx, dy = dir
nx, ny = x+dx, y+dy
if is_outta_range(nx, ny): continue
if board[ny][nx] == board[y][x]:
debug.log('Direction {}'.format(dir))
debug.log('Start at {}'.format(Point(x, y)))
# to check properly, go to the end of direction
while board[ny][nx] == board[y][x]:
nx += dx
ny += dy
if is_outta_range(nx, ny): break
dx, dy = reverse_of(dir)
debug.log('End of direction : {}'.format(Point(nx, ny)))
is_end = track(board, nx, ny, reverse_of(dir))
if is_end:
# returns player who won.
return board[ny][nx]
debug.stop()
def scan_full(board) -> StragiticStatus:
pass