Example #1
0
def exempleIA(IA,team1, team2, it, ip):
    match = SoccerMatch(team1,team2)
    #on reinitisalise fichier
    a = open("Match","w")
    a.close()
    match.play()
    match.save("Match")
    Monte_Carlo("Match","action",it,ip,IA.dico)
    a = open("action","w")
    a.close()
Example #2
0
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")
Example #3
0
def 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)
    #on reinitisalise fichier
    a = open("Match","w")
    a.close()
    match.play()
    match.save("Match")
Example #4
0
def creation_scenario(etats, action, it, ip):
    #un scenario est un tuple (etat_discret, action, SoccerState
    m = SoccerMatch.load(etats)
    f = open(action,"r")
    a = f.read()
    liste = a.split()
    f.close()
    i = 0
    scenario = []
    for etat_j in m.states:
        #pb nombre d'etat variable celon les match
        if (i < len(liste)):
            tuple = (transformation_etat(etat_j,it,ip), liste[i],etat_j)
            scenario.append(tuple)
            i = i + 1
    #print("scenario : \n",scenario)
    return scenario
Example #5
0
import soccersimulator
import math
import random
from soccersimulator import settings
from soccersimulator import BaseStrategy, SoccerAction
from soccersimulator import SoccerTeam, SoccerMatch
from soccersimulator import Vector2D, Player, SoccerTournament
from Strategie import *
from Team import *

match = SoccerMatch(team1, team2, 2000)
soccersimulator.show(match)
Example #6
0
    for i in range(0,10):
        a.write("\n goal")
    a.close()
    f = open('dico_apprentissage','r')
    dicoIA = pickle.load(f)
    f.close()
    Monte_Carlo("fichier","action",1,0)
    print("enregistre le dico")
    enregistre_dico(dicoIA)

#on supprime le fichier action apres l'apprentissage
a = open("action","w")
a.close()

if __name__ == "__main__":
    match = SoccerMatch(teamIA, teamAdv2)
    #on efface l'ancien match
    a = open("fichier","w")
    a.close()
    
    
    #Si on veut enregister le dictionnaire
    temp = sys.stdout
    sys.stdout = open("dico_apprentissage","w")
    print(IA.dico)
    sys.stdout.close()
    sys.stdout = temp
    
    soccersimulator.show(match)
    match.save("fichier")
Example #7
0
import soccersimulator
from soccersimulator import SoccerMatch


m1= SoccerMatch.load("IAGardien.match")
soccersimulator.show(m1)

m2= SoccerMatch.load("IAGardien2.match")
soccersimulator.show(m2)

Example #8
0
import soccersimulator
from soccersimulator.settings import *
from soccersimulator import SoccerTeam, SoccerMatch, Player
from Strategies import *
from team import *

match = SoccerMatch(Priya_4a, Priya_2b)
soccersimulator.show(match)
Example #9
0
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)
    nb_tournois = args.nbp if args.nbp else [1,2,4]
    retour = not args.noretour
    if args.replay:
        tournoi = None
        try:
            tournoi = SoccerTournament.load(args.replay)
            tournoi._matches = dict([ (kk,v) for kk,v in tournoi._matches.items() if not args.only or tournoi.get_team(kk[0]).login in args.only
                                      or tournoi.get_team(kk[1]).login in args.only ])

            print("Tournoi charge")
            print(tournoi.format_scores())
        except:
            pass
        if tournoi is None:
            try:
                tournoi = SoccerMatch.load(args.replay)
                print("Match charge")
            except:
                pass
        if tournoi is None:
            print("Format non reconnu")
        else:
            show(tournoi)
        sys.exit(0)

    if args.git:
        dl_from_github(liste_login,path)
    if args.date:
        check_date(liste_login,path)
    tournois = dict()
    for t in nb_tournois:
Example #11
0
t1= SoccerTeam("Qq",[Player("QPlayer",QStrat)])
t2 = SoccerTeam("Adv",[Player("j1",J_1vs1_Strat)])

mat = SoccerMatch(t1,t2)
#soccersimulator.show(mat)
print
cpt = 0
while cpt<=0:
    print "CPT", cpt
    print "      "

    print "BEGIN match.play()"
    #mat.play()
    soccersimulator.show(mat)
    SoccerMatch.save(mat,"matchQlearn4")

    print "      "
    print "### FIn match.play Now MAJ ##"


    # FAIRE LA MISE A JOUR APRES AVOIR JOUE MATCH 
    maj(mat,1,0,NOM_FICHIER_DIC)
    print " ## FIN MAJJJ##"

    print "CA CETAIT POUR MATCH CPT", cpt

    cpt+=1

