Exemplo n.º 1
0
    def tap(self, keycode, character, press):
        # If 'n' is pressed then next move is played by allmighty SF
        if character == 'n' and press:
            print '---------------------------'
            try:
                pgn_text = get_pgn()
                game = pgn.loads(pgn_text)[0]
                if game.white == me: side = Player.WHITE
                else: side = Player.BLACK 
            except:
                print 'Issue with PGN:', pgn_text
                return

            print 'Moves: ', game.moves

            board = Bitboard()
            for move in game.moves:
                if move != '*':
                    board.push_san(move)

            fen_pos = board.fen()
            print 'FEN: ', fen_pos

            ## Set fen position to stockfish, find the best move

            stock.setposition_fen(fen_pos)
            move_dict = stock.bestmove()
            print 'move_dict: ', move_dict

            move = move_dict['move']

            ## Try to play the best move
            try:
                make_move(move, side)
            except:
                print 'Problem playing move!'

        # By pressing number from 1-9 you can set how long SF could possibly
        # think on a particular move (in seconds)
        elif character in DIGITS and press:
            print 'pressed: ', character
            stock.movetime = int(character) * 1000