-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpattern_gen.py
74 lines (65 loc) · 3.03 KB
/
pattern_gen.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
def ship_search(period, x, y, dx, dy, symmetry, transform, nrange, pattern_file):
"""Generates a pattern file for a ship search"""
origin_x = x # Store original values
origin_y = y
x += nrange * 2 # Adding borders
y += nrange * 2
file = open(pattern_file, "w+")
for t in range(period + 1):
for i in range(nrange): # Write in the border
file.write("0 " * (x + dx) + "\n")
num_vars = 0
for i in range(y - nrange * 2 + dy):
file.write("0 " * nrange)
if (symmetry == "D2|" or symmetry == "D4+") and ((i > 0 and t == 0) or (i > dy and t == period)):
num_vars += origin_x // 2 + 2
if symmetry == "D2-" or symmetry == "D4+":
if origin_y % 2: # If odd
if i <= origin_y // 2:
num_vars = i * origin_x
elif i > origin_y // 2:
num_vars = (origin_y - i - 1) * origin_x
else: # If even
if i <= origin_y // 2 - 1:
num_vars = i * origin_x
elif i > origin_y // 2 - 1:
num_vars = (origin_y - i - 1) * origin_x
elif transform == "Flip|" and t == period:
num_vars = (i + 1 - dy) * origin_x - 1
for j in range(x - nrange * 2 + dx):
if t == 0 and i < origin_y and j < origin_x:
if symmetry == "D2|" or symmetry == "D4+":
file.write(f"a{num_vars} ")
if origin_x % 2: # If odd
num_vars += 1 if j < origin_x // 2 else -1
else: # If even
if j < origin_x // 2 - 1:
num_vars += 1
elif j > origin_x // 2 - 1:
num_vars -= 1
else:
file.write(f"a{num_vars} ")
num_vars += 1
elif t == period and i >= dy and j >= dx:
if symmetry == "D2|" or symmetry == "D4+":
file.write(f"a{num_vars} ")
if origin_x % 2: # If odd
num_vars += 1 if j < origin_x // 2 else -1
else: # If even
if j < origin_x // 2 - 1:
num_vars += 1
elif j > origin_x // 2 - 1:
num_vars -= 1
else:
file.write(f"a{num_vars} ")
if transform == "Flip|": num_vars -= 1
else: num_vars += 1
elif t != 0 and t != period:
file.write("* ")
else:
file.write("0 ")
file.write("0 " * nrange + "\n")
for i in range(nrange): # Write in the border
file.write("0 " * (x + dx) + "\n")
file.write("\n")
file.close()