-
Notifications
You must be signed in to change notification settings - Fork 0
/
Play_Game2048.py
46 lines (40 loc) · 1.32 KB
/
Play_Game2048.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
# Game 2048: Manual play
# Instructions:
# Move up, down, left, or right to merge the tiles. The objective is to
# get a tile with the number 2048 (or higher)
#
# Control:
# arrows : Merge up, down, left, or right
# r : Restart game
# q / ESC : Quit
from Game2048 import Game2048
import numpy as np
import pygame
env = Game2048()
env.reset()
actions = ['left', 'right', 'up', 'down']
exit_program = False
action_taken = False
while not exit_program:
env.render()
# Process game events
for event in pygame.event.get():
if event.type == pygame.QUIT:
exit_program = True
if event.type == pygame.KEYDOWN:
if event.key in [pygame.K_ESCAPE, pygame.K_q]:
exit_program = True
if event.key == pygame.K_UP:
action, action_taken = 'up', True
if event.key == pygame.K_DOWN:
action, action_taken = 'down', True
if event.key == pygame.K_RIGHT:
action, action_taken = 'right', True
if event.key == pygame.K_LEFT:
action, action_taken = 'left', True
if event.key == pygame.K_r:
env.reset()
if action_taken:
(board, score), reward, done = env.step(action)
action_taken = False
env.close()