-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStrategyTest.py
More file actions
93 lines (83 loc) · 2.31 KB
/
StrategyTest.py
File metadata and controls
93 lines (83 loc) · 2.31 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
from Bot.Strategies.OurStrategy import OurStrategy
from Bot.Game.Field import Field
from Bot.Game import Piece
# field = map(lambda r: map(lambda x: int(x), r.split(",")), field.split(";"))
# for line in field:
# print(line)
field = """
0,0,0,0,0,0,0,0,0,0;
0,0,0,0,0,0,0,0,0,0;
0,0,0,0,0,0,0,0,0,0;
0,0,0,0,0,0,0,0,0,0;
0,0,0,0,0,0,0,0,0,0;
0,0,0,0,0,0,0,0,0,0;
0,0,0,0,0,0,0,0,0,0;
0,0,0,0,0,0,0,0,0,0;
0,0,0,0,0,0,0,0,0,0;
0,0,0,0,0,0,0,0,0,0;
0,0,0,0,0,0,0,0,0,0;
0,0,0,0,0,0,0,0,0,0;
0,0,0,0,0,0,0,0,0,0;
0,0,0,0,0,0,0,0,0,0;
0,0,0,0,0,0,0,0,0,0;
0,0,0,0,0,0,0,0,0,0;
0,0,0,0,0,0,0,0,0,0;
0,0,0,0,0,0,0,0,0,0;
0,0,0,0,0,0,0,0,0,0;
0,0,0,0,0,0,0,0,0,0"""
initialField = map(lambda r: map(lambda x: int(x), r.split(",")), field.split(";"))
piece = Piece.create("L")
print(piece.positions())
fieldObj = Field()
fieldObj.updateField(initialField)
bestScore = -float("inf")
offset = 0
rotation = 0
for i in range(0, len(piece._rotations)):
print("")
for x in range(0, fieldObj.width):
fieldObj.updateField(initialField)
field = fieldObj.projectPieceDown(piece, [x, 0])
if not field is None:
# for line in field:
# print(line)
fieldObj.updateField(field)
a = -0.510066
b = 0.760666
c = -0.35663
d = -0.184483
result = a * (fieldObj.aggregateHeight()) + b * (fieldObj.completLine()) + c * (fieldObj.numberOfHole()) + d * (fieldObj.bumpiness())
if result > bestScore:
bestScore = result
offset = x
rotation = i
piece.turnRight()
fieldObj.updateField(initialField)
piece = Piece.create("L")
piece.turnRight(rotation)
field = fieldObj.projectPieceDown(piece, [offset, 0])
for line in field:
print(line)
#print(fieldObj.heights())
#print(OurStrategy.aggregateHeight(fieldObj))
# field = """
# 0,0,0,0,1,1,0,0,0,0;
# 0,0,0,0,0,0,0,0,0,0;
# 0,0,0,0,0,0,0,0,0,0;
# 0,0,0,0,0,0,0,0,0,0;
# 0,0,0,0,0,0,0,0,0,0;
# 0,0,0,0,0,0,0,0,0,0;
# 0,0,0,0,0,0,0,0,0,0;
# 0,0,0,0,0,0,0,0,0,0;
# 0,0,0,0,0,0,0,0,0,0;
# 0,0,0,0,0,0,0,0,0,0;
# 0,0,0,0,0,0,0,0,0,0;
# 0,0,0,0,0,0,0,0,0,0;
# 0,0,0,0,0,0,0,0,0,0;
# 0,0,0,0,0,0,0,0,0,0;
# 0,0,0,0,0,0,0,0,0,0;
# 0,0,0,0,1,1,0,0,0,0;
# 0,0,0,0,1,1,0,0,0,1;
# 0,0,1,0,1,1,0,1,0,1;
# 0,1,1,1,1,1,0,1,0,1;
# 1,1,1,1,1,1,1,1,0,1"""