當前位置: 首頁>>代碼示例>>Python>>正文


Python chess.Board類代碼示例

本文整理匯總了Python中chess.Board的典型用法代碼示例。如果您正苦於以下問題:Python Board類的具體用法?Python Board怎麽用?Python Board使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Board類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: pv_to_san

 def pv_to_san(self):
     if(self.san_arr == None):
         return ""
     else:
         try:
             pv_san = []
             board = Board(self.san_arr[0])
             moves = self.san_arr[1]
             for uci in moves:
                 move = Move.from_uci(uci)
                 if(move in board.pseudo_legal_moves):
                     pv_san.append(board.san(move))
                     board.push(move)
             if(len(pv_san) > 0):
                 s = ""
                 white_moves = True
                 move_no = (self.no_game_halfmoves//2)+1
                 if(self.no_game_halfmoves % 2 == 1):
                     white_moves = False
                     s += str(move_no)+". ... "
                     move_no += 1
                 for san in pv_san:
                     if(white_moves):
                         s += " "+str(move_no)+". "+san
                         move_no +=1
                     else:
                         s += " "+san
                     white_moves = not white_moves
                 return s
             else:
                 return ""
         except ValueError:
             return ""
開發者ID:jasiegel4,項目名稱:jerry,代碼行數:33,代碼來源:engine_info.py

示例2: repertoire

def repertoire(id=1):
    if request.args.get('practice'):
        print(practice(id))
    board = Board()
    form = MoveForm()
    if request.method == 'GET':
        position = Position.query.filter_by(id=id).first()
        moves = Move.query.join(User.moves).filter(User.id == current_user.id, Move.source_position_id == position.id).all()
        return render_template('tools/repertoire.html', fen=position.fen + ' 0 1', moves=moves, form=form, id=id)
    
    if request.method == 'POST':
        fen = form.append_fen.data
        san = form.append_san.data
        quality_id = form.quality.data
        board = Board(fen)
        board.push_san(san)
        source_position = Position.query.filter_by(fen=' '.join(fen.split()[:-2])).first()
        end_position_fen = ' '.join(board.fen().split()[:-2])
        end_position = Position.query.filter_by(fen=end_position_fen).first()
        if end_position is None:
            end_position = Position(fen=end_position_fen)
            db.session.add(end_position)
        move = Move.query.filter_by(source_position_id=source_position.id, destination_position_id=end_position.id).first()
        if move is None:
            move = Move(source_position_id=source_position.id, destination_position_id=end_position.id, san=san)
            um = UserMove(quality_id=quality_id)
            um.move = move
            current_user.moves.append(um)
        db.session.commit()
        moves = Move.query.join(User.moves).filter(User.id == current_user.id, Move.source_position_id == source_position.id).all()
        return render_template('tools/repertoire.html', fen=source_position.fen + ' 0 1', moves=moves, form=form, id=id)
開發者ID:Ghotrix,項目名稱:chess-everything,代碼行數:31,代碼來源:views.py

示例3: test_free_rows_and_columns

	def test_free_rows_and_columns(self):
		b = Board(2,2)
		self.assertEquals(free_rows_and_columns(b.data),(2,2))
		b2 = b.add_piece([("N",0,0)])
		self.assertEquals(free_rows_and_columns(b2.data),(1,1))
		b3 = b2.add_piece([("N",0,1)])
		self.assertEquals(free_rows_and_columns(b3.data),(1,0), b3)
開發者ID:kalleaaltonen,項目名稱:csolve,代碼行數:7,代碼來源:testchess.py

示例4: display_move_on_clock

 def display_move_on_clock(self, move, fen, side, beep=False, left_dots=0, right_dots=0):
     bit_board = Board(fen)
     move_text = bit_board.san(move)
     if side == ClockSide.RIGHT:
         move_text = move_text.rjust(11)
     text = self.dgttranslate.move(move_text)
     self._display_on_dgt_pi(text, beep, left_dots, right_dots)
開發者ID:lucasvdp,項目名稱:picochess,代碼行數:7,代碼來源:dgtpi.py

示例5: test_eq

	def test_eq(self):
		a = Board(2,2)
		b = Board(2,2)
		c = a.add_piece([("N",0,0)])
		self.assertTrue(a == a)
		self.assertTrue(a == b)
		self.assertTrue(b == a)
		self.assertTrue(a != c)
開發者ID:kalleaaltonen,項目名稱:csolve,代碼行數:8,代碼來源:testchess.py

示例6: display_move_on_clock

 def display_move_on_clock(self, move, fen, beep=False):
     if self.enable_dgt_3000:
         bit_board = Board(fen)
         text = self.dgttranslate.move(bit_board.san(move))
         self._display_on_dgt_3000(text, beep)
     else:
         text = ' ' + move.uci()
         self._display_on_dgt_xl(text, beep)
開發者ID:pablo2000,項目名稱:picochess,代碼行數:8,代碼來源:dgthw.py

示例7: test_rotations

	def test_rotations(self):
		b = Board(2,2) #.add_piece([("N",0,0)])
		print b.__dict__
		rots = list(b.rotations())
		for r in rots:
			print r.__dict__
		self.assertTrue(all(a==b for a in rots for b in rots))
		self.assertItemsEqual(rots, [b])	
開發者ID:kalleaaltonen,項目名稱:csolve,代碼行數:8,代碼來源:testchess.py

示例8: run_engine

 def run_engine(self, fen, move_time):
     #self.base_engine.setoption({'Clear': 'Hash'})
     board = Board()
     board.set_fen(fen)
     self.base_engine.position(board)
     self.base_engine.go(movetime=move_time, async_callback=False)
     while self.base_engine.bestmove is None:
         pass
     return self.info_handler_base.info["score"][1].cp
開發者ID:n-p,項目名稱:RWO,代碼行數:9,代碼來源:analysis-fen.py

示例9: display_move_on_clock

 def display_move_on_clock(self, move, fen, beep=BeepLevel.CONFIG):
     beep = self.get_beep_level(beep)
     if self.enable_dgt_3000:
         bit_board = Board(fen)
         text = bit_board.san(move)
         self._display_on_dgt_3000(text, beep)
     else:
         text = ' ' + move.uci()
         self._display_on_dgt_xl(text, beep)
開發者ID:aekker,項目名稱:picochess,代碼行數:9,代碼來源:dgthw.py

示例10: _oldstyle_fen

 def _oldstyle_fen(game: chess.Board):
     builder = []
     builder.append(game.board_fen())
     builder.append('w' if game.turn == chess.WHITE else 'b')
     builder.append(game.castling_xfen())
     builder.append(chess.SQUARE_NAMES[game.ep_square] if game.ep_square else '-')
     builder.append(str(game.halfmove_clock))
     builder.append(str(game.fullmove_number))
     return ' '.join(builder)
開發者ID:Ernisius,項目名稱:Picochess-nonDGT,代碼行數:9,代碼來源:server.py

示例11: test_board

	def test_board(self):
		# ..    NN
		# .. => NN
		b = Board(2,2)
		print b.free
		self.assertTrue(b.add_piece([("N",0,0)]))
		b2 = b.add_piece([("N",0,0),("N",0,1),("N",1,0),("N",1,1)])
		self.assertTrue(b2)
		self.assertEquals(len(b2.free), 0, "\n%s\n\nfree:%s"%(b2, b2.free))
		self.assertFalse(b.add_piece([("Q",0,0),("Q",1,1)]))
開發者ID:kalleaaltonen,項目名稱:csolve,代碼行數:10,代碼來源:testchess.py

示例12: deep_copy_board_pos

 def deep_copy_board_pos(self, board):
     fresh = Board()
     for i in range(0, 8):
         for j in range(0, 8):
             piece = board.piece_at(j * 8 + i)
             if piece:
                 sym = piece.symbol()
                 fresh.set_piece_at(j * 8 + i, Piece.from_symbol(sym))
             else:
                 fresh.remove_piece_at(j * 8 + i)
     return fresh
開發者ID:jasiegel4,項目名稱:jerry,代碼行數:11,代碼來源:dialog_enter_position.py

示例13: from_board

    def from_board(cls: Type[GameT], board: chess.Board) -> GameT:
        """Creates a game from the move stack of a :class:`~chess.Board()`."""
        # Setup the initial position.
        game = cls()
        game.setup(board.root())
        node = game  # type: GameNode

        # Replay all moves.
        for move in board.move_stack:
            node = node.add_variation(move)

        game.headers["Result"] = board.result()
        return game
開發者ID:niklasf,項目名稱:python-chess,代碼行數:13,代碼來源:pgn.py

示例14: run_engine

 def run_engine(self, epd, max_depth=0, move_time=0):
     self.modified_engine.setoption({'Clear': 'Hash'})
     board = Board()
     board.set_epd(epd)
     self.modified_engine.position(board)
     if max_depth != 0:
         self.modified_engine.go(depth=max_depth, async_callback=False)
     else:
         self.modified_engine.go(movetime=move_time, async_callback=False)
     while self.modified_engine.bestmove is None:
         pass
     result = self.info_handler_modified.info["score"][1].cp
     return result
開發者ID:n-p,項目名稱:RWO,代碼行數:13,代碼來源:RWO3.5.py

示例15: display_move_on_clock

 def display_move_on_clock(self, move, fen, side, beep=False, left_dots=0, right_dots=0):
     if self.enable_dgt_3000:
         bit_board = Board(fen)
         move_text = bit_board.san(move)
         if side == ClockSide.RIGHT:
             move_text = move_text.rjust(8)
         text = self.dgttranslate.move(move_text)
         self._display_on_dgt_3000(text, beep, left_dots, right_dots)
     else:
         move_text = move.uci()
         if side == ClockSide.RIGHT:
             move_text = move_text.rjust(6)
         self._display_on_dgt_xl(move_text, beep, left_dots, right_dots)
開發者ID:lucasvdp,項目名稱:picochess,代碼行數:13,代碼來源:dgthw.py


注:本文中的chess.Board類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。