Skip to content

Commit 9b08830

Browse files
committed
Update python_easy_chess_gui.py
* Add weight column in book1 and book2 boxes.
1 parent e0ea9f1 commit 9b08830

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

python_easy_chess_gui.py

+20-4
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353

5454

5555
APP_NAME = 'Python Easy Chess GUI'
56-
APP_VERSION = 'v0.75'
56+
APP_VERSION = 'v0.76'
5757
BOX_TITLE = '{} {}'.format(APP_NAME, APP_VERSION)
5858

5959

@@ -245,15 +245,31 @@ def get_book_move(self):
245245

246246
def get_all_moves(self):
247247
is_found = False
248+
total_score = 0
249+
book_data = {}
250+
cnt = 0
251+
248252
if os.path.isfile(self.book_file):
249-
moves = '{:5s} {:<}\n'.format('move', 'score')
253+
moves = '{:4s} {:<5s} {}\n'.format('move', 'score', 'weight')
250254
with chess.polyglot.open_reader(self.book_file) as reader:
251255
for entry in reader.find_all(self.board):
252256
is_found = True
253257
san_move = self.board.san(entry.move)
254-
moves += '{:5s} {:<}\n'.format(san_move, entry.weight)
258+
score = entry.weight
259+
total_score += score
260+
bd = {cnt: {'move': san_move, 'score': score}}
261+
book_data.update(bd)
262+
cnt += 1
255263
else:
256-
moves = '{:5s} {:<}\n'.format('move', 'score')
264+
moves = '{:4s} {:<}\n'.format('move', 'score')
265+
266+
# Get weight for each move
267+
if is_found:
268+
for _, v in book_data.items():
269+
move = v['move']
270+
score = v['score']
271+
weight = score/total_score
272+
moves += '{:4s} {:<5d} {:<2.1f}%\n'.format(move, score, 100*weight)
257273

258274
return moves, is_found
259275

0 commit comments

Comments
 (0)