-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmarker_array.py
76 lines (67 loc) · 2.5 KB
/
marker_array.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
71
72
73
74
75
from itertools import product
import numpy as np
import random
def marker_generator(r, c):
marker_set = [1, 2, 3, 4]
format = list(product(marker_set, marker_set, marker_set, marker_set))
used_format = (np.ones(256, dtype=int) * -1).tolist()
board = (np.ones((8, 12), dtype=int) * -1).tolist()
r = 0
while r < 7:
c = 0
while c < 11:
square = [board[r][c], board[r][c+1], board[r+1][c], board[r+1][c+1]]
if -1 not in square:
c += 1
continue
filled_pos = [i for i, value in enumerate(square) if value != -1]
possible_markers = []
for fmt in format:
check = [0] * len(filled_pos)
for i, f in enumerate(filled_pos):
if fmt[f] == square[f]:
check[i] = 1
if sum(check) == len(filled_pos):
possible_markers.append(fmt)
cnt = 0
find_marker_rc = False
while cnt <= len(possible_markers):
marker_rc = possible_markers[random.randrange(len(possible_markers))]
if used_format[format.index(marker_rc)] == -1:
used_format[format.index(marker_rc)] = 1
find_marker_rc = True
break
else:
cnt += 1
if find_marker_rc:
board[r][c], board[r][c+1], board[r+1][c], board[r+1][c+1] = marker_rc
print(r, c, ':', board[r][c], board[r][c + 1], board[r + 1][c], board[r + 1][c + 1])
c += 1
else:
if c == 0:
r -= 1
c = 11
else:
c -= 1
print(r, c, ': Duplicate!', board[r][c], board[r][c + 1], board[r + 1][c], board[r + 1][c + 1])
used_format[format.index((board[r][c], board[r][c+1], board[r+1][c], board[r+1][c+1]))] = -1
board[r][c], board[r][c+1], board[r+1][c], board[r+1][c+1] = -1, -1, -1, -1
r += 1
return board
if __name__ == "__main__":
board = marker_generator(8, 12)
l = []
s = True
for r in range(7):
for c in range(11):
square = (board[r][c], board[r][c+1], board[r+1][c], board[r+1][c+1])
if square in l:
s = False
break
l.append(square)
if not s:
break
if s:
print('perfect')
else:
print('wrong')