Exemple #1
0
import random

from bke import MLAgent, is_winner, opponent, RandomAgent, train_and_plot


class MyAgent(MLAgent):
    def evaluate(self, board):
        if is_winner(board, self.symbol):
            reward = 1
        elif is_winner(board, opponent[self.symbol]):
            reward = -1
        else:
            reward = 0
        return reward


random.seed(1)

my_agent = MyAgent()
random_agent = RandomAgent()

train_and_plot(agent=my_agent,
               validation_agent=random_agent,
               iterations=50,
               trainings=100,
               validations=1000)
Exemple #2
0
 def train_and_plot(self, iterations, trainings, validations):
     random_agent = RandomAgent()
     train_and_plot(agent=self, validation_agent=random_agent, iterations=iterations, trainings=trainings, validations=validations)
     save(self, 'MyAgent')