def affiche_joue_IA(IA,teamIA, teamAdv,it, ip): #si le fichier d'action n'est pas vide on apprend if os.path.getsize("action") != 0: Monte_Carlo("Match","action",it,ip,IA.dico) #on supprime les anciennes actions a = open("action","w") a.close() match = SoccerMatch(teamIA, teamAdv) a = open("Match","w") a.close() match.play() soccersimulator.show(match) match.save("Match")
def compute_strategy(self, state, id_team, id_player): if id_team == 1: position_milieu_but = Vector2D(x=150.0, y=45.0) if id_team == 2: position_milieu_but = Vector2D(x=0.0, y=45.0) vector_acc = state.ball.position - state.player_state(id_team, id_player).position if state.ball.position.distance(state.player_state(id_team, id_player).position) < BALL_RADIUS + PLAYER_RADIUS: vector_shoot = position_milieu_but - state.ball.position else: vector_shoot = Vector2D() return SoccerAction(vector_acc, vector_shoot) team1 = SoccerTeam("team1", [(Player("t1j1", RandomStrategy())), (Player("t1j2", RandomStrategy()))]) team2 = SoccerTeam("team2", [Player("t2j1", RandomStrategy()), (Player("t2j2", RandomStrategy()))]) team3 = SoccerTeam("team3", [Player("t3j1", RandomStrategy())]) match = SoccerMatch(team1, team2) soccersimulator.show(match) tournoi = SoccerTournament(1) tournoi.add_team(team1) tournoi.add_team(team2) tournoi.add_team(team3) soccersimulator.show(tournoi)
from soccersimulator import SoccerMatch, show, SoccerTeam,Player,KeyboardStrategy from decisiontree import DTreeStrategy, gen_features import cPickle from coordination import * from team import * import sys ### Entrainer un arbre de la team1IA prefix = "tree" if len(sys.argv)>1: prefix = sys.argv[1] strat_key = KeyboardStrategy(fn="monfichier.exp") #fn veut dire filename strat_key.add("f", fonceur_shooteur) strat_key.add("b", buteur) strat_key.add("r", runv_goal) strat_key.add("t", runv_goal_arr) strat_key.add("d", dribleur) strat_key.add("g", gardienIA) #Joueur de la team1IA t1j1 = Player("t1j1", strat_key) dogomet1 = SoccerTeam("dogomet1", [t1j1]) match_dogomet1 = SoccerMatch(dogomet1, lalya0) if __name__=="__main__": show(match_dogomet1)
# -*- coding: utf-8 -*- from soccersimulator import show from soccersimulator import SoccerTeam, Player, SoccerMatch from team import team2,team1 import Asparodia,hmdd,fifa2016,jordanupmc,Kabegami,lounisAmazigh,luluperet,LysaGaridi,zero #from strat import strat #strat = KeyboardStrategy() #strat.add("d",StrategyD()) #strat.add("f",StrategyF()) #strat.add("r",StrategyR()) #strat.add("a",StrategyA()) #strat.add("i",StrategyI()) #strat.add("g",StrategyG()) #show(SoccerMatch(hmdd.team1,team2)) show(SoccerMatch(team1,team2)) #strat.write("monfichier.exp")
# -*- coding: utf-8 -*- """ Created on Mon Feb 1 16:19:08 2016 @author: 3200404 """ from soccersimulator import show from soccersimulator import SoccerMatch from team import * #if __name__ == __main__: #show(SoccerMatch(teama4,teamREAL)) #show(SoccerMatch(team1j,team2j)) #show(SoccerMatch(teamPSG4,teama4)) show(SoccerMatch(team2j,team2j2)) #show(SoccerMatch(teama4,teamIA))
# -*- coding: utf-8 -*- from soccersimulator import show from soccersimulator import SoccerTeam, Player, SoccerMatch from team import team2, team1 import Asparodia, hmdd, fifa2016, jordanupmc, Kabegami, lounisAmazigh, luluperet, LysaGaridi, zero #from strat import strat #strat = KeyboardStrategy() #strat.add("d",StrategyD()) #strat.add("f",StrategyF()) #strat.add("r",StrategyR()) #strat.add("a",StrategyA()) #strat.add("i",StrategyI()) #strat.add("g",StrategyG()) #show(SoccerMatch(hmdd.team1,team2)) show(SoccerMatch(team1, team2)) #strat.write("monfichier.exp")
D1= [d1,d2,d3,d4,d5] D2= [d5,d4,d3,d2,d1] Liste = [] Liste.append(team1) Liste.append(team2) Liste.append(team3) Liste.append(team4) Liste.append(team5) Liste.append(team6) ListeT = [] ListeT.append(duo1) ListeT.append(duo2) ListeT.append(duo3) ListeT.append(duo4) ListeT.append(duo5) ListeT.append(duo6) if __name__ == "__main__": init_fichier(team1,team2) #exemple_tournoi(IA,L1,Liste,1,0,10) tournoi_IA(IA,teamIAD,ListeT,1,0,10,False) #affiche_joue_IA(IA,teamIA,team5,1,0) M = SoccerMatch(teamIAD, duo1) M.play() soccersimulator.show(M) enregistre_dico(IA.dico,"dico_apprentissage")
""" Permet de jouer et d'entrainer une strategie * changer les strategies ajoutees * utilisation : python entrainer prefix_fichier_exemple par defaut ajoute au fichier d'exemples sil existe deja (extension : .exp pour le fichier exemple) """ from soccersimulator import SoccerMatch, show, SoccerTeam,Player,KeyboardStrategy from WalterIA import * import sys if __name__=="__main__": prefix = "tree" if len(sys.argv)>1: prefix = sys.argv[1] strat_key = KeyboardStrategy() strat_key.add("e",all2(3)) strat_key.add("a",gogole()) strat_key.add("z",all2(2)) team_noob = SoccerTeam("keyb",[Player("KBs", strat_key)]) team_bad = SoccerTeam("foncteam",[Player("Fonceur",all2(3))]) match = SoccerMatch(team_noob,team_bad,2000) show(match) strat_key.write(prefix+".exp",True)
from decisiontree import DTreeStrategy, gen_features import cPickle from coordination import * from team import * import sys ### Entrainer un arbre de la team2IA prefix = "tree" if len(sys.argv)>1: prefix = sys.argv[1] strat_key = KeyboardStrategy(fn="monfichier2.exp") #fn veut dire filename strat_key.add("f", fonceur_shooteur) strat_key.add("b", buteur) strat_key.add("r", runv_goal) strat_key.add("t", runv_goal_arr) strat_key.add("d", dribleur) strat_key.add("g", gardienIA) #Les deux joueurs de la team2IA t2j1 = Player("t2j1", strat_key) t2j2 = Player("t2j2", strat_key) dogomet2 = SoccerTeam("dogomet2", [t2j1], [t2j2]) match_dogomet2 = SoccerMatch(dogomet2, lalya2) if __name__=="__main__": show(match_dogomet2)
from soccersimulator import show from soccersimulator import SoccerMatch from soccersimulator import KeyboardStrategy from team import lalya1, lalya2, lalya4, lalya1bis, lalya0 from coordination import * match_lalya1 = SoccerMatch(lalya1, lalya1) match_lalya2 = SoccerMatch(lalya2, lalya2) match_lalya4 = SoccerMatch(lalya4, lalya4) match_lalya5 = SoccerMatch(lalya4, lalya2) if __name__ == "__main__": strat = KeyboardStrategy(fn="monfichier.exp") #fn veut dire filename strat.add("d", defenseur) #Ensuite on ajoute les joueurs, bref... show(match_lalya5)
BaseStrategy.__init__(self,"Random") def compute_strategy(self,state,id_team,id_player): if id_team==1: position_milieu_but=Vector2D(x=150.,y=45.) if id_team==2: position_milieu_but=Vector2D(x=0.,y=45.) vector_acc=state.ball.position-state.player_state(id_team,id_player).position if (state.ball.position.distance(state.player_state(id_team,id_player).position)<BALL_RADIUS+PLAYER_RADIUS): vector_shoot=position_milieu_but-state.ball.position else: vector_shoot=Vector2D() return SoccerAction(vector_acc,vector_shoot) team1= SoccerTeam("team1",[(Player("t1j1",RandomStrategy())),(Player("t1j2",RandomStrategy()))]) team2= SoccerTeam("team2",[Player("t2j1",RandomStrategy()),(Player("t2j2",RandomStrategy()))]) team3= SoccerTeam("team3",[Player("t3j1",RandomStrategy())]) match=SoccerMatch(team1,team2) soccersimulator.show(match) tournoi=SoccerTournament(1) tournoi.add_team(team1) tournoi.add_team(team2) tournoi.add_team(team3) soccersimulator.show(tournoi)
import soccersimulator from soccersimulator import SoccerMatch m1= SoccerMatch.load("IAGardien.match") soccersimulator.show(m1) m2= SoccerMatch.load("IAGardien2.match") soccersimulator.show(m2)
from decisiontree import DTreeStrategy from soccersimulator import SoccerMatch, show, SoccerTeam, Player, KeyboardStrategy from decisiontree import gen_features import cPickle #### Arbres de decisions import os fn = os.path.join(os.path.dirname(os.path.realpath(__file__)), "test.pkl") tree = cPickle.load(file(fn)) dic = { "Random": RandomStrategy(), "Fonceur": FonceurStrategy(), "Defense": DefenseStrategy() } treeStrat = DTreeStrategy(tree, dic, gen_features) ### Entrainer un arbre strat_key = KeyboardStrategy() strat_key.add("a", RandomStrategy()) strat_key.add("z", FonceurStrategy()) strat_key.add("e", DefenseStrategy()) team_noob = SoccerTeam( "keyb", [Player("KBs", strat_key), Player("Defense", DefenseStrategy())]) team_bad = SoccerTeam( "foncteam", [Player("IA", treeStrat), Player("Defense", DefenseStrategy())]) show(SoccerMatch(team_noob, team_bad))
import soccersimulator from soccersimulator import SoccerMatch mat1= SoccerMatch.load("MatchQLearn5") soccersimulator.show(mat1) mat1= SoccerMatch.load("MatchQLearn3") soccersimulator.show(mat1) mat1= SoccerMatch.load("MatchQLearn2") soccersimulator.show(mat1) mat1= SoccerMatch.load("MatchQLearnndef1") soccersimulator.show(mat1) mat1= SoccerMatch.load("MatchQLearnndef4") soccersimulator.show(mat1) mat1= SoccerMatch.load("MatchQLearnndef2") soccersimulator.show(mat1)
from soccersimulator import show from soccersimulator import SoccerTeam,Player, SoccerMatch from team import team1, team2, team4, team2bis show(SoccerMatch(team2,team2bis))
import soccersimulator, soccersimulator.settings,math,Walter as W from soccersimulator.settings import * from soccersimulator import SoccerTeam as STe,SoccerMatch as SM, Player, SoccerTournament as ST, BaseStrategy as AS, SoccerAction as SA, Vector2D as V2D,SoccerState as SS settings=soccersimulator.settings psg= STe("psg",[Player("Thiago Silva",W.all(2))]) marseille= STe("marseille",[Player("Ocampos",W.all2(3))]) match=SM(psg,marseille) soccersimulator.show(match) #tournoi=ST(1) #tournoi.add_team(psg) #tournoi.add_team(marseille) #soccersimulator.show(tournoi)
# -*- coding: utf-8 -*- """ Created on Mon Feb 1 16:19:08 2016 @author: 3200404 """ from soccersimulator import show from soccersimulator import SoccerMatch from team import * #if __name__ == __main__: show(SoccerMatch(teamPSG4,teamREAL))
]) #team1=SoccerTeam("team1",[Player("t1j1",StateLessStrategy(fonceur)),Player("t1j2",StateLessStrategy(fonceur)),Player("t1j3",StateLessStrategy(fonceur)),Player("t1j4",StateLessStrategy(fonceur))]) #team2=SoccerTeam("team1",[Player("t1j1",StateLessStrategy(Smart1v1)),Player("t1j2",StateLessStrategy(Smart1v1)),Player("t1j3",StateLessStrategy(Smart1v1)),Player("t1j4",StateLessStrategy(Smart1v1))]) strat = KeyboardStrategy() #ou pour une sauvegarde automatique #KeyboardStrategy(fn="monfichier.exp") FS = StateLessStrategy(fonceur) GK = StateLessStrategy(QuickFollow) strat.add("d", FS) strat.add("a", GK) player1 = Player("j1", strat) team1 = SoccerTeam("team1", [player1]) team2 = SoccerTeam("team2", [Player("t2j1", StateLessStrategy(Smart1v1))]) match = SoccerMatch(team1, team2) show(match) strat.write("monfichier.exp") #match=SoccerMatch(team1,team2) #soccersimulator.show(match) #tournoi = SoccerTournament(1) #tournoi.add_team(team1) #tournoi.add_team(team2) #tournoi.play() #soccersimulator.show(tournoi)
from soccersimulator import show from soccersimulator import SoccerTeam, Player, SoccerMatch from team import team1, team2, team4, team2bis show(SoccerMatch(team2, team2bis))