Пример #1
0
def effective_model_power(checkpoint, game, model_class, sims, cuda=False):
    my_model = NeuralNetwork(game, model_class, cuda=cuda)
    my_model.load(checkpoint)
    my_player = DeepMCTSPlayer(game, my_model, sims)
    strength = 10
    num_opponents = game.get_num_players() - 1
    lost = False

    while not lost:
        contenders = [
            UninformedMCTSPlayer(game, strength) for _ in range(num_opponents)
        ]

        # Play main game
        scores, outcomes = play_match(game, [my_player] + contenders,
                                      verbose=False,
                                      permute=True)
        score, outcome = scores[my_player], outcomes[my_player]
        if outcome == "Lose": lost = True
        print("{} <{}>      Opponent strength: {}".format(
            outcome, round(score, 3), strength),
              end="")

        # Play control game
        control_player = UninformedMCTSPlayer(game, sims)
        scores, outcomes = play_match(game, [control_player] + contenders,
                                      verbose=False,
                                      permute=True)
        score, outcome = scores[control_player], outcomes[control_player]
        print("      (Control: {} <{}>)".format(outcome, round(score, 3)))

        strength *= 2  # Opponent strength doubles every turn
Пример #2
0
 def test_resets_work(self):
     game = TicTacToe()
     p1, p2 = UninformedMCTSPlayer(game, 1), UninformedMCTSPlayer(game, 1)
     for _ in range(100):
         scores, outcomes = play_match(game, [p1, p2])
         self.assertEqual(scores, {p1: 1.0, p2: 0.0})
         self.assertEqual(outcomes, {p1: "Win", p2: "Lose"})
     for _ in range(100):
         scores, outcomes = play_match(game, [p1, p2], permute=True)
         self.assertEqual(scores, {p1: 0.5, p2: 0.5})
         self.assertEqual(outcomes, {p1: "Tie", p2: "Tie"})
Пример #3
0
def rank_checkpoints(game, model_class, sims, cuda=False):
    winning_model = NeuralNetwork(game, model_class, cuda=cuda)
    contending_model = NeuralNetwork(game, model_class, cuda=cuda)
    ckpts = winning_model.list_checkpoints()
    num_opponents = game.get_num_players() - 1
    current_winner = ckpts[0]

    for contender in ckpts:

        # Load contending player
        contending_model.load(contender)
        contending_player = DeepMCTSPlayer(game, contending_model, sims)

        # Load winning player
        winning_model.load(current_winner)
        winners = [
            DeepMCTSPlayer(game, winning_model, sims)
            for _ in range(num_opponents)
        ]

        scores, outcomes = play_match(game, [contending_player] + winners,
                                      verbose=False,
                                      permute=True)
        score, outcome = scores[contending_player], outcomes[contending_player]
        print("Current Champ: {}    Challenger: {}    Outcome: {} <{}>    ".
              format(current_winner, contender, outcome, score),
              end="")
        if outcome == "Win":
            current_winner = contender
        print("New Champ: {}".format(current_winner))
Пример #4
0
 def test_three_permutation(self):
     game = ThreePlayerLeapFrog()
     p1, p2, p3 = UninformedMCTSPlayer(game, 1), UninformedMCTSPlayer(
         game, 1), UninformedMCTSPlayer(game, 1)
     scores, outcomes = play_match(game, [p1, p2, p3], permute=True)
     self.assertEqual(scores, {p1: 1 / 3, p2: 1 / 3, p3: 1 / 3})
     self.assertEqual(outcomes, {p1: "Tie", p2: "Tie", p3: "Tie"})
Пример #5
0
 def test_three_simple(self):
     game = ThreePlayerLeapFrog()
     p1, p2, p3 = UninformedMCTSPlayer(game, 1), UninformedMCTSPlayer(
         game, 1), UninformedMCTSPlayer(game, 1)
     scores, outcomes = play_match(game, [p1, p2, p3])
     self.assertEqual(scores, {p1: 0.0, p2: 0.0, p3: 1.0})
     self.assertEqual(outcomes, {p1: "Lose", p2: "Lose", p3: "Win"})
def evaluate_against_uninformed(checkpoint,
                                game,
                                model_class,
                                my_sims,
                                opponent_sims,
                                cuda=False):
    my_model = NeuralNetwork(game, model_class, cuda=cuda)
    my_model.load(checkpoint)
    num_opponents = game.get_num_players() - 1
    uninformeds = [
        UninformedMCTSPlayer(game, opponent_sims) for _ in range(num_opponents)
    ]
    informed = DeepMCTSPlayer(game, my_model, my_sims)
    scores = play_match(game, [informed] + uninformeds, permute=True)
    print("Opponent strength: {}     Scores: {}".format(opponent_sims, scores))
Пример #7
0
def one_vs_all(checkpoint, game, model_class, sims, cuda=False):
    my_model = NeuralNetwork(game, model_class, cuda=cuda)
    my_model.load(checkpoint)
    contending_model = NeuralNetwork(game, model_class, cuda=cuda)
    ckpts = my_model.list_checkpoints()
    num_opponents = game.get_num_players() - 1

    for contender in ckpts:
        contending_model.load(contender)
        my_player = DeepMCTSPlayer(game, my_model, sims)
        contenders = [
            DeepMCTSPlayer(game, contending_model, sims)
            for _ in range(num_opponents)
        ]
        scores, outcomes = play_match(game, [my_player] + contenders,
                                      verbose=False,
                                      permute=True)
        score, outcome = scores[my_player], outcomes[my_player]
        print("Challenger:", contender, "Outcome:", outcome, score)
Пример #8
0
 def test_self_play(self):
     game = TwoPlayerGuessIt()
     p1 = UninformedMCTSPlayer(game, 4)
     scores, outcomes = play_match(game, [p1, p1], permute=True)
     self.assertEqual(len(scores), 1)
     self.assertEqual(len(outcomes), 1)
Пример #9
0
 def test_permutation(self):
     game = TicTacToe()
     p1, p2 = UninformedMCTSPlayer(game, 1), UninformedMCTSPlayer(game, 1)
     scores, outcomes = play_match(game, [p1, p2], permute=True)
     self.assertEqual(scores, {p1: 0.5, p2: 0.5})
     self.assertEqual(outcomes, {p1: "Tie", p2: "Tie"})
Пример #10
0
 def test_simple(self):
     game = TicTacToe()
     p1, p2 = UninformedMCTSPlayer(game, 1), UninformedMCTSPlayer(game, 1)
     scores, outcomes = play_match(game, [p1, p2])
     self.assertEqual(scores, {p1: 1.0, p2: 0.0})
     self.assertEqual(outcomes, {p1: "Win", p2: "Lose"})