Exemplo n.º 1
0
    def __init__(self, ip, port):
        self.game_over = 0
        # Création de la socket
        self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

        # Récupération de l'addresse ip et le port
        self.ip = ip
        self.port = port

        # Connexion de la socket
        try:
            self.sock.connect((self.ip, self.port))
        except Exception as error:
            print("Connection error: ", error)

        # Autres Initialisations
        self.Plateau = PlateauDeJeu(
        )  # initialisation de la map, avec 0 ligne, 0 colonnes, 0 maisons, 0 humains, 0 vampires, 0 LG
        # le plateau de jeu est un simple tableau d'instances de la classe Groupe
        self.IA = Intelligence()  # initialisation de l'IA
Exemplo n.º 2
0
from IA import Intelligence
from species import Species
from Plateau import PlateauDeJeu

ia = Intelligence()
ia.mySpecie = Species.werewolf

Plateau = PlateauDeJeu(10,10)
Plateau.addGroup(1,1,5,Species.human)
Plateau.addGroup(10,10,5,Species.vampire)
Plateau.addGroup(5,5,10,Species.werewolf)

h = ia.calculateHeuristics(Plateau)
print("L\'heuristique vaut " + str(h))
print(h==5)

Exemplo n.º 3
0
from species import Species
from Plateau import PlateauDeJeu
from group import Group
from missions_generator import enumerate_possible_missions

plateau = PlateauDeJeu(13, 5)

myGroup = Group(4, 1, 4, Species.werewolf)
plateau.addGroup(2, 2, 4, Species.human)
plateau.addGroup(9, 0, 2, Species.human)
plateau.addGroup(9, 2, 2, Species.human)
plateau.addGroup(9, 1, 2, Species.human)
plateau.addGroup(9, 3, 2, Species.human)
plateau.addGroup(9, 4, 2, Species.human)

plateau.addGroup(12, 1, 3, Species.vampire)
plateau.addGroup(12, 3, 3, Species.werewolf)

plateau.addGroup(4, 3, 4, Species.vampire)
plateau.addThisGroup(myGroup)

# plateau = PlateauDeJeu(5, 6)
# myGroup = Group(5, 4, 2, Species.werewolf)
# plateau.addGroup(4,4,2,Species.werewolf)
# plateau.addGroup(3,4,1,Species.human)
# plateau.addGroup(2,4,1,Species.human)
# plateau.addGroup(2,2,1,Species.human)
# #plateau.addGroup(9,2,1, Species.human)
# #plateau.addGroup(9,4,2, Species.human)
# plateau.addGroup(1,1,3,Species.vampire)
# plateau.addThisGroup(myGroup)
Exemplo n.º 4
0
from IA import Intelligence
from species import Species
from Plateau import PlateauDeJeu
from group import Group
from actions_generator import enumerate_possible_actions

plateau = PlateauDeJeu(10, 5)

myGroup = Group(4,4,1,Species.werewolf)
plateau.addGroup(2,2,4,Species.human)
plateau.addGroup(9,0,2,Species.human)
plateau.addGroup(9,2,1, Species.human)
plateau.addGroup(9,4,2, Species.human)
plateau.addGroup(1,3,4,Species.vampire)
plateau.addThisGroup(myGroup)
plateau.print_plateau()
print("Enumeration actions ...\n")
actions = enumerate_possible_actions(plateau, myGroup, Species.werewolf)

for actionSimple in actions[0]:
    action_type = actionSimple.action_type
    assigned = actionSimple.assignedGroup
    target = actionSimple.target_group
    print("Action de type " + str(action_type) + " : " + str(assigned) + " vers " + str(target) + ", note : " + str(actionSimple.calc_mark(plateau)))

for twoActions in actions[1]:
    group0 = twoActions[0].assignedGroup
    group1 = twoActions[1].assignedGroup
    print("split " + str(group0.eff) + ", " + str(group1.eff))
    print("   " + str(twoActions[0]) + " : " + str(twoActions[0].calc_mark(plateau)))
    print("   " + str(twoActions[1]) + " : " + str(twoActions[1].calc_mark(plateau)))
from species import Species
from Plateau import PlateauDeJeu
from group import Group
from missions_generator import enumerate_possible_missions

plateau = PlateauDeJeu(5, 5)

plateau.addGroup(4, 3, 6, Species.vampire)
plateau.addGroup(4, 4, 4, Species.vampire)
plateau.addGroup(4, 0, 3, Species.human)
plateau.addGroup(3, 0, 3, Species.human)
plateau.addGroup(0, 4, 10, Species.werewolf)

plateau.print_plateau()

missionArray = enumerate_possible_missions(plateau, Species.vampire)

for mission in missionArray:
    print("\n\nNOUVELLE MISSION, note : ", mission.calc_mark(plateau))
    print(mission)
    coup = mission.calculateCoup(plateau)
    print(coup)
Exemplo n.º 6
0
    def update(self):
        primitiveOrder = self.sock.recv(3)  # pas décodé
        order = primitiveOrder.decode("utf-8")
        if not order:
            print("Bizarre, c'est vide")

        if order == "UPD":
            # mettez à jour votre Plateau à partir des tuples contenus dans changes
            print("j'ai reçu UPD")
            n = self.recv(1)[0]
            changes = []
            for i in range(n):
                changement = self.recv(
                    5
                )  # chaque changement a la forme [X, Y, nombre_H, nombre_V, nombre_L]
                self.updateGroups(changement)

            # calculez votre coup, c'est ici le coeur de l'aglo
            coup = self.IA.chooseMission(self.Plateau)
            # calcule le coup de l'IA, qui est un tableau de
            # Nx5 chiffres(x_dep,y_dep,nombre,x_arr,y_arr)_
            # préparez la trame MOV ou ATK
            self.send("MOV", coup)

        elif order == "SET":
            lines = (self.recv(1)[0])
            columns = (self.recv(1)[0])
            print("J'ai recu SET")
            self.Plateau.height = lines
            self.Plateau.width = columns

        elif order == "HUM":
            n = self.recv(1)[0]
            for i in range(n):
                for j in range(2):
                    self.recv(
                        1
                    )[0]  #on depile juste la socket mais c'est un ordre déprécié

        elif order == "HME":
            x = self.recv(1)[0]
            y = self.recv(1)[0]
            print("J'ai reçu HME :", x, y)
            self.Plateau.maMaison = [x, y]

        elif order == "MAP":
            n = self.recv(1)[0]
            changes = []
            for i in range(n):
                changement = self.recv(5)
                changes.append(changement)
            for changement in changes:
                x = changement[0]
                y = changement[1]
                humains = changement[2]
                vamp = changement[3]
                lg = changement[4]
                if humains > 0:
                    self.Plateau.addGroup(x, y, humains, Species.human)
                elif vamp > 0:
                    self.Plateau.addGroup(x, y, vamp, Species.vampire)
                elif lg > 0:
                    self.Plateau.addGroup(x, y, lg, Species.werewolf)
                else:
                    print("espèce non attendue reçue en commande MAP")
            myGroupe = self.Plateau.getGroup(self.Plateau.maMaison[0],
                                             self.Plateau.maMaison[1])
            self.IA.mySpecie = myGroupe.species

        elif order == "END":
            self.Plateau = PlateauDeJeu()  # réinitialise le Plateau
            self.IA = Intelligence()  # réinitialise l' IA

        elif order == "BYE":
            self.sock.close()
            self.game_over = 1
        else:
            print("commande non attendue recue", order)