Ejemplo n.º 1
0
def test_topMoves_chooseTop2_ReturnListsOfMoves():
    moves1 = [
        BlackMove(9, 9),
        WhiteMove(0, 0),
        WhiteMove(0, 2),
        BlackMove(0, 3),
        BlackMove(0, 4)
    ]
    moves2 = [
        BlackMove(9, 9),
        WhiteMove(0, 0),
        WhiteMove(0, 2),
        BlackMove(0, 3),
        BlackMove(0, 4)
    ]
    moves3 = [BlackMove(9, 9), WhiteMove(0, 0), WhiteMove(0, 1)]
    moves4 = [BlackMove(9, 9), WhiteMove(0, 0), WhiteMove(0, 1)]
    moves5 = [BlackMove(9, 9), WhiteMove(0, 2), WhiteMove(8, 8)]

    assembler = Assembler(moves1, merge_symmetric_moves=True)
    assembler.assemble(moves2)
    assembler.assemble(moves3)
    assembler.assemble(moves4)
    assembler.assemble(moves5)

    actual = assembler.top_n_moves(2)
    expected = [';;B[JJ];W[AA];W[AC]', ';;B[JJ];W[AA];W[AB]']

    assert actual == expected
Ejemplo n.º 2
0
    game_results = Extractor().extract(args.json_src, "game_result")

    print("Assembling to a tree...")
    assembler = Assembler(
        merge_symmetric_moves=args.enable_symmetrical_assembling, )

    with tqdm.tqdm(total=len(kifus)) as pbar:
        number_of_skipped_moves = 0
        for kifu, url, game_results in zip(kifus, urls, game_results):
            # Use Kifuparser to parse the raw string into sequence of move
            moves = KifuParser.parse(kifu)

            if len(moves) < args.lower_bound:
                number_of_skipped_moves += 1
            else:
                assembler.assemble(moves, url, game_results)

            pbar.update(1)

        print(
            f"'{number_of_skipped_moves}' kifus are skipped because it has too few moves.\n"
        )

    if args.num_of_openings != 0:
        with open("openings.txt", "w") as f:
            f.write(str(assembler.top_n_moves(args.num_of_openings)))

    print(f"Writing to file '{args.output_file}'...>")
    with open(args.output_file, "w") as f:
        dump_to(assembler, f, editor_style=args.use_editor_style)