|
53 | 53 |
|
54 | 54 |
|
55 | 55 | APP_NAME = 'Python Easy Chess GUI' |
56 | | -APP_VERSION = 'v0.64' |
| 56 | +APP_VERSION = 'v0.65' |
57 | 57 | BOX_TITLE = '{} {}'.format(APP_NAME, APP_VERSION) |
58 | 58 |
|
59 | 59 |
|
|
206 | 206 | menu_def_neutral = [ |
207 | 207 | ['&File', ['E&xit']], |
208 | 208 | ['&Mode', ['!Neutral', 'Play', '!Analysis']], |
209 | | - ['&Board', ['Flip']], |
| 209 | + ['Boar&d', ['Flip']], |
210 | 210 | ['&Engine', ['Set Engine', 'Set Depth', |
211 | 211 | 'Set Movetime', 'Get Settings::engine_info_k']], |
212 | | - ['Book', ['Set Book::book_set_k', 'Get Settings::book_info_k']], |
| 212 | + ['&Book', ['Set Book::book_set_k', 'Get Settings::book_info_k']], |
213 | 213 | ['&Help', ['About']], |
214 | 214 | ] |
215 | 215 |
|
|
225 | 225 | ['&Engine', ['Go', 'Set Depth', |
226 | 226 | 'Set Movetime', 'Get Settings::engine_info_k', |
227 | 227 | 'Unhide Search Info']], |
| 228 | + ['&Book', ['Set Book::book_set_k', 'Get Settings::book_info_k']], |
228 | 229 | ['&Help', ['About']], |
229 | 230 | ] |
230 | 231 |
|
@@ -837,11 +838,12 @@ def get_engine_settings(self, engine_id_name): |
837 | 838 |
|
838 | 839 | def get_book_settings(self): |
839 | 840 | """ Display GUI book settings """ |
840 | | - sg.PopupOK('Book = {}\nUse Book = {}\nBest move = {}\nRandom move = {}'. \ |
841 | | - format(self.gui_book_file, |
| 841 | + sg.PopupOK('Book = {}\nUse Book = {}\nBest move = {}\nRandom move = {}\nMax Ply = {}'. \ |
| 842 | + format(self.gui_book_file, |
842 | 843 | 'Yes' if self.is_use_gui_book else 'No', |
843 | 844 | 'No' if self.is_random_book else 'Yes', |
844 | | - 'Yes' if self.is_random_book else 'No'), |
| 845 | + 'Yes' if self.is_random_book else 'No', |
| 846 | + self.max_book_ply), |
845 | 847 | title=BOX_TITLE, keep_on_top=True) |
846 | 848 |
|
847 | 849 | def play_game(self, engine_id_name, board): |
@@ -880,13 +882,78 @@ def play_game(self, engine_id_name, board): |
880 | 882 | while True: |
881 | 883 | button, value = self.window.Read(timeout=100) |
882 | 884 |
|
883 | | - # User can hide/unhide search info when engine is to move on its first move |
| 885 | + # User can hide/unhide search info when engine is to move |
| 886 | + # on its first move in Play mode |
884 | 887 | if button == 'Hide Search Info' or button == 'Unhide Search Info': |
885 | 888 | new_menu, is_hide_engine_search_info = self.update_play_menu( |
886 | 889 | menu_def_play, is_hide_engine_search_info) |
887 | 890 | self.menu_elem.Update(new_menu) |
888 | 891 | continue |
889 | 892 |
|
| 893 | + # Allow user to view book settings when engine is to move |
| 894 | + # on its first move in Play mode |
| 895 | + if button == 'Get Settings::book_info_k': |
| 896 | + self.get_book_settings() |
| 897 | + continue |
| 898 | + |
| 899 | + # Allow user to change book settings when engine is to move |
| 900 | + # on its first move in Play mode |
| 901 | + if button == 'Set Book::book_set_k': |
| 902 | + # Backup current values, we will restore these value in case |
| 903 | + # the user presses cancel or X button |
| 904 | + current_is_use_gui_book = self.is_use_gui_book |
| 905 | + current_is_random_book = self.is_random_book |
| 906 | + current_max_book_ply = self.max_book_ply |
| 907 | + |
| 908 | + layout = [ |
| 909 | + [sg.T('Book File', size=(8, 1)), sg.T(self.gui_book_file, |
| 910 | + size = (24, 1), relief='sunken')], |
| 911 | + [sg.T('Max Ply', size=(8, 1)), |
| 912 | + sg.Spin([t for t in range(1, 33, 1)], |
| 913 | + initial_value=self.max_book_ply, |
| 914 | + size=(6, 1), key='book_ply_k')], |
| 915 | + [sg.CBox('GUI book', key = 'use_gui_book_k', |
| 916 | + default=self.is_use_gui_book)], |
| 917 | + [sg.Radio('Best move', 'Book Radio', |
| 918 | + default = False if self.is_random_book else True), |
| 919 | + sg.Radio('Random move', 'Book Radio', |
| 920 | + key='random_move_k', |
| 921 | + default = True if self.is_random_book else False)], |
| 922 | + [sg.OK(), sg.Cancel()], |
| 923 | + ] |
| 924 | + |
| 925 | + self.window.Hide() |
| 926 | + w = sg.Window(BOX_TITLE, layout) |
| 927 | + |
| 928 | + while True: |
| 929 | + e, v = w.Read(timeout=10) |
| 930 | + |
| 931 | + # If user presses X button |
| 932 | + if e is None: |
| 933 | + self.is_use_gui_book = current_is_use_gui_book |
| 934 | + self.is_random_book = current_is_random_book |
| 935 | + self.max_book_ply = current_max_book_ply |
| 936 | + logging.info('Book setting is exited.') |
| 937 | + break |
| 938 | + |
| 939 | + if e == 'Cancel': |
| 940 | + self.is_use_gui_book = current_is_use_gui_book |
| 941 | + self.is_random_book = current_is_random_book |
| 942 | + self.max_book_ply = current_max_book_ply |
| 943 | + logging.info('Book setting is cancelled.') |
| 944 | + break |
| 945 | + |
| 946 | + if e == 'OK': |
| 947 | + self.max_book_ply = int(v['book_ply_k']) |
| 948 | + self.is_use_gui_book = v['use_gui_book_k'] |
| 949 | + self.is_random_book = v['random_move_k'] |
| 950 | + logging.info('Book setting is OK') |
| 951 | + break |
| 952 | + |
| 953 | + w.Close() |
| 954 | + self.window.UnHide() |
| 955 | + continue |
| 956 | + |
890 | 957 | if button == 'New::new_game_k': |
891 | 958 | is_new_game = True |
892 | 959 | break |
@@ -963,12 +1030,74 @@ def play_game(self, engine_id_name, board): |
963 | 1030 | if not is_human_stm: |
964 | 1031 | break |
965 | 1032 |
|
966 | | - # User can hide/unhide search info when user is to move |
| 1033 | + # User can hide/unhide search info when user is to move on Play mode |
967 | 1034 | if button == 'Hide Search Info' or button == 'Unhide Search Info': |
968 | 1035 | new_menu, is_hide_engine_search_info = self.update_play_menu( |
969 | 1036 | menu_def_play, is_hide_engine_search_info) |
970 | 1037 | self.menu_elem.Update(new_menu) |
971 | 1038 | continue |
| 1039 | + |
| 1040 | + # Allow user to view book settings when user is to move in Play mode |
| 1041 | + if button == 'Get Settings::book_info_k': |
| 1042 | + self.get_book_settings() |
| 1043 | + continue |
| 1044 | + |
| 1045 | + # Allow user to change book settings when user is to move in Play mode |
| 1046 | + if button == 'Set Book::book_set_k': |
| 1047 | + # Backup current values, we will restore these value in case |
| 1048 | + # the user presses cancel or X button |
| 1049 | + current_is_use_gui_book = self.is_use_gui_book |
| 1050 | + current_is_random_book = self.is_random_book |
| 1051 | + current_max_book_ply = self.max_book_ply |
| 1052 | + |
| 1053 | + layout = [ |
| 1054 | + [sg.T('Book File', size=(8, 1)), sg.T(self.gui_book_file, |
| 1055 | + size = (24, 1), relief='sunken')], |
| 1056 | + [sg.T('Max Ply', size=(8, 1)), |
| 1057 | + sg.Spin([t for t in range(1, 33, 1)], |
| 1058 | + initial_value=self.max_book_ply, |
| 1059 | + size=(6, 1), key='book_ply_k')], |
| 1060 | + [sg.CBox('GUI book', key = 'use_gui_book_k', |
| 1061 | + default=self.is_use_gui_book)], |
| 1062 | + [sg.Radio('Best move', 'Book Radio', |
| 1063 | + default = False if self.is_random_book else True), |
| 1064 | + sg.Radio('Random move', 'Book Radio', |
| 1065 | + key='random_move_k', |
| 1066 | + default = True if self.is_random_book else False)], |
| 1067 | + [sg.OK(), sg.Cancel()], |
| 1068 | + ] |
| 1069 | + |
| 1070 | + self.window.Hide() |
| 1071 | + w = sg.Window(BOX_TITLE, layout) |
| 1072 | + |
| 1073 | + while True: |
| 1074 | + e, v = w.Read(timeout=10) |
| 1075 | + |
| 1076 | + # If user presses X button |
| 1077 | + if e is None: |
| 1078 | + self.is_use_gui_book = current_is_use_gui_book |
| 1079 | + self.is_random_book = current_is_random_book |
| 1080 | + self.max_book_ply = current_max_book_ply |
| 1081 | + logging.info('Book setting is exited.') |
| 1082 | + break |
| 1083 | + |
| 1084 | + if e == 'Cancel': |
| 1085 | + self.is_use_gui_book = current_is_use_gui_book |
| 1086 | + self.is_random_book = current_is_random_book |
| 1087 | + self.max_book_ply = current_max_book_ply |
| 1088 | + logging.info('Book setting is cancelled.') |
| 1089 | + break |
| 1090 | + |
| 1091 | + if e == 'OK': |
| 1092 | + self.max_book_ply = int(v['book_ply_k']) |
| 1093 | + self.is_use_gui_book = v['use_gui_book_k'] |
| 1094 | + self.is_random_book = v['random_move_k'] |
| 1095 | + logging.info('Book setting is OK') |
| 1096 | + break |
| 1097 | + |
| 1098 | + w.Close() |
| 1099 | + self.window.UnHide() |
| 1100 | + continue |
972 | 1101 |
|
973 | 1102 | if button is None: |
974 | 1103 | logging.info('Quit app X is pressed.') |
@@ -1228,7 +1357,7 @@ def play_game(self, engine_id_name, board): |
1228 | 1357 | logging.info('Exit app while engine is searching') |
1229 | 1358 | sys.exit(0) |
1230 | 1359 |
|
1231 | | - # User can hide/unhide search info while engine is thinking |
| 1360 | + # User can hide/unhide search info while engine is thinking on Play mode |
1232 | 1361 | if button == 'Hide Search Info' or button == 'Unhide Search Info': |
1233 | 1362 | new_menu, is_hide_engine_search_info = self.update_play_menu( |
1234 | 1363 | menu_def_play, is_hide_engine_search_info) |
@@ -1624,10 +1753,12 @@ def main_loop(self): |
1624 | 1753 | self.get_engine_settings(engine_id_name) |
1625 | 1754 | continue |
1626 | 1755 |
|
| 1756 | + # Allow user to view book settings in Neutral mode |
1627 | 1757 | if button == 'Get Settings::book_info_k': |
1628 | 1758 | self.get_book_settings() |
1629 | 1759 | continue |
1630 | 1760 |
|
| 1761 | + # Allow user to change book settings in Neutral mode |
1631 | 1762 | if button == 'Set Book::book_set_k': |
1632 | 1763 | # Backup current values, we will restore these value in case |
1633 | 1764 | # the user presses cancel or X button |
|
0 commit comments