-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
103 lines (91 loc) · 3 KB
/
main.py
File metadata and controls
103 lines (91 loc) · 3 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import importlib
import os
import re
from gui import gui
from ressources import chessboard, pieces
from ressources.standard import start
class Game():
def __init__(self):
# self.playWithGui()
self.testMoves()
# self.playFromTurnlist("game2")
def playWithGui(self):
board = chessboard.Chessboard(8, 8)
board.initTest()
gui.GUI(board)
def testMoves(self):
board = chessboard.Chessboard(8, 8)
board.initTest2()
board.drawBoard()
# board.showAllMoves("w")
moves = board.getAllMoves("w")
for i in moves:
print(i)
def testCheck(self):
for _ in range(0, 10):
print("=== NEW TEST ===")
board = chessboard.Chessboard(8, 8)
board.initTest()
if board.inCheck("w"):
print("CHECK")
pass
else:
print("King is safe for now.")
pass
board.showAllMoves("w")
# board.drawBoard()
print("=== END OF TEST ===")
def testMate(self):
for _ in range(0, 10):
print("=== NEW TEST ===")
board = chessboard.Chessboard(8, 8)
board.initTest()
board.drawBoard()
if board.inCheckmate("w"):
# print("=== NEW TEST ===")
print("CHECKMATE")
# board.drawBoard()
elif board.inCheck("w"):
print("CHECK")
pass
else:
print("King is safe for now.")
pass
print("=== END OF TEST ===")
def testKingPositions(self):
for _ in range(0, 10):
board = chessboard.Chessboard(8, 8)
board.initTest()
board.drawBoard()
def importTurnlist(self, logfile):
# get file content
path = os.getcwd() + f"/ressources/replays/{logfile}.txt"
with open(path, "r", encoding="utf8") as log:
text = log.read()
# split between spaces and new lines
# [:-1] removes newline at the end of files
splitted = (re.split("[\s|\n]", text))[:-1]
if len(splitted) % 2 == 1:
raise ValueError(f"Something wrong with {logfile} file length")
turnlist = []
for i in range(len(splitted)):
if i % 2 == 0:
turnlist.append([splitted[i], splitted[i + 1]])
# loglist now list of [position, target] - lists moves
return text, turnlist
def playFromTurnlist(self, logfile):
text, turnlist = self.importTurnlist(logfile)
board = chessboard.Chessboard(8, 8)
board.initPieces()
board.drawBoard()
for move in turnlist:
print(*move)
board.movePiece(move[0], move[1])
board.drawBoard()
# board.showAllMoves("w")
if __name__ == '__main__':
importlib.reload(chessboard)
importlib.reload(pieces)
importlib.reload(start)
importlib.reload(gui)
game = Game()