-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsimulate_.py
More file actions
69 lines (65 loc) · 2.47 KB
/
simulate_.py
File metadata and controls
69 lines (65 loc) · 2.47 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
from bot_ import Bot
import position_
import field_
import copy
class Simulate():
def __init__(self):
self.cnt_moves=0
self.cnt_cleared_lines=0
self.round=0
self.score=0
self.combo=0
def runGame(self):
bot=Bot()
field=copy.deepcopy(field_.pos.field)
print 'Current piece: ', field_.pos.currentPiece
print 'Next piece:', field_.pos.nextPiece
while True:
try:
moves=bot.build_tree2(field_.pos, field_.pos.currentPiece)
best_position=bot.evaluate_pos(moves,bot, field_.pos, field_.pos.currentPiece)
action_moves=bot.get_moves(best_position, bot)
move=position_.Position(field_.pos, field_.pos.currentPiece, field_.pos.nextPiece)
field_.pos.prot=best_position[0]
clears=move.from_tree_node(best_position)
if clears==2:
self.score+=3
if self.combo>0:
self.combo+=1
self.score=self.score+self.combo-1
else:
self.combo+=1
elif clears==3:
self.score+=6
if self.combo>0:
self.combo+=1
self.score=self.score+self.combo-1
else:
self.combo+=1
elif clears==4:
self.score+=10
if self.combo>0:
self.combo+=1
self.score=self.score+self.combo-1
else:
self.combo+=1
else:
self.combo=0
field_.pos.print_pos()
print 'Best position', best_position, 'Action moves', action_moves
field_.pos.currentPiece=move.nextPiece
field_.pos.nextPiece=field_.pos.getNextPiece()
self.cnt_moves+=1
self.cnt_cleared_lines+=clears
self.round+=1
if self.round==15:
field_.pos.insert_row()
self.round=0
else:
pass
except IndexError:
field_.pos.field=field
print 'score', self.score
print 'combo', self.combo
return self.cnt_moves, self.cnt_cleared_lines
#Simulate().runGame()