forked from Underflow/reinforcement-2048
-
Notifications
You must be signed in to change notification settings - Fork 0
/
2048.py
executable file
·41 lines (30 loc) · 873 Bytes
/
2048.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
#! env python2.7
import sys
import os
import time
from ai import AI
from browser import Browser
from PySide.QtCore import *
from PySide.QtGui import *
class Game:
def __init__(self):
self.browser = Browser()
self.app = QApplication(sys.argv)
self.timer = QTimer()
self.timer.timeout.connect(self.updateEvent)
self.ai = AI()
self.last_score = 1
def run(self, delay):
self.timer.start(delay)
self.browser.run()
return self.app.exec_()
def updateEvent(self):
self.timer.stop()
(score, board) = self.browser.extractData()
if self.last_score > score:
self.ai.restart_game()
self.last_score = score
self.browser.sendMove(self.ai.get_move(score, board))
self.timer.start() # restart the event loop
game = Game()
game.run(10)