File tree Expand file tree Collapse file tree 1 file changed +20
-4
lines changed Expand file tree Collapse file tree 1 file changed +20
-4
lines changed Original file line number Diff line number Diff line change 5353
5454
5555APP_NAME = 'Python Easy Chess GUI'
56- APP_VERSION = 'v0.75 '
56+ APP_VERSION = 'v0.76 '
5757BOX_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
You can’t perform that action at this time.
0 commit comments