def quit(self): self.stopped = True self.quitting = True engine.movenow() self.save_settings() gv.usib.stop_engine() gv.usiw.stop_engine() Gtk.main_quit() return False
def go(self): if self.gameover != 0: return if self.side_to_move == RED and self.red_player != COMPUTER: return if self.side_to_move == WHITE and self.white_player != COMPUTER: return # computer is thinking about next move - force it to move now if self.thinking: engine.movenow() return # engine is stopped and it's the computers turn to move. start thread to make the move self.ct = thread.start_new_thread( self.computer_move, () )
def stop(self): self.stopped = True gv.gui.enable_menu_items() gv.gui.enable_go_button() gv.gui.disable_stop_button() gv.gui.unset_all_drag_and_drop_squares() # update time gv.tc.stop_clock() # stop engines gv.usib.stop_engine() gv.usiw.stop_engine() engine.movenow() gv.gui.set_status_bar_msg("stopped")
def key_press_event(self, widget, event): kp = Gdk.keyval_name(event.keyval) kp = kp.lower() # treat ctrl+= same as ctrl++ (i.e. increase board size) if kp == "equal" and event.get_state() & Gdk.ModifierType.CONTROL_MASK: self.board.resize_board(widget) return # If in position edit mode don't allow key presses except 'Delete' if self.board.get_pos_edit(): if kp == 'delete': self.board.position_edit_clear_board() return # if computer is thinking don't allow key presses except for 'm' if self.thinking: # 'm' to interrupt computers thinking and make it move now if kp == "m" or kp == "g": engine.movenow() return if kp == "r": self.board.retract() elif kp == "bracketleft": self.board.rewind() elif kp == "bracketright": self.board.forward() elif kp == "braceleft": self.board.rewind_to_start() elif kp == "braceright": self.board.forward_to_end() elif kp == "g": self.go() elif kp == "2" or kp == "3" or kp == "4" or kp == "6" or kp == "k" or kp == "s": if kp == "2": kp = 2 if kp == "3": kp = 3 if kp == "4": kp = 4 if kp == "6": kp = 6 if kp == "c": kp = 7 if kp == "s": kp = 8 # add/delete/save from opening book opening_book_path = os.path.expanduser("~") + "/.samuel/opening.gbk" engine.openingbook(kp, opening_book_path) msg = engine.rdisp() self.gui.set_panel_text(msg)
def move_now(self, b): if self.player[self.stm] == "Human": return if not self.thinking: return # builtin gshogi engine if self.player[self.stm] == "gshogi": engine.movenow() return # USI engine try: if self.stm == BLACK: gv.usib.command("stop\n") else: gv.usiw.command("stop\n") except: pass
def move_now(self, b): engine.movenow()