예제 #1
0
def play():
    config = Config()
    winner = None
    while winner == None:
        show(config)
        start, dest = ask()
        if config.try_play(start, dest):
            winner, _ = config.winner()
        else:
            print("Invalid move, please replay")
    show(config)
    show_winner(winner)
예제 #2
0
def test():
    config = Config()
    with open('chess/engine/games.csv', newline='') as games:
        reader = csv.DictReader(games)
        nb = 0
        for row in reader:
            nb += 1
            moves = row['moves'].split()
            i = 0
            over = None
            if row['victory_status'] == 'mate' and nb > 0:
                while over == None:
                    start, dest, prom_not_queen = ask_test(moves[i])
                    # auto promotion in queen so others are not handled
                    if prom_not_queen:
                        over = 0
                    elif config.try_play(start,dest):
                        # show(config)
                        over,_ = config.winner()
                    else:
                        sys.exit("fail at move :  " + moves[i])
                    i += 1
                config.reset()