Beispiel #1
0
 def generate_data_rl(self, ngames=50, fname=''):
     """
     generate a new batch of data with the latest prediction model
     self.model_predict
     rl vs. smithy bot
     """
     vf = lambda x: self.model_predict.predict(x)
     p1 = RLPlayer(vf)
     p1.epsilon = self.epsilon
     p1.record_history = 1
     p2 = RLPlayer(vf)
     p2.epsilon = self.epsilon
     p2.record_history = 1
     d_this = record_game(ngames, [p1, p2], fname)
     self.add_data(d_this)
     return d_this
Beispiel #2
0
 def generate_data_rl(self, ngames=50, fname=''):
     """
     generate a new batch of data with the latest prediction model self.model_predict
     by playing against self.
     """
     vf = lambda x: self.model.predict(x)
     p2 = RLPlayer(vf)
     p2.epsilon = self.epsilon
     p2.record_history = 1
     p2.include_action = 1
     return self.generate_data_bot(p2, ngames, fname)
Beispiel #3
0
 def generate_data_rl(self, ngames=50, fname=''):
     """
     generate a new batch of data with the latest prediction model
     self.model_predict
     rl vs. smithy bot
     """
     vbuy = lambda x: self.model_predict.predict(x)
     #vact = lambda x: self.model_act.predict(x)
     # p1 = BuyActRLplayer(vbuy, vact)
     p1 = RLPlayer(vbuy)
     p1.epsilon = self.epsilon
     p1.record_history = 1
     p1.include_action = 1
     p2 = RLPlayer(vbuy)
     p2.epsilon = self.epsilon
     p2.record_history = 1
     p2.include_action = 1
     d_this, _ = self.record_game(ngames, [p1, p2], fname, verbose=1)
     self.add_data(d_this)
     return d_this
Beispiel #4
0
def compare_rl_bots(fn1, fn2, num_games=50, order=0):
    # set up the two rl bots, and make them fight.
    print('setting up bot1...')
    dql = SarsaAgent()
    dql.create_model_5layers()
    data = dql.load_game_data('1game')
    dql.fit(data)
    dql.load_model(fn1)
    p1 = RLPlayer(lambda x: dql.model.predict(x))
    p1.name = fn1
    p1.epsilon = 0
    print('setting up bot2...')
    dql2 = SarsaAgent()
    dql2.create_model_5layers()
    data = dql2.load_game_data('1game')
    dql2.fit(data)
    dql2.load_model(fn1)
    p2 = RLPlayer(lambda x: dql2.model.predict(x))
    p2.name = fn2
    p2.epsilon = 0
    print('fight!')
    return compare_bots([p1, p2], num_games, order)
Beispiel #5
0
 def generate_data_bot(self, bot, ngames=50, fname=''):
     """
     generate a new batch of data with the latest prediction model self.model
     rl vs. specified bot
     """
     vf = lambda x: self.model.predict(x)
     p1 = RLPlayer(vf)
     p1.epsilon = self.epsilon
     p1.record_history = 1
     p1.include_action = 1
     bot.record_history = 0
     d_this = self.record_game(ngames, [p1, bot], fname)
     self.add_data(d_this)
     return d_this
Beispiel #6
0
 def generate_data_smithy(self, ngames=50, fname=''):
     """
     generate a new batch of data with the latest prediction model
     self.model_predict
     rl vs. smithy bot
     """
     vbuy = lambda x: self.model_predict.predict(x)
     # vact = lambda x: self.model_act.predict(x)
     # p1 = BuyActRLplayer(vbuy, vact)
     p1 = RLPlayer(vbuy)
     p1.epsilon = self.epsilon
     p1.record_history = 1
     p1.include_action = 1
     p2 = SmithyBot()
     # try including smithy bot's data in the training.
     p2.record_history = 0
     d_this, _ = self.record_game(ngames, [p1, p2], fname)
     self.add_data(d_this)
     return d_this