print "FIN FINALE"
Example #12
0

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")
Example #13
0
from soccersimulator import show
from soccersimulator import SoccerTeam, Player, SoccerMatch
from team import team1, team2, team4, team2bis

show(SoccerMatch(team2, team2bis))
""" 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 strategies import FonceurStrategy, DefenseStrategy, RandomStrategy
import sys

if __name__ == "__main__":
    prefix = "tree"
    if len(sys.argv) > 1:
        prefix = sys.argv[1]
    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("Fonceur", FonceurStrategy()),
        Player("Defense", DefenseStrategy())
    ])
    match = SoccerMatch(team_noob, team_bad, 1000)
    show(match)
    strat_key.write(prefix + ".exp", True)
Example #15
0
# nom et strategie du premier joueur
print team1.player_name(0), team1.strategy(0)

joueur1 = Player("Joueur 2", BaseStrategy("fonceetshoot"))
joueur2 = Player("Goal 2", BaseStrategy("defenseduGoal"))
print joueur1.name, joueur2.strategy, joueur2.name, joueur2.strategy
team2 = SoccerTeam("Equipe 2", [Joueur 2, Goal 2])
# nombre de joueurs de l equipe
print team1.nb_players
# renvoie la liste des noms, la liste des strategies
print team1.players_name, team1.strategies
# nom et strategie du premier joueur
print team1.player_name(0), team1.strategy(0)

#Creer un match entre 2 equipes et de duree 2000 pas
match = SoccerMatch(team1, team2, 2000)
#Jouer le match (sans le visualiser)
match.play()
#Jouer le match en le visualisant
show(match)
#Attention !! une fois le match joue, la fonction play() permet de faire jouer le replay
# mais pas de relancer le match !!!
# Pour regarder le replay d un match
show(match)
# Pour sauvegarder un match
match.save("fichier")
# Pour charger un match
match = SoccerMatch.load("fichier")
# Pour reinitialiser un match
match.reset()
Example #16
0
# -*- 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))
Example #17
0
def init_fichier(team1 ,team2):
    if os.path.getsize("Match") == 0:
        match = SoccerMatch(team1,team2)
        match.save("Match")
Example #18
0
        tournoi = None
        try:
            tournoi = SoccerTournament.load(args.replay)
            tournoi._matches = dict([
                (kk, v) for kk, v in tournoi._matches.items()
                if not args.only or tournoi.get_team(kk[0]).login in args.only
                or tournoi.get_team(kk[1]).login in args.only
            ])

            print("Tournoi charge")
            print(tournoi.format_scores())
        except:
            pass
        if tournoi is None:
            try:
                tournoi = SoccerMatch.load(args.replay)
                print("Match charge")
            except:
                pass
        if tournoi is None:
            print("Format non reconnu")
        else:
            show(tournoi)
        sys.exit(0)

    if args.git:
        dl_from_github(liste_login, path)
    if args.date:
        check_date(liste_login, path)
    tournois = dict()
    for t in nb_tournois:
Example #19
0
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)


Example #20
0
# -*- 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")
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))
Example #22
0
])

#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)
Example #23
0
from projet import *
from PlayerDecorator import *
from zone import *


joueur1 = Player("Joueur 1", fonceStrat)
joueur2 = Player("Joueur 2", gardien)
joueur3 = Player("Joueur 3", MilieuStrategy())
joueur4 = Player("Joueur 4", attaque)
joueur5 = Player("Joueur 5", defense)
joueur6 = Player("Joueur 6", j_solo)

team1 = SoccerTeam("team1",[joueur6])
test = SoccerTeam("test",[joueur1])
team2 = SoccerTeam("team2",[joueur2,joueur4])
team4 = SoccerTeam("team4",[joueur2,joueur5,joueur4,joueur1])

#apprentissage supervise
strat = KeyboardStrategy()
strat.add("f",fonceStrat)
strat.add("g",gardien)
strat.add("a",attaque)
strat.add("d",defense)

eleve = Player("eleve",strat)
team_spe = SoccerTeam("team_eleve",[eleve])

#match = SoccerMatch(team1, team_spe)
match = SoccerMatch(team4, team4)
soccersimulator.show(match)