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