def entrainement(fn): simu = Simulation(team1, team2) show_simu(simu) # recuperation de tous les etats training_states = strat_j1.states # sauvegarde dans un fichier dump_jsonz(training_states, fn)
def entrainer(fname): #Creation d'une partie kb_strat_def = KeyboardStrategy() kb_strat_def.add("a", posdefStrategy()) kb_strat_def.add("z", passeStrategy()) kb_strat_atk = KeyboardStrategy() kb_strat_atk.add("q", pospasseStrategy()) kb_strat_atk.add("s", dribbleStrategy()) kb_strat_atk.add("d", tirStrategy()) team1 = SoccerTeam(name="Control Team") team2 = SoccerTeam(name="Sparing") team1.add("Defenseur", kb_strat_def) team1.add("Attaquant", kb_strat_atk) team2.add("Player1", AttaqueStrategy()) team2.add("Player2", DefenseStrategy()) simu = Simulation(team1, team2) #Jouer, afficher et controler la partie show_simu(simu) print("Nombre d'exemples : " + str(len(kb_strat_atk.states))) print("Nombre d'exemples : " + str(len(kb_strat_def.states))) # Sauvegarde des etats dans un fichier dump_jsonz(kb_strat_atk.states, fname) dump_jsonz(kb_strat_def.states, fname)
def entrainer1v1_main(self, fname, ia): if self.nb_players != 1: raise Exception( "Not the good number of players for this function.") #Creation d'une partie kb_strat = KeyboardStrategy() kb_strat.add("a", m.strategy.ShootStrat()) kb_strat.add("z", m.strategy.DefStrat()) kb_strat.add("e", m.strategy.GardienStrat()) kb_strat.add("q", m.strategy.DribleStrat()) kb_strat.add("s", m.strategy.PassStrat()) kb_strat.add("d", m.strategy.AtkStrat()) team1 = SoccerTeam(name="Control Team") #team2 = SoccerTeam(name="Sparing") team1.add("ControlPlayer", kb_strat) #team2.add("Player",m.strategy.ShootStrat()) team2 = ia.get_team(1) simu = Simulation(team1, team2) #Jouer, afficher et controler la partie show_simu(simu) print("Nombre d'exemples : " + str(len(kb_strat.states))) # Sauvegarde des etats dans un fichier if simu.get_score_team(1) > simu.get_score_team(2): try: temp = load_jsonz(fname) temp += kb_strat.states dump_jsonz(temp, fname) except FileNotFoundError: dump_jsonz(kb_strat.states, fname)
def entrainer2v2_snap(self, fname1, fname2, nb_snap): if self.nb_players != 2: raise Exception( "Not the good number of players for this function.") #Creation d'une partie kb_strat1 = KeyboardStrategy() kb_strat1.add("a", m.strategy.ShootStrat()) kb_strat1.add("z", m.strategy.DefStrat()) kb_strat1.add("e", m.strategy.GardienStrat()) kb_strat1.add("q", m.strategy.DribleStrat()) kb_strat1.add("s", m.strategy.PassStrat()) kb_strat1.add("d", m.strategy.AtkStrat()) kb_strat2 = KeyboardStrategy() kb_strat2.add("a", m.strategy.ShootStrat()) kb_strat2.add("z", m.strategy.DefStrat()) kb_strat2.add("e", m.strategy.GardienStrat()) kb_strat2.add("q", m.strategy.DribleStrat()) kb_strat2.add("s", m.strategy.PassStrat()) kb_strat2.add("d", m.strategy.AtkStrat()) kb_strat2.idp = 1 sortie = False i = 0 while (not sortie) and i < nb_snap: state = self.create_rd_state() kb_strat1.state = state kb_strat2.state = state self.affiche_rd_state(state, 900, 600) joueur_0 = input("Choose strategy for player red 0 : ") joueur_1 = input("Choose strategy for player red 1 : ") kb_strat1.send_strategy(joueur_0) kb_strat2.send_strategy(joueur_1) if input("wanna continue?") == "n": sortie = True i += 1 try: temp_joueur_1 = load_jsonz(fname1) temp_joueur_1 += kb_strat1.states dump_jsonz(temp_joueur_1, fname1) except FileNotFoundError: dump_jsonz(kb_strat1.states, fname1) try: temp_joueur_2 = load_jsonz(fname2) temp_joueur_2 += kb_strat2.states dump_jsonz(temp_joueur_2, fname2) except FileNotFoundError: dump_jsonz(kb_strat2.states, fname2)
def entrainer(fname): #Creation d'une partie kb_strat = KeyboardStrategy() kb_strat.add("a", FonceurStrategy()) kb_strat.add("z", Milieu()) kb_strat.add("e", Gardien()) team1 = SoccerTeam(name="Contol Team") team2 = SoccerTeam(name="Sparing") team1.add("ControlPlayer", kb_strat) team2.add("Player", FonceurStrategy()) simu = Simulation(team1, team2) #Jouer, afficher et controler la partie show_simu(simu) print("Nombre d'exemples : " + str(len(kb_strat.states))) # Sauvegarde des etats dans un fichier dump_jsonz(kb_strat.states, fname)
def entrainer(fname): #Creation d'une partie kb_strat = KeyboardStrategy() kb_strat.add("q", GoToMyGoalStrategy()) kb_strat.add("z", PushUpStrategy()) kb_strat.add("p", PassStrategy()) kb_strat.add("m", ReceivePassStrategy()) kb_strat.add("d", CutDownAngleStrategy()) kb_strat.add("s", MarkStrategy()) team1 = SoccerTeam(name="Contol Team") team2 = ia.get_team(2) team1.add("ControlPlayer", kb_strat) team1.add(" ST", AttaquantStrategy(fn_st="st_dico_TME8.pkl")) simu = Simulation(team1, team2) #Jouer, afficher et controler la partie show_simu(simu) print("Nombre d'exemples : " + str(len(kb_strat.states))) # Sauvegarde des etats dans un fichier dump_jsonz(kb_strat.states, fname)
def entrainer(fichier): """ Simule un match dans lequel on doit intervenir pour générer un fichier d'apprentissage. Contrôles : a pour Fonceur, d pour Défenseur. """ #Création des équipes kb_strat = KeyboardStrategy() kb_strat.add("a", Fonceur()) kb_strat.add("d", Defenseur()) team1 = SoccerTeam(name="Moi") team2 = SoccerTeam(name="Idiots") team1.add("ControlPlayer", kb_strat) team2.add("Player", Fonceur()) #Jouer, afficher et controler la partie simu = Simulation(team1, team2) show_simu(simu) print("Nombre d'exemples : " + str(len(kb_strat.states))) # Sauvegarde des états dans un fichier dump_jsonz(kb_strat.states, fichier)
strat_j2.add('q',FonceStrategy()) strat_j2.add('s',StaticStrategy()) team1.add("Jexp 1",strat_j1) team1.add("Jexp 2",strat_j2) team2 = SoccerTeam("team2") team2.add("rien 1", StaticStrategy()) team2.add("rien 2", StaticStrategy()) simu = Simulation(team1,team2) show_simu(simu) # recuperation de tous les etats sur les 2 joueurs training_states = strat_j1.states+strat_j2.states # sauvegarde dans un fichier dump_jsonz(training_states,"test_states.jz") ### chargement d'un fichier sauvegarder states_tuple = load_jsonz("test_states.jz") ### Transformation d'un etat en features def my_get_features(state,idt,idp): """ extraction du vecteur de features d'un etat, ici distance a la balle, distance au but, distance balle but """ p_pos= state.player_state(idt,idp).position f1 = p_pos.distance(state.ball.position) f2= p_pos.distance( Vector2D((2-idt)*settings.GAME_WIDTH,settings.GAME_HEIGHT/2.)) f3 = state.ball.position.distance(Vector2D((2-idt)*settings.GAME_WIDTH,settings.GAME_HEIGHT/2.)) return [f1,f2,f3] #Nom des features (optionel) my_get_features.names = ["ball_dist","goal_dist","ballgoal_dist"]