def random(self, name=None, lower=-1.0, upper=1.0, weights={}, settings={}): """ Create a randomly configured player. Weights and settings are randomly generated between the lower and upper limits, defaulted at 0.0 and 1.0. Optionally a weights and settings dict can be passed in for any weights/settings that you want to fix. In this instance only the other weights will be added randomly to this dict. """ weights = weights.copy() settings = settings.copy() # copy over the list of requires weights required_weights = self.player_class.required_weights[:] # and settings required_settings = self.player_class.required_settings[:] # loop through required weights and create random weight for any # that have not been passed into this function. for rq_weight in required_weights: if not weights.has_key(rq_weight): if rq_weight.endswith('_multi'): weights[rq_weight] = [ self._random_float(upper, lower) for x in range(0, 6) ] else: weights[rq_weight] = self._random_float(upper, lower) # See above, do the same for settings #for rq_setting in required_settings: # if not settings.has_key(rq_setting): # settings[rq_setting] = random.randrange() # Create an instance of the player simple to check that it passes # the configuration test. player_obj = self.player_class(True, weights=weights, settings=settings, name=name) player_obj.check_setup() # Then discard it del player_obj # Create a configured player object that is ready to be placed in a game. return players.ConfiguredPlayer( self.player_class, name=name or "Randomly Generated %s" % self.player_class.name, settings=settings, weights=weights, )
def test_game(self): """ Run through 10,000 test games with random players. For testing the game player and also testing game rules. 10,000 totally games are likely to explore most of the game rules and find any flaws. """ for i in range(10000): player_a = players.ConfiguredPlayer( basic.RandomPlayer, name="R A", ) player_b = players.ConfiguredPlayer( basic.RandomPlayer, name="R B", ) mg = board.MancalaGame(player_a, player_b) mg.run_game()
def test_minimax_game(self): """ Run through a sample test game with MiniMax players. """ settings = { 'max_depth': 2, } player_a = basic.MiniMaxPlayer.objects.random(name="MM 1", settings=settings.copy()) player_b = basic.MiniMaxPlayer.objects.random(name="MM 2", settings=settings.copy()) player_a = players.ConfiguredPlayer( basic.RandomPlayer, name="R A", ) player_b = players.ConfiguredPlayer( basic.RandomPlayer, name="R B", ) mg = board.MancalaGame(player_a, player_b) mg.run_game()
def _train(self, cp): nn_player = players.ConfiguredPlayer(NeuralNetPlayer, name="NNN") #print nn_player.name, "vs", cp.name, "--", home_game = board.MancalaGame(nn_player, cp) home_game.run_game() home_a, home_b = home_game.board.scores() self.backpropogate(home_game) result = ( 0, '###', ) if home_a > home_b: #print '%02s %02s -- NN' % (home_a, home_b) result = ( 1, nn_player.name, ) Log(result=1).save() elif home_b > home_a: #print '%02s %02s -- CP' % (home_a, home_b) result = ( -1, cp.name, ) Log(result=-1).save() else: #print '%02s %02s -- DR' % (home_a, home_b) Log(result=0).save() pass return result
settings={ 'max_depth': 3, })) settings = { 'max_depth': 3, } weights = weights = { 'scrape': 100.0, 'store': 10.0, 'score': 0.5, 'stance': 0.0, 'pits_multi': [10.0, 9.0, 8.0, 7.0, 6.0, 5.0], } cro = players.ConfiguredPlayer(basic.MiniMaxPlayer, weights, settings=settings, name="MMCC") player_list.append(cro) t = tournament.MancalaTournament(player_list) r = t.run(yield_length=True) l = list(r) print sum([len(i) for i in l]) / len(l) print max([len(i) for i in l]) print min([len(i) for i in l]) games = l[0]
random_bases = [] for x in range(0, number_of_each): random_bases.append( basic.MiniMaxPlayer.objects.random(name="M2%s" % x, settings={ 'max_depth': 1, })) random_bases.append( basic.MiniMaxPlayer.objects.random(name="M2%s" % x, settings={ 'max_depth': 1, })) for i in range(100): r = players.ConfiguredPlayer( basic.RandomPlayer, name="R %s" % i, ) PLAYER_LIST.append(r) for y in range(1, max_depth + 1): for i in range(0, number_of_each): mm = basic.MiniMaxPlayer.objects.random( name="M%s%s" % (y, i), weights=random_bases[i].weights, settings={ 'max_depth': y, }) PLAYER_LIST.append(mm) mt = tournament.MancalaTournament(PLAYER_LIST) mt.VERBOSE = True
random_bases = [] for x in range(0, number_of_each): random_bases.append( basic.MiniMaxPlayer.objects.random(name="M2%s" % x, settings={ 'max_depth': 1, })) random_bases.append( basic.MiniMaxPlayer.objects.random(name="M2%s" % x, settings={ 'max_depth': 1, })) for i in range(30): r = players.ConfiguredPlayer( basic.RandomPlayer, name="R%02s" % i, ) PLAYER_LIST.append(r) for y in range(1, max_depth + 1): for i in range(0, number_of_each): mm = basic.MiniMaxPlayer.objects.random( name="M%s%s" % (y, i), weights=random_bases[i].weights, settings={ 'max_depth': y, }) PLAYER_LIST.append(mm) c_mm = players.ConfiguredPlayer( basic.MiniMaxPlayer,