-
Notifications
You must be signed in to change notification settings - Fork 0
/
gui_chess.py
72 lines (46 loc) · 1.52 KB
/
gui_chess.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
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
# brew install pyqt
from PyQt5 import QtGui, QtSvg
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import QApplication, QWidget
import sys
import chess, chess.svg
from RandomAI import RandomAI
from MinimaxAI import MinimaxAI
from ChessGame import ChessGame
from HumanPlayer import HumanPlayer
import random
class ChessGui:
def __init__(self, player1, player2):
self.player1 = player1
self.player2 = player2
self.game = ChessGame(player1, player2)
self.app = QApplication(sys.argv)
self.svgWidget = QtSvg.QSvgWidget()
self.svgWidget.setGeometry(50, 50, 400, 400)
self.svgWidget.show()
def start(self):
self.timer = QTimer()
self.timer.timeout.connect(self.make_move)
self.timer.start(10)
self.display_board()
def display_board(self):
svgboard = chess.svg.board(self.game.board)
svgbytes = QByteArray()
svgbytes.append(svgboard)
self.svgWidget.load(svgbytes)
def make_move(self):
print("making move, white turn " + str(self.game.board.turn))
self.game.make_move()
self.display_board()
if __name__ == "__main__":
random.seed(1)
#player_ronda = RandomAI()
# to do: gui does not work well with HumanPlayer, due to input() use on stdin conflict
# with event loop.
player1 = RandomAI()
player2 = RandomAI()
game = ChessGame(player1, player2)
gui = ChessGui(player1, player2)
gui.start()
sys.exit(gui.app.exec_())