def start(self, show=True): if not self.simu: team1 = SoccerTeam("Team 1") team2 = SoccerTeam("Team 2") team1.add(self.strategy.name, self.strategy) team2.add(Strategy().name, Strategy()) self.simu = Simulation(team1, team2, max_steps=self.max_steps) self.simu.listeners += self if show: show_simu(self.simu) else: self.simu.start()
def check_team(team): teamDefault = SoccerTeam() for nb in range(team.nb_players): teamDefault.add(str(nb), Strategy()) if Simulation(team,teamDefault,max_steps=MAX_TEST_STEPS).start().error or \ Simulation(teamDefault,team,max_steps=MAX_TEST_STEPS).start().error: return False return True
def __init__(self): self.strat = ShootExpe() team1 = SoccerTeam("test") team1.add("Expe", self.strat) team2 = SoccerTeam("test2") team2.add("Nothing", Strategy()) self.simu = Simulation(team1, team2, max_steps=40000) self.simu.listeners += self self.discr_step = 20 self.nb_essais = 20
def __init__(self,visu = False): # Visu permet la visualisation de la simu. Si on en veut pas, on met false. Cela est permis par la fonction start en bas. team1 = SoccerTeam("expe1") team2 = SoccerTeam("expe2") self.strat = shoot() # On donne la strat qu'on va utiliser. team1.add("jexp1", self.strat ) team2.add("jplot",Strategy()) # Si besoin d'un joueur de team adverse self.simu = Simulation(team1,team2,max_steps=10000000) # On def la simu avec un enorme max_steps car on veut test x round et on veut pas devoir recommencer un match self.visu = visu self.simu.listeners+=self #ajout de l observer list_a = np.linspace(0.1,20,30) # Creation de la matrice pour la parametre a. De param1 a param2 avec param2 valeurs list_b = np.linspace(0.1,20,30) self.list_params = [(a,b) for a in list_a for b in list_b] # Creation de tout les couples possible self.cpt_params = 0 # Va permettre de tester toute la liste de couple de params self.nb_expe = 20 # Nb de round que l on fera par postion self.res = dict() # Ini de notre dico self.pos = dict()
cage2 = Vector2D( GAME_WIDTH, GAME_HEIGHT / 2, ) cage1 = Vector2D(0, GAME_HEIGHT / 2) if (id_team == 1): if balle.distance(joueur) < PLAYER_RADIUS + BALL_RADIUS: return SoccerAction(shoot=cage2 - joueur) else: return SoccerAction(acceleration=balle - joueur) else: if balle.distance(joueur) < PLAYER_RADIUS + BALL_RADIUS: return SoccerAction(shoot=cage1 - joueur) else: return SoccerAction(acceleration=balle - joueur) # Create teams team1 = SoccerTeam(name="Team 1") team2 = SoccerTeam(name="Team 2") # Add players team1.add("Tireur", tir()) # Random strategy team2.add("Static", Strategy()) # Static strategy # Create a match simu = Simulation(team2, team1) # Simulate and display the match show_simu(simu)
dist = math.hypot(ballPositionX - playerPositionX, ballPositionY - playerPositionY) if (dist < PLAYER_RADIUS + BALL_RADIUS and state.ball.position.x > GAME_WIDTH / 2): return SoccerAction( Vector2D(angle=3.14, norm=0.2), vecteurShootGoal( state.ball, 0, state.player_state(id_team, id_player).position.y, 10)) elif (dist < PLAYER_RADIUS + BALL_RADIUS): return SoccerAction( Vector2D(angle=3.14, norm=0.2), vecteurShootGoal(state.ball, 0, GAME_HEIGHT / 2, 4.5)) else: return SoccerAction( Vector2D(ballPositionX - playerPositionX, ballPositionY - playerPositionY).normalize() * maxPlayerAcceleration, Vector2D(0, 0)) ## Creation d'une equipe pyteam = SoccerTeam(name="Overwatch") thon = SoccerTeam(name="Rainbow6") pyteam.add("Lucio", Strategy()) #Strategie qui ne fait rien thon.add("Valkyrie", shootStrategy()) #Strategie aleatoire #Creation d'une partie simu = Simulation(pyteam, thon) #Jouer et afficher la partie show_simu(simu)
QTestStrategy = QStrategy.QStrategy() QTestStrategy.add("right",SimpleStrategy(shoot_right,"")) QTestStrategy.add("left",SimpleStrategy(shoot_left,"")) QTestStrategy.add("up",SimpleStrategy(shoot_up,"")) QTestStrategy.add("down",SimpleStrategy(shoot_down,"")) ''' #Learning expe = QLearning(strategy=QTestStrategy, monte_carlo=False) expe.start(fps=1500) with open("qstrategy.pkl", "wb") as fo: QTestStrategy.qtable = expe.qtable print('Q TABLE', expe.qtable) pkl.dump(QTestStrategy, fo) #Test #with open("qstrategy.pkl","rb") as fi: # QStrategy = pkl.load(fi) # Simulate and display the match #simu = RandomPos(QStrategy) team1 = SoccerTeam(name="Team 1") team2 = SoccerTeam(name="Team 2") team1.add("Attaquant", QTestStrategy) team1.add("Attaquant2", QTestStrategy) team2.add("wing g", Strategy()) team2.add("wing d", Strategy()) # Random strategy simu = Simulation(team1, team2) #simu.start() show_simu(simu) expe.get_res()