当前位置: 首页>>代码示例>>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;未经允许,请勿转载。