-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_interpreter.py
47 lines (36 loc) · 1.22 KB
/
test_interpreter.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
from selenium.webdriver.common.keys import Keys
import interpreter
import random
def random_moves(print_every=20):
"""
Plays a game of 2048 by choosing moves randomly.
Input: print_every - how often to print the game state (# of moves made,
score, and board state). Set to 0 to not print at all.
"""
game = interpreter.Interpreter2048()
game.open()
move_count = 0
while True:
move_count += 1
keys = [Keys.UP, Keys.DOWN, Keys.LEFT, Keys.RIGHT]
game.input_key(keys[random.randrange(4)])
if print_every != 0 and move_count % print_every == 0:
print 'moves:', move_count
print 'score:', game.current_score()
print game.read_tiles()
if game.is_game_over():
break
print 'total # of moves:', move_count
print 'final score:', game.current_score()
print game.read_tiles()
game.close()
def one_move():
game = interpreter.Interpreter2048()
game.open()
print game.read_tiles()
print 'score:', game.current_score()
print 'input: UP'
game.input_key(Keys.UP)
print game.read_tiles()
print 'score:', game.current_score()
game.close()