Skip to content

Commit 46987f0

Browse files
Corrected some errors(not fully functional yet)
1 parent d4933ad commit 46987f0

File tree

8 files changed

+72
-44
lines changed

8 files changed

+72
-44
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
0
2-
20
2+
0
33
0

chessAnalyzer/Chess-Coordinate-Trainer-master/__init__.py

Whitespace-only changes.

chessAnalyzer/Chess-Coordinate-Trainer-master/chess_coordinate_trainer.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Made by Stephen Ryan. Github: stephen70
2+
import urllib.request
23

34
try:
45
from Tkinter import *
@@ -24,11 +25,22 @@
2425
os.makedirs(dataPath)
2526

2627
# find icon path
27-
iconPath = Path(PurePath(BASE_PATH, 'Icons'))
28-
windowIconPath = Path(PurePath(iconPath, 'CCT.ico'))
29-
aboutIconPath = Path(PurePath(iconPath, 'about.ico'))
30-
lbIconPath = Path(PurePath(iconPath, 'leaderboards.ico'))
31-
gearsIconPath = Path(PurePath(iconPath, 'gears.ico'))
28+
urllib.request.urlretrieve("https://raw.githubusercontent.com/stephen70/Chess-Coordinate-Trainer/master"
29+
"/Icons/CCT.ico",
30+
"CCT.ico")
31+
urllib.request.urlretrieve("https://raw.githubusercontent.com/stephen70/Chess-Coordinate-Trainer/master"
32+
"/Icons/about.ico",
33+
"about.ico")
34+
urllib.request.urlretrieve("https://raw.githubusercontent.com/stephen70/Chess-Coordinate-Trainer/master"
35+
"/Icons/gears.ico",
36+
"gears.ico")
37+
urllib.request.urlretrieve("https://raw.githubusercontent.com/stephen70/Chess-Coordinate-Trainer/master"
38+
"/Icons/leaderboards.ico",
39+
"leaderboards.ico")
40+
windowIconPath = Path(PurePath('CCT.ico'))
41+
aboutIconPath = Path(PurePath('about.ico'))
42+
lbIconPath = Path(PurePath('leaderboards.ico'))
43+
gearsIconPath = Path(PurePath('gears.ico'))
3244

3345
# initialise various variables used
3446
lbValues = []
@@ -234,7 +246,7 @@ def blackButtons():
234246
prefbutton = Button(menuframe, width=29, height=1, command=lambda: showoptions(), text="Preferences", bg="gray94")
235247
lbbutton = Button(menuframe, width=30, height=1, command=lambda: showLB(), text="Leaderboards", bg="gray94")
236248
aboutbutton = Button(menuframe, width=14, height=1, command=lambda: showAbout(), text="About", bg="gray94")
237-
exitbutton = Button(menuframe, width=12, height=1, command=sys.exit, text="Exit", bg="gray94")
249+
exitbutton = Button(menuframe, width=12, height=1, command=lambda: exit(), text="Exit", bg="gray94")
238250

239251
# place them in a grid layout
240252
startbutton.grid(row=0, column=0)
@@ -263,6 +275,14 @@ def blackButtons():
263275
newRecordLabel = Label(top, width=11, height=1, bg="gray80")
264276

265277

278+
def exit():
279+
os.remove('CCT.ico')
280+
os.remove('about.ico')
281+
os.remove('leaderboards.ico')
282+
os.remove('gears.ico')
283+
sys.exit()
284+
285+
266286
# when a new record is obtained, create a flashing "New Record!" label
267287
def newRecordChanger():
268288
global recordcolour

chessAnalyzer/Engine/__init__.py

Whitespace-only changes.

chessAnalyzer/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44

55
__email__ = "aryananand.chess@gmail.com"
66

7-
__version__ = "0.0.1"
7+
__version__ = "0.0.4"

chessAnalyzer/chess_graph.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def graph(pgn, engine, location):
99

1010
headers = chess.pgn.read_headers(open(pgn))
1111

