Example #1
0
    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, () )
Example #2
0
    def key_press_event(self, widget, event):
        kp = Gdk.keyval_name(event.keyval)
        kp = kp.lower()

        # 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)
Example #3
0
 def move_now(self, b):
     engine.movenow()