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


Python Board.print_solutions方法代碼示例

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


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

示例1: main

# 需要導入模塊: from chess.board import Board [as 別名]
# 或者: from chess.board.Board import print_solutions [as 別名]
def main():
    """ Main function """
    parser = ArgumentParser()
    parser.add_argument("-x", "--horizontal", dest="width", default=3, type=int,
    help="Horizontal dimension (default=3)")
    parser.add_argument("-y", "--vertical", dest="height", default=3, type=int,
    help="Vertical dimension (default=3)")
    parser.add_argument("-k", "--kings", dest="king", default=0, type=int,
    help="Number of kings")
    parser.add_argument("-q", "--queens", dest="queen", default=0, type=int,
    help="Number of queens")
    parser.add_argument("-b", "--bishops", dest="bishop", default=0, type=int,
    help="Number of bishops")
    parser.add_argument("-r", "--rooks", dest="rook", default=0, type=int,
    help="Number of rooks")
    parser.add_argument("-n", "--knights", dest="knight", default=0, type=int,
    help="Number of knights")
    parser.add_argument("-p", "--print", dest="printsolutions", default=False,
    help="Print the solutions", action='store_true')
    args = parser.parse_args()

    if sum([args.king, args.queen, args.bishop, args.rook, args.knight]) == 0:
        print 'No chess pieces given. Nothing to do. Running the assignment!'
        assignment()
    else:
        print 'Chess pieces:'
        print '- Kings ' + str(args.king)
        print '- Queens ' + str(args.queen)
        print '- Bishops ' + str(args.bishop)
        print '- Rooks ' + str(args.rook)
        print '- Knights ' + str(args.knight)

    board = Board(args.width, args.height)
    pieces = {}
    pieces['king'] = args.king
    pieces['queen'] = args.queen
    pieces['bishop'] = args.bishop
    pieces['rook'] = args.rook
    pieces['knight'] = args.knight
    board.set_pieces(pieces)
    print 'Start', datetime.datetime.now()
    board.put_pieces()
    print 'End', datetime.datetime.now()
    print 'Found '+str(len(board.solutions))+ ' solutions'
    if args.printsolutions is True:
        board.print_solutions()
開發者ID:jqadrad,項目名稱:chess,代碼行數:48,代碼來源:__main__.py


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