forked from drew-rwx/pattycake
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
59 lines (51 loc) · 1.6 KB
/
Copy pathtest.py
File metadata and controls
59 lines (51 loc) · 1.6 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import sys
from main import PATS_Approximator
from main import ff_line_match_first, ff_pattern_match_best, ff_pattern_match_first, ff_pattern_match_best_tile_limit, ff_pattern_match_first_tile_limit
#
# main
#
if __name__ == "__main__":
# python3 test.py [FF_NUMBER]
if len(sys.argv) < 2:
print("ERROR: Not enough arguments.")
print("python3 test.py [FF_NUMBER]")
quit()
generations = 2_000
population_size = 200
# patterns to try
pattern_files = ["patterns/checkerboard_4.txt",
"patterns/lines_4.txt",
"patterns/random_4.txt",
"patterns/random_5.txt"]
# extract pattern
patterns = []
for pf in pattern_files:
p = []
with open(pf, "r") as f:
data = f.read()
p = data.split()
patterns.append(p)
# fitness function
ff_num = int(sys.argv[1])
if ff_num == 1:
ff = ff_pattern_match_first
elif ff_num == 2:
ff = ff_pattern_match_best
elif ff_num == 3:
ff = ff_pattern_match_first_tile_limit
elif ff_num == 4:
ff = ff_pattern_match_best_tile_limit
elif ff_num == 5:
ff = ff_line_match_first
else:
ff = ff_pattern_match_first
for p in patterns:
pats = PATS_Approximator(p, population_size, ff)
print(f"ID: {pats.id}")
# run the algorithm
for g in range(generations):
pats.run_generation()
if g % 100 == 0:
print(f"Generation {g + 1} / {generations}")
if g % 10 == 0:
pats.write_data()