Beispiel #1
0
def coeff_train(game):
    coeff = [1, 1, 1]
    old_h = H.LinearCombinationHeuristic(coeff)
    pick = random.randint(0, 2)
    for i in range(0, 15):
        coeff[pick] += 1
        new_h = H.LinearCombinationHeuristic(coeff)
        pl1_score = 0
        pl2_score = 0
        print(coeff)
        print("--------------START GAME LOOP-----------------")
        for j in range(0, 10):
            print("----------------PLAY START-----------------")
            score = ai_vs_ai(game, new_h, old_h, 5, 5, False)
            if score == 1:
                pl1_score += 1
            elif score == 2:
                pl2_score += 2
            game.reset()

        if pl1_score > pl2_score:
            old_h = new_h
            print("PL1 wins")
        else:
            print("PL2 wins")
            new_pick = random.randint(0, 2)
            while new_pick == pick:
                new_pick = random.randint(0, 2)
            pick = new_pick
    print("--------------END GAME LOOP-------------------")
    print(coeff)
    return coeff