Ejemplo n.º 1
0
 def alphabeta(self, state, recursiveValue, specie, alpha, beta):
     #condition d'arret
     if (self.maxRecursiveValue <= recursiveValue) or (
             state.getMembers(specie) == []) or (state.getMembers(
                 specie.inverse()) == []) or (
                     (time.time() - self.startTime) > self.maxTime):
         return self.calculateHeuristics(state)
     #branche alpha
     if specie == self.mySpecie:
         missionList = enumerate_possible_missions(state, specie,
                                                   self.branchFactor,
                                                   self.max_split_rate)
         for mission in missionList:
             alpha = max(
                 alpha,
                 self.alphabeta(mission.execute(state), recursiveValue + 1,
                                specie.inverse(), alpha, beta))
             if alpha > beta:
                 return beta
         return alpha
     #branche beta
     else:
         missionList = enumerate_possible_missions(state, specie,
                                                   self.branchFactor,
                                                   self.max_split_rate)
         for mission in missionList:
             beta = min(
                 beta,
                 self.alphabeta(mission.execute(state), recursiveValue + 1,
                                specie.inverse(), alpha, beta))
             if alpha > beta:
                 return alpha
         return beta
Ejemplo n.º 2
0
 def alphabeta(self, state, recursiveValue, specie,  alpha, beta):
     #condition d'arret
     if (self.maxRecursiveValue <= recursiveValue) or (state.getMembers(specie)==[]) or (state.getMembers(specie.inverse())==[]) or ((time.time()-self.startTime)>self.maxTime) :
         return  self.calculateHeuristics(state)
     #branche alpha
     if specie == self.mySpecie:
         missionList = enumerate_possible_missions(state, specie, self.branchFactor,self.max_split_rate)
         for mission in missionList:
             alpha = max(alpha, self.alphabeta(mission.execute(state),recursiveValue+1 , specie.inverse(),alpha, beta))
             if alpha > beta:
                 return beta
         return alpha
     #branche beta
     else:
         missionList = enumerate_possible_missions(state, specie, self.branchFactor,self.max_split_rate)
         for mission in missionList:
             beta=min(beta,self.alphabeta(mission.execute(state),recursiveValue+1, specie.inverse(),alpha, beta))
             if alpha > beta :
                 return alpha
         return beta
Ejemplo n.º 3
0
    def chooseMission(self, state):
        self.startTime = time.time() # on lance un timer au debut du tour, pour eviter le timeout

        possibleBranches = []
        missionlist = enumerate_possible_missions(state, self.mySpecie, self.branchFactor, self.max_split_rate)
        for mission in missionlist:
            assessedMission = [mission, 0]
            assessedMission[1] = self.alphabeta(mission.execute(state),1, self.mySpecie.inverse(),-100000, +100000) #appel recursif du alphabeta
            possibleBranches.append(assessedMission)
        #possibleBranches est une liste de tuples : <mission possible, note alphabeta de cette mission>, une mission etant constituée d'une liste d'actions pour chaque groupe
        coupFinal = sorted(possibleBranches, key=lambda x: (x[1]))[-1][0].calculateCoup(state) #on calcule le coup de la meilleure mission
        return coupFinal
Ejemplo n.º 4
0
    def chooseMission(self, state):
        self.startTime = time.time(
        )  # on lance un timer au debut du tour, pour eviter le timeout

        possibleBranches = []
        missionlist = enumerate_possible_missions(state, self.mySpecie,
                                                  self.branchFactor,
                                                  self.max_split_rate)
        for mission in missionlist:
            assessedMission = [mission, 0]
            assessedMission[1] = self.alphabeta(
                mission.execute(state), 1, self.mySpecie.inverse(), -100000,
                +100000)  #appel recursif du alphabeta
            possibleBranches.append(assessedMission)
        #possibleBranches est une liste de tuples : <mission possible, note alphabeta de cette mission>, une mission etant constituée d'une liste d'actions pour chaque groupe
        coupFinal = sorted(
            possibleBranches, key=lambda x: (x[1]))[-1][0].calculateCoup(
                state)  #on calcule le coup de la meilleure mission
        return coupFinal
Ejemplo n.º 5
0
# #plateau.addGroup(9,2,1, Species.human)
# #plateau.addGroup(9,4,2, Species.human)
# plateau.addGroup(1,1,3,Species.vampire)
# plateau.addThisGroup(myGroup)

# plateau = PlateauDeJeu(10, 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,1, Species.human)
# plateau.addGroup(9,4,2, Species.human)
# plateau.addGroup(4,3,4,Species.vampire)
# plateau.addThisGroup(myGroup)

plateau.print_plateau()
missionArray = enumerate_possible_missions(plateau, Species.werewolf, 10, 10)

for mission in missionArray:
    print("\nthis is a mission de note : " + str(mission.calc_mark()))
    # coup = mission.calculateCoup(plateau)
    for action in mission.actions:
        action_type = action.action_type
        assigned = action.assignedGroup
        target = action.target_group
        print("Action de type " + str(action_type) + " : " + str(assigned) +
              " vers " + str(target) + " note : " + str(action.mark))

    newstate = mission.execute(plateau)

    newstate.print_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)
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)
# 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)

# plateau = PlateauDeJeu(10, 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,1, Species.human)
# plateau.addGroup(9,4,2, Species.human)
# plateau.addGroup(4,3,4,Species.vampire)
# plateau.addThisGroup(myGroup)

plateau.print_plateau()
missionArray = enumerate_possible_missions(plateau, Species.werewolf, 10,10)

for mission in missionArray:
    print("\nthis is a mission de note : " + str(mission.calc_mark()))
    # coup = mission.calculateCoup(plateau)
    for action in mission.actions:
        action_type = action.action_type
        assigned = action.assignedGroup
        target = action.target_group
        print("Action de type " + str(action_type) + " : " + str(assigned) + " vers " + str(target)+" note : " + str(action.mark))

    newstate= mission.execute(plateau)

    newstate.print_plateau()