import glob import pickle CFG_1=dict({"ballBrakeConstant":0.08, "ballBrakeSquare":0.01}) CFG_2=dict({"ballBrakeConstant":0.05, "ballBrakeSquare":0.0025}) CFG_3=dict({"ballBrakeConstant":0.04, "ballBrakeSquare":0.004}) team1=SoccerTeam("Fonceur/Random") team1.add_player(SoccerPlayer("Fonceur",FonceurStrategy())) team1.add_player(SoccerPlayer("Random",RandomStrategy())) team2=SoccerTeam("Random/Random") team2.add_player(SoccerPlayer("Random 1",RandomStrategy())) team2.add_player(SoccerPlayer("Random 2",RandomStrategy())) list_key_player1=['a','z'] list_key_player2=['q','s'] list_strat_player1=[RandomStrategy(),FonceurStrategy()] list_strat_player2=[RandomStrategy(),FonceurStrategy()] # arguemnts : liste des touches, liste des strategies, nom du fichier, tout sauvegarder ou non, concatener dans un meme fichier a la suite ou non inter_strat_player1=InteractStrategy(list_key_player1,list_strat_player1,"test_interact.pkl") inter_strat_player2=InteractStrategy(list_key_player2,list_strat_player2,"test_interact.pkl",True)
pos = Vector2D.create_random() shoot = Vector2D.create_random() return SoccerAction(pos,shoot) def copy(self): return RandomStrategy() def create_strategy(self): return RandomStrategy() equipe1 = SoccerTeam("équipe1" ) equipe2 = SoccerTeam("équipe2") player1 = SoccerPlayer("joueur1",RandomStrategy()) player2 = SoccerPlayer("joueur2",RandomStrategy()) player3 = SoccerPlayer("joueur3",RandomStrategy()) player4 = SoccerPlayer("joueur4",RandomStrategy()) equipe1.add_player(player1) equipe2.add_player(player2) equipe1.add_player(player3) equipe2.add_player(player4) battle=SoccerBattle(equipe1,equipe2) obs=PygletObserver() obs.set_soccer_battle(battle) pyglet.app.run() class FonceurStrategy(SoccerStrategy): def _init_(self): self.name ="fonceur" def start_battle(self,state): pass def finish_battle(self,won) : pass
treeia.load(fn) TreeST=TreeStrategy("tree1",treeia) treeia1=TreeIA(gen_feature_simple,dict({"DefBis":DefenseurBis(),"Haut":Haut(),"Bas":Bas()})) fn=os.path.join(os.path.dirname(os.path.realpath(__file__)),"def_plusproche.pkl") treeia1.load(fn) TreeST1=TreeStrategy("tree2",treeia1) treeia2=TreeIA(gen_feature_simple,dict({"DefBis":DefenseurBis(),"Degage":Degage(),"TirerCoinHaut":TirerCoinHaut(),"TirerCoinBas":TirerCoinBas(),"Haut":Haut(),"Bas":Bas()})) fn=os.path.join(os.path.dirname(os.path.realpath(__file__)),"att2.pkl") treeia2.load(fn) TreeST2=TreeStrategy("tree3",treeia2) compo=ComposeStrategy(SurMemeLigneBis(),Rd()) team5.add_player(SoccerPlayer("tree1",TreeST)) team5.add_player(SoccerPlayer("Att2",TreeST2)) team5.add_player(SoccerPlayer("Goal",compo)) team5.add_player(SoccerPlayer("Tree 2",TreeST1)) team_tree.add_player(SoccerPlayer("Tree 1",TreeST)) team_tree.add_player(SoccerPlayer("G",compo)) team_tree.add_player(SoccerPlayer("DT",DegageTer())) team_tree.add_player(SoccerPlayer("Def",DefBis())) battle=SoccerBattle(team_tree,team5) obs=PygletObserver() obs.set_soccer_battle(battle) pyglet.app.run()
1 # -*- coding: utf-8 -*- """ Created on Mon Feb 9 11:34:52 2015 @author: 3301031 """ from soccersimulator import pyglet from soccersimulator import PygletObserver from soccersimulator import SoccerBattle, SoccerTeam, SoccerPlayer from soccersimulator import * from classes import * from apprentissage import * team1 = SoccerTeam("team1") team2 = SoccerTeam("team2") team1.add_player(SoccerPlayer("t1j1", TreeST())) team2.add_player(SoccerPlayer("t2j1", Goal1())) team1.add_player(SoccerPlayer("t1j2", RandomStrategy())) team2.add_player(SoccerPlayer("t2j2", RandomStrategy())) battle = SoccerBattle(team1, team2) obs = PygletObserver() obs.set_soccer_battle(battle) pyglet.app.run()
from soccersimulator import PygletObserver from soccersimulator import SoccerBattle from soccersimulator import SoccerPlayer, SoccerTeam, InteractStrategy, TreeStrategy from td1 import * from sklearn.tree import DecisionTreeClassifier import numpy as np import pickle import os from soccersimulator import SoccerStrategy from monequipe import teams list_key_player1 = ['a', 'e'] list_strat_player1 = [Fonceur(), DefStratBis()] inter_strat_player1 = InteractStrategy(list_key_player1, list_strat_player1, "best_goal") team1 = SoccerTeam("AI") team1.add_player(SoccerPlayer("AI", inter_strat_player1)) team2 = SoccerTeam("Normal") team2.add_player(SoccerPlayer("Def", Fonceur())) teams = [team1, team2] name = "AI Test" team1 = teams[0] team2 = teams[1] battle = SoccerBattle(team1, team2) obs = PygletObserver() obs.set_soccer_battle(battle) pyglet.app.run()
vitesse = state.ball.position - player.position tir = state.get_goal_center( self.get_op(teamid)) - player.position + state.get_goal_center( self.get_op(teamid)) - player.position return SoccerAction(vitesse, tir) def copy(self): return GoalFixeStrategy() def create_strategy(self): return GoalFixeStrategy() def get_op(self, teamid): if teamid == 1: return 2 else: return 1 #lancement partie team1 = SoccerTeam("team1") team2 = SoccerTeam("team2") team1.add_player(SoccerPlayer("t1j1", ZigStrategy())) team2.add_player(SoccerPlayer("t2j1", FonceurStrategy())) team1.add_player(SoccerPlayer("t1j2", GoalFixeStrategy())) team2.add_player(SoccerPlayer("t2j2", GoalFixeStrategy())) battle = SoccerBattle(team1, team2) obs = PygletObserver() obs.set_soccer_battle(battle) pyglet.app.run()
""" Created on Mon Mar 23 12:06:24 2015 @author: 3301031 """ from soccersimulator import pyglet from soccersimulator import PygletObserver from soccersimulator import SoccerBattle, SoccerTeam, SoccerPlayer from StratsSimples import * from apprentissage import * from soccersimulator import TreeStrategy from classes import * # équipe pas intelligente team1 = SoccerTeam("Mau F.C") team1.add_player(SoccerPlayer("t1j1", RandomStrategy())) # Apprentissage (équipes intelligentes) team_tree = SoccerTeam("Team Tree") # création équipe intelligente treeia=TreeIA(gen_feature_simple,dict({"immobile": Immobile(), "Allerverscages": AllerVersCages(), "random": RandomStrategy(),"fonceur": JoueurFonceur(),\ "allerversballe": AllerVersBalle(), "haut": Haut(), "bas": Bas(), "gauche": Gauche(), "droit": Droit(), "allertirerbas": AllerTirerBas(),\ "allertirerhaut": AllerTirerHaut(), "allertirercages": AllerTirerCages()})) # strats nécessaire pour mon défenseur intelligent fn = os.path.join(os.path.dirname(os.path.realpath(__file__)), "Defenseur1") treeia.load(fn) TreeST = TreeStrategy("Defenseur1", treeia) team_tree.add_player(SoccerPlayer("jintel1", TreeST)) teams = [team1, team_tree]
# -*- coding: utf-8 -*- from soccersimulator import SoccerPlayer, SoccerTeam, InteractStrategy, TreeStrategy from strats import RandomStrategy, FonceurStrategy from apprentissage import * from apprentissage import gen_feature_simple team1=SoccerTeam("Fonceur Random") team1.add_player(SoccerPlayer("Fonceur",FonceurStrategy())) team1.add_player(SoccerPlayer("Random",RandomStrategy())) team2=SoccerTeam("Random Random") team2.add_player(SoccerPlayer("Random 1",RandomStrategy())) team2.add_player(SoccerPlayer("Random 2",RandomStrategy())) list_key_player1=['a','z'] list_strat_player1=[RandomStrategy(),FonceurStrategy()] inter_strat_player1=InteractStrategy(list_key_player1,list_strat_player1,"joueur1") team3 = SoccerTeam("Interactive") team3.add_player(SoccerPlayer("Inter 1",inter_strat_player1)) team3.add_player(SoccerPlayer("Rand",RandomStrategy())) team_tree = SoccerTeam("Team Tree") treeia=TreeIA(gen_feature_simple,dict({"Random":RandomStrategy(),"Fonceur":FonceurStrategy()})) ### Apprentissage fn=os.path.join(os.path.dirname(os.path.realpath(__file__)),"myfirsttree.pkl") treeia.load(fn) TreeST=TreeStrategy("tree1",treeia)
#team1.add_player(SoccerPlayer("t1j4",PasBouger())) comp = ComposeStrategy(SurMemeLigneHorizHaut(), TirerVersP()) compo = ComposeStrategy(AllerVersBalle(), Dribbler()) comp1 = ComposeStrategy(SurMemeLigneHorizBas(), TirerVersP()) comp2 = ComposeStrategy(AllerVersBalle(), AleatoireBis()) # bonne equipe voir si je la change avec tomate ou aubergine #team2.add_player(SoccerPlayer(";)",DegageTer())) #team2.add_player(SoccerPlayer("t2j1",DeGoal())) #team2.add_player(SoccerPlayer("attaq",Def())) #team2.add_player(SoccerPlayer("def",Defenseur())) #goal = ComposeStrategy(SurMemeLigneBis(),Rd()) #team3.add_player(SoccerPlayer("Def2",DegageTer())) #team3.add_player(SoccerPlayer("pDef",comp1)) #team3.add_player(SoccerPlayer("Rd",Rd())) team3.add_player(SoccerPlayer("Def1", DefenseurBis())) #team3.add_player(SoccerPlayer("MixS",MixSimple())) team3.add_player(SoccerPlayer("Deg", FonceurStrategy())) team5.add_player(SoccerPlayer("FS", Degage())) team5.add_player(SoccerPlayer("DT", Goal())) #team5.add_player(SoccerPlayer("DC",DefBis())) #team5.add_player(SoccerPlayer("MS",DefenseurBis())) battle = SoccerBattle(team5, team3) obs = PygletObserver() obs.set_soccer_battle(battle) pyglet.app.run()
from soccersimulator import SoccerBattle, SoccerPlayer, SoccerTeam from soccersimulator import PygletObserver,ConsoleListener,LogListener from soccersimulator import pyglet from strategies import RunnerStrategy, DefendStrategy from apprentissage import * team1 = SoccerTeam("Aventurier Errant") team1.add_player(SoccerPlayer("t1j1", RunnerStrategy("Runner"))) team2 = SoccerTeam("Aventuriers Errants") team2.add_player(SoccerPlayer("t2j1", RunnerStrategy("Runner"))) team2.add_player(SoccerPlayer("t2j2", DefendStrategy("Defend"))) team4 = SoccerTeam("Aventuriers Errants") team4.add_player(SoccerPlayer("t4j1", RunnerStrategy("Runner"))) team4.add_player(SoccerPlayer("t4j2", RunnerStrategy("Runner"))) team4.add_player(SoccerPlayer("t4j3", DefendStrategy("Defend"))) team4.add_player(SoccerPlayer("t4j4", DefendStrategy("Defend"))) ## Overpowered ## oeam1 = SoccerTeam("Overpowered") oeam1.add_player(OverpoweredPlayer("t1j1")) oeam2 = SoccerTeam("Overpowered") oeam2.add_player(OverpoweredPlayer("t2j1")) oeam2.add_player(OverpoweredPlayer("t2j2")) oeam4 = SoccerTeam("Overpowered") oeam4.add_player(OverpoweredPlayer("t4j1")) oeam4.add_player(OverpoweredPlayer("t4j2")) oeam4.add_player(OverpoweredPlayer("t4j3"))
# -*- coding: utf-8 -*- """ Created on Mon Jan 26 19:32:52 2015 @author: 3301031 """ from soccersimulator import SoccerBattle, SoccerTeam, SoccerPlayer from classes import * team1=SoccerTeam("C.A BocaJuniors 2v2") team1.add_player(SoccerPlayer("t1j1",Dribbleur())) team1.add_player(SoccerPlayer("t1j2",Dribbleur())) team2=SoccerTeam("Argentina 4v4") team2.add_player(SoccerPlayer("t2j1",Attaquant())) team2.add_player(SoccerPlayer("t2j2",Goal())) team2.add_player(SoccerPlayer("t2j3",Intercepteur())) team2.add_player(SoccerPlayer("t2j4",Intercepteur())) team3=SoccerTeam("DiegoMaradona 1v1") team3.add_player(SoccerPlayer("t2j1",ComposeStrategy(GoalContreAttaque(), JoueurFonceur()))) teams = [team1, team2, team3]
"CoinHaut": CoinHaut(), "CoinBas": CoinBas(), "Haut": Haut(), "Bas": Bas(), "Rd": Rd() })) fn = os.path.join(os.path.dirname(os.path.realpath(__file__)), "defenseurcoin.pkl") treeia.load(fn) TreeST = TreeStrategy("tree1", treeia) #team5.add_player(SoccerPlayer("DC",TreeST)) #team5.add_player(SoccerPlayer("FS",comp)) #team5.add_player(SoccerPlayer("DT",comp)) team5.add_player(SoccerPlayer("Def", DefenseurBis())) team5.add_player(SoccerPlayer("MS", FonceurStrategy())) ############################################################################### # apprentissage #list_key_player1=['s','z','x','d','q'] #list_strat_player1=[DefenseurBis(),CoinHaut(),CoinBas(),Haut(),Bas()] #list_strat_player1=[Defen,Haut(),Bas()] list_key_player1 = ['q', 's', 'z', 'x', 'a', 'w'] list_strat_player1 = [ DefBis(), Degage(), TirerCoinHaut(), TirerCoinBas(), Haut(), Bas()
from soccersimulator import pyglet from soccersimulator import PygletObserver, LogObserver, PygletReplay from soccersimulator import SoccerBattle, SoccerPlayer, SoccerTeam from soccersimulator import InteractStrategy from strategies import * import glob import pickle CFG_1 = dict({"ballBrakeConstant": 0.08, "ballBrakeSquare": 0.01}) CFG_2 = dict({"ballBrakeConstant": 0.05, "ballBrakeSquare": 0.0025}) CFG_3 = dict({"ballBrakeConstant": 0.04, "ballBrakeSquare": 0.004}) team2 = SoccerTeam("Coureur") team2.add_player(SoccerPlayer("t2j1", RunnerStrategy("Runner"))) team2.add_player(SoccerPlayer("t2j2", RunnerStrategy("Runner"))) team2.add_player(SoccerPlayer("t2j3", DefendStrategy("Runner"))) team2.add_player(SoccerPlayer("t2j4", DefendStrategy("Runner"))) team4 = SoccerTeam("Interceptuer") team4.add_player(OverpoweredPlayer("t4j1")) team4.add_player(OverpoweredPlayer("t4j2")) team4.add_player(OverpoweredPlayer("t4j3")) team4.add_player(OverpoweredPlayer("t4j4")) #battle = SoccerBattle(teams[2], teams[1]) #obs = PygletObserver() #obs.set_soccer_battle(battle) #pyglet.app.run()
treeia = TreeIA( gen_feature_simple, dict({ "DefenseurBis": DefenseurBis(), "CoinHaut": CoinHaut(), "CoinBas": CoinBas(), "Haut": Haut(), "Bas": Bas() })) fn = os.path.join(os.path.dirname(os.path.realpath(__file__)), "defenseurcoin1.pkl") treeia.load(fn) TreeST = TreeStrategy("tree1", treeia) team1 = SoccerTeam("Poireaux") team1.add_player(SoccerPlayer("t1j1", DegageTer())) team4 = SoccerTeam("Carottes") team4.add_player(SoccerPlayer("t4j2", MixSimple())) team2 = SoccerTeam("Patates") team2.add_player(SoccerPlayer("t2j1", Degage())) team2.add_player(SoccerPlayer("t2j2", DefenseurBis())) team6 = SoccerTeam("Oignons") team6.add_player(SoccerPlayer("t6j1", TreeST)) team6.add_player(SoccerPlayer("t6j2", DegageTer())) team3 = SoccerTeam("Aubergines") team3.add_player(SoccerPlayer("t3j1", DefenseurBis())) team3.add_player(SoccerPlayer("t3j2", DefBis()))
return SoccerAction(pos,shoot) else: shoot = state.get_goal_center(1)-player.position return SoccerAction(pos,shoot) def copy(self): return TirBut() def create_strategy(self): return TirBut() class GoalToGoal(SoccerStrategy): def __init__(self): self.name="GtoG" def start_battle(self,state): pass def finish_battle(self,won): pass def compute_strategy(self,state,player,teamid): global stop=0 if(player) team1=SoccerTeam("team1") team2=SoccerTeam("team2") team1.add_player(SoccerPlayer("t1j1",TirBut())) team2.add_player(SoccerPlayer("t2j1",FonceurStrategy())) battle=SoccerBattle(team1,team2) obs=PygletObserver() obs.set_soccer_battle(battle) pyglet.app.run()
from soccersimulator import pyglet from soccersimulator import PygletObserver from soccersimulator import SoccerPlayer, SoccerTeam, InteractStrategy, TreeStrategy from apprentissage import * from apprentissage import gen_feature_simple from StratsSimples import * from classes import * list_key_player1 = ['w', 'x', 'e', 'r', 't'] list_strat_player1 = [ AllerVersCages(), Immobile(), AllerTirerBas(), AllerTirerHaut(), AllerTirerCages() ] inter_strat_player1 = InteractStrategy(list_key_player1, list_strat_player1, "Defenseur1") team1 = SoccerTeam("Argentina") team3 = SoccerTeam("MauFc") team3.add_player(SoccerPlayer("Inter 1", inter_strat_player1)) team1.add_player(SoccerPlayer("t1j1", JoueurFonceur())) battle = SoccerBattle(team1, team3) obs = PygletObserver() obs.set_soccer_battle(battle) pyglet.app.run() #dot: definition de l'arbre
from soccersimulator import SoccerBattle, SoccerPlayer, SoccerTeam from soccersimulator import PygletObserver,ConsoleListener,LogListener from soccersimulator import pyglet from base_strategie import * from ToolBox import * team1=SoccerTeam("Minute Maid Tropical") team1.add_player(SoccerPlayer("t1j1",Goal1v1Strategy())) team2=SoccerTeam("Minute Maid Orange") team2.add_player(SoccerPlayer("t2j1",DefenseurStrategy())) team2.add_player(SoccerPlayer("t2j2",FonceurStrategy())) team3=SoccerTeam("Minute Maid Pomme") team3.add_player(SoccerPlayer("t1j1",FonceurStrategy())) team3.add_player(SoccerPlayer("t1j4",DefenseurStrategy())) team3.add_player(SoccerPlayer("t1j3",Goal1v1Strategy())) team3.add_player(SoccerPlayer("t1j2",FonceurStrategy())) teams =[team1, team2, team3]
def compute_strategy(self, state, player, teamid): pos = state.ball.position - player.position shoot = Vector2D(0, 0) if (PLAYER_RADIUS + BALL_RADIUS) >= (state.ball.position.distance( player.position)): shoot = Vector2D.create_random(-5, 5) teamadverse = 2 if teamid == 2: teamadverse = 1 state.get_goal_center(teamadverse) return SoccerAction(pos, shoot) def copy(self): return JoueurFonceur() def create_strategy(self): return JoueurFonceur() team1 = SoccerTeam("team1") team2 = SoccerTeam("team2") team1.add_player(SoccerPlayer("t1j1", JoueurFonceur())) team2.add_player(SoccerPlayer("t2j1", JoueurFonceur())) team1.add_player(SoccerPlayer("t1j2", RandomStrategy())) team2.add_player(SoccerPlayer("t2j2", RandomStrategy())) battle = SoccerBattle(team1, team2) obs = PygletObserver() obs.set_soccer_battle(battle) pyglet.app.run()
''' Stratégie de mouvement Se déplace vers un point indiqué ''' class AllerVersLoc(SoccerStrategy): def __init__(self, localisation): self.loc = localisation pass def start_battle(self,state): pass def finish_battle(self,won): pass def compute_strategy(self,state,player,teamid): mouvement = loc - player.position return SoccerAction(mouvement) def copy(self): return AllerVersLoc() def create_strategy(self): return AllerVersLoc() '''Fenêtre de test de partie''' team1=SoccerTeam("team1") team2=SoccerTeam("team2") team1.add_player(SoccerPlayer("t1j1",AllerVersLoc(Vector2D(0,0)))) team2.add_player(SoccerPlayer("t2j1",AllerVersLoc(Vector2D(5,20)))) battle=SoccerBattle(team1,team2) obs=PygletObserver() obs.set_soccer_battle(battle) pyglet.app.run()
#-*- coding: utf-8 -*- import pyglet from soccersimulator import Vector2D, SoccerBattle, SoccerPlayer, SoccerTeam, SoccerStrategy, SoccerAction, GAME_WIDTH, GAME_HEIGHT from soccersimulator import PygletObserver, ConsoleListener, LogListener, PLAYER_RADIUS, BALL_RADIUS, mdpsoccer from classe_basique import * from joueur_alea import * teama = SoccerTeam("teama") teamb = SoccerTeam("teamb") teama.add_player(SoccerPlayer("t1j1", GoalStrategy())) teama.add_player(SoccerPlayer("t1j2", FonceurStrategy())) teamb.add_player( SoccerPlayer("t2j1", ComposeStrategy(GoalStrategy(), Degager()))) teamb.add_player(SoccerPlayer("t2j2", PremSelector())) print teama print teamb battle = SoccerBattle(teama, teamb) obs = PygletObserver() obs.set_soccer_battle(battle) pyglet.app.run() from monequipe import teams
from soccersimulator import SoccerBattle, SoccerPlayer, SoccerTeam from soccersimulator import PygletObserver,ConsoleListener,LogListener from soccersimulator import pyglet from joueur_alea import RandomStrategy, GoalStrategy, FonceurStrategy from classe_basique import * from joueur_alea import * team1=SoccerTeam("Forever_alone") team1.add_player(SoccerPlayer("t1j1",FonceurStrategy())) team4=SoccerTeam("Mais_Fonce") team4.add_player(SoccerPlayer("t1j1",FonceurStrategy())) team2=SoccerTeam("Messi_dribble_ta_team") team2.add_player(SoccerPlayer("t1j1",ComposeStrategy(GoalStrategy(),Degager()))) team2.add_player(SoccerPlayer("t1j2",PremSelector())) team3=SoccerTeam("One_job:Marquer") team3.add_player(SoccerPlayer("t1j1",FonceurStrategy())) team3.add_player(SoccerPlayer("t1j2",FonceurStrategy())) team3.add_player(SoccerPlayer("t1j3",GoalStrategy())) team3.add_player(SoccerPlayer("t1j4",Defenseur())) teams =[team1,team2,team3,team4]