12-
print('Analyzing this game_in_question: ' + headers["Event"] + " | " + headers["White"] +
12+
print('Analyzing this game: ' + headers["Event"] + " | " + headers["White"] +
1313
" - " + headers["Black"] + " " + headers["Result"] +
1414
" | " + headers["Date"])
1515

@@ -92,7 +92,7 @@ def rookending(fen):
9292
# Iterate through all moves and play them on a board.
9393
board = act_game.board()
9494

95-
print('Analyzing game_in_question...')
95+
print('Analyzing game...')
9696

9797
for move in act_game.mainline_moves():
9898
board.push(move)

chessAnalyzer/eco_codes/__init__.py

Whitespace-only changes.

chessAnalyzer/main.py

Lines changed: 42 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
import json
44
import math
55
import os
6+
import os.path
67
from typing import Dict, Any, Union
8+
import urllib.request
79

810
import chess
911
import chess.engine
@@ -56,28 +58,31 @@ def opening(game_in_question):
5658
ply_count = 0
5759
root_node = game_in_question.parent
5860
node = game_in_question.end()
59-
with open('eco_codes/eco.json', 'r') as eco_file:
60-
eco_data = json.load(eco_file)
61-
while not node == game_in_question.parent:
62-
prev_node = node.parent
61+
url = urllib.request.urlopen(
62+
"https://raw.githubusercontent.com/CoderAryanAnand/pythonChessAnalyzer/main/chessAnalyzer/eco_codes/eco"
63+
".json")
64+
content = url.read()
65+
eco_data = json.loads(content)
66+
while not node == game_in_question.parent:
67+
prev_node = node.parent
6368

64-
fen = eco_fen(node.board())
65-
classification = classify_fen(fen, eco_data)
69+
fen = eco_fen(node.board())
70+
classification = classify_fen(fen, eco_data)
6671

67-
if classification["code"] != "":
68-
# Add some comments classifying the opening
69-
node.comment = "{} {}".format(classification["code"],
70-
classification["desc"])
71-
# Remember this position so we don't analyze the moves
72-
# preceding it later
73-
root_node = node
74-
# Break (don't classify previous positions)
75-
break
72+
if classification["code"] != "":
73+
# Add some comments classifying the opening
74+
node.comment = "{} {}".format(classification["code"],
75+
classification["desc"])
76+
# Remember this position so we don't analyze the moves
77+
# preceding it later
78+
root_node = node
79+
# Break (don't classify previous positions)
80+
break
7681

77-
ply_count += 1
78-
node = prev_node
82+
ply_count += 1
83+
node = prev_node
7984

80-
return node.parent, root_node, ply_count
85+
return node.parent, root_node, ply_count
8186

8287

8388
def winning_chances(centipawns):
@@ -119,7 +124,10 @@ def __init__(self, eval_time: float, cwd: str, eng_file: str = 'Engine/Stockfish
119124
self.engine = chess.engine.SimpleEngine.popen_uci(self.eng_file)
120125
self.white_mvs, self.black_mvs, self.black_lpos, self.white_lpos = 0, 0, list(), list()
121126
self.current_working_directory = cwd
122-
os.mkdir(self.current_working_directory + '/Game Report')
127+
try:
128+
os.mkdir(self.current_working_directory + '/Game Report')
129+
except FileExistsError:
130+
pass
123131

124132
def get_eval(self, fen: str) -> float:
125133
"""
@@ -156,27 +164,27 @@ def get_best_var(self, fen: str, uci=False) -> list or str:
156164
else:
157165
return board.variation_san(result['pv'])
158166

159-
def create_graph(self, pgn_loc: str, loc: str):
167+
def graph(self, pgn_loc: str, loc: str):
160168
graph(pgn_loc, self.eng_file, location=loc)
161169

162170
def annotate_game(self, pgn_loc: str) -> chess.pgn.Game:
163171
"""
164-
Goes through the game_in_question and analyses and annotates it
172+
Goes through the game and analyses and annotates it
165173
"""
166-
# Read game_in_question and create starting position
174+
# Read game and create starting position
167175
pgn = chess.pgn.read_game(open(pgn_loc))
168176

169-
# Find out what opening the game_in_question has
177+
# Find out what opening the game has
170178
opening(pgn)
171179

172-
# Mark the end of the game_in_question
173-
pgn.end().comment = "End of game_in_question. " \
174-
"The moves after this one are just telling you how the game_in_question could have gone on."
180+
# Mark the end of the game
181+
pgn.end().comment = "End of game. " \
182+
"The moves after this one are just telling you how the game could have gone on."
175183
# Set variables for the loop
176184
# prev_eva = 0.00 # not needed anymore
177185
is_opening = True
178186

179-
# Iterate through the game_in_question
187+
# Iterate through the game
180188
for node in pgn.mainline():
181189
move = node.move
182190
board = node.board()
@@ -229,7 +237,7 @@ def annotate_game(self, pgn_loc: str) -> chess.pgn.Game:
229237
print(f'\n\n\n{bColors.WARNING}{bColors.BOLD}Use <print(pgn, file=open(pgn_loc, "w"), end="\\n\\n")> '
230238
f'to add the '
231239
f'annotations to '
232-
f'the game_in_question.\n\n{bColors.END_C}')
240+
f'the game.\n\n{bColors.END_C}')
233241
return pgn
234242

235243
@staticmethod
@@ -240,16 +248,16 @@ def train_coordinates():
240248

241249
def game_report(self, pgn_loc: str, annotate=False) -> tuple:
242250

243-
# Read game_in_question and create starting position
251+
# Read game and create starting position
244252
pgn = chess.pgn.read_game(open(pgn_loc))
245253

246254
board = chess.Board()
247255

248256
opening(pgn)
249257

250-
# Mark the end of the game_in_question
251-
pgn.end().comment = "End of game_in_question. " \
252-
"The moves after this one are just telling you how the game_in_question could have gone on."
258+
# Mark the end of the game
259+
pgn.end().comment = "End of game. " \
260+
"The moves after this one are just telling you how the game could have gone on."
253261
# Set variables for the loop
254262
is_opening = True
255263
self.white_mvs: Dict[str, Union[int, Any]] = {'Forced move': 0, 'Best move': 0, 'Excellent move': 0,
@@ -259,7 +267,7 @@ def game_report(self, pgn_loc: str, annotate=False) -> tuple:
259267
'Good move': 0, 'Interesting move': 0, 'Book move': 0,
260268
'Inaccuracy': 0, 'Mistake': 0, 'Blunder': 0}
261269

262-
# Iterate through the game_in_question
270+
# Iterate through the game
263271
for node in pgn.mainline():
264272
move = node.move
265273
lgl_mvs = len([i for i in board.legal_moves])
@@ -379,7 +387,7 @@ def game_report(self, pgn_loc: str, annotate=False) -> tuple:
379387
f.close()
380388

381389
loc = 'Game Report/%s/Graph/Graph of {}.html' % (headers["White"] + " vs " + headers["Black"])
382-
self.create_graph(pgn_loc, loc)
390+
self.graph(pgn_loc, loc)
383391
else:
384392
pass
385393

0 commit comments

Comments
 (0)