Skip to content

Commit

Permalink
Update python_easy_chess_gui.py
Browse files Browse the repository at this point in the history
* Add weight column in book1 and book2 boxes.
  • Loading branch information
fsmosca committed Jun 19, 2019
1 parent e0ea9f1 commit 9b08830
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions python_easy_chess_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@


APP_NAME = 'Python Easy Chess GUI'
APP_VERSION = 'v0.75'
APP_VERSION = 'v0.76'
BOX_TITLE = '{} {}'.format(APP_NAME, APP_VERSION)


Expand Down Expand Up @@ -245,15 +245,31 @@ def get_book_move(self):

def get_all_moves(self):
is_found = False
total_score = 0
book_data = {}
cnt = 0

if os.path.isfile(self.book_file):
moves = '{:5s} {:<}\n'.format('move', 'score')
moves = '{:4s} {:<5s} {}\n'.format('move', 'score', 'weight')
with chess.polyglot.open_reader(self.book_file) as reader:
for entry in reader.find_all(self.board):
is_found = True
san_move = self.board.san(entry.move)
moves += '{:5s} {:<}\n'.format(san_move, entry.weight)
score = entry.weight
total_score += score
bd = {cnt: {'move': san_move, 'score': score}}
book_data.update(bd)
cnt += 1
else:
moves = '{:5s} {:<}\n'.format('move', 'score')
moves = '{:4s} {:<}\n'.format('move', 'score')

# Get weight for each move
if is_found:
for _, v in book_data.items():
move = v['move']
score = v['score']
weight = score/total_score
moves += '{:4s} {:<5d} {:<2.1f}%\n'.format(move, score, 100*weight)

return moves, is_found

Expand Down

0 comments on commit 9b08830

Please sign in to comment.