5353
5454
5555APP_NAME = 'Python Easy Chess GUI'
56- APP_VERSION = 'v0.62 '
56+ APP_VERSION = 'v0.63 '
5757BOX_TITLE = '{} {}' .format (APP_NAME , APP_VERSION )
5858
5959
@@ -313,6 +313,7 @@ def run(self):
313313 with self .engine .analysis (self .board , chess .engine .Limit (
314314 time = self .max_time , depth = self .max_depth )) as analysis :
315315 for info in analysis :
316+
316317 try :
317318 if 'depth' in info :
318319 self .depth = int (info ['depth' ])
@@ -377,10 +378,11 @@ class EasyChessGui():
377378 is_user_white = True # White is at the bottom in board layout
378379
379380 def __init__ (self , gui_book_file , is_use_gui_book , is_random_book ,
380- max_depth , max_time_sec , threads = 1 , memory_mb = 16 ):
381+ max_book_ply , max_depth , max_time_sec , threads = 1 , memory_mb = 16 ):
381382 self .max_depth = max_depth
382383 self .is_use_gui_book = is_use_gui_book
383384 self .is_random_book = is_random_book
385+ self .max_book_ply = max_book_ply
384386 self .max_time = max_time_sec
385387 self .threads = threads
386388 self .hash = memory_mb
@@ -1191,7 +1193,7 @@ def play_game(self, engine_id_name, board):
11911193 is_book_from_gui = True
11921194
11931195 # If using gui book
1194- if self .is_use_gui_book :
1196+ if self .is_use_gui_book and move_cnt <= self . max_book_ply :
11951197 # Verify presence of a book file
11961198 if os .path .isfile (self .gui_book_file ):
11971199 gui_book = GuiBook (self .gui_book_file , board , self .is_random_book )
@@ -1623,10 +1625,15 @@ def main_loop(self):
16231625 # the user presses cancel or X button
16241626 current_is_use_gui_book = self .is_use_gui_book
16251627 current_is_random_book = self .is_random_book
1628+ current_max_book_ply = self .max_book_ply
16261629
16271630 layout = [
1628- [sg .T ('GUI book' ), sg .T (self .gui_book_file ,
1631+ [sg .T ('Book File' , size = ( 8 , 1 ) ), sg .T (self .gui_book_file ,
16291632 size = (24 , 1 ), relief = 'sunken' )],
1633+ [sg .T ('Max Ply' , size = (8 , 1 )),
1634+ sg .Spin ([t for t in range (1 , 33 , 1 )],
1635+ initial_value = self .max_book_ply ,
1636+ size = (6 , 1 ), key = 'book_ply_k' )],
16301637 [sg .CBox ('GUI book' , key = 'use_gui_book_k' ,
16311638 default = self .is_use_gui_book )],
16321639 [sg .Radio ('Best move' , 'Book Radio' ,
@@ -1647,16 +1654,19 @@ def main_loop(self):
16471654 if e is None :
16481655 self .is_use_gui_book = current_is_use_gui_book
16491656 self .is_random_book = current_is_random_book
1657+ self .max_book_ply = current_max_book_ply
16501658 logging .info ('Book setting is exited.' )
16511659 break
16521660
16531661 if e == 'Cancel' :
16541662 self .is_use_gui_book = current_is_use_gui_book
16551663 self .is_random_book = current_is_random_book
1664+ self .max_book_ply = current_max_book_ply
16561665 logging .info ('Book setting is cancelled.' )
16571666 break
16581667
16591668 if e == 'OK' :
1669+ self .max_book_ply = int (v ['book_ply_k' ])
16601670 self .is_use_gui_book = v ['use_gui_book_k' ]
16611671 self .is_random_book = v ['random_move_k' ]
16621672 logging .info ('Book setting is OK' )
@@ -1733,9 +1743,10 @@ def main():
17331743 pecg_book = 'book/pecg_book.bin'
17341744 is_use_gui_book = True
17351745 is_random_book = True # If false then use best book move
1746+ max_book_ply = 8
17361747
17371748 pecg = EasyChessGui (pecg_book , is_use_gui_book , is_random_book ,
1738- max_depth , max_time_sec )
1749+ max_book_ply , max_depth , max_time_sec )
17391750 pecg .main_loop ()
17401751
17411752
0 commit comments