Пример #1
0
    def choose(self, game, x):
        current_state = game.OfficialState
        FinalAnswer = [None, None, None, None]

        MyActions = [current_state.get_actions(x, i) for i in range(4)]
        TheirActions = [
            current_state.get_actions((x + 1) % 2, i) for i in range(4)
        ]

        analysis = []

        for a in MyActions[0]:
            printf("ding!\n")
            for b in MyActions[1]:
                printf("dong!\n")
                for c in MyActions[2]:
                    for d in MyActions[3]:

                        best = float("-inf")
                        worst = float("inf")
                        average = float("-inf")
                        util = 0

                        for e in TheirActions[0]:
                            for f in TheirActions[1]:
                                for g in TheirActions[2]:
                                    for h in TheirActions[3]:
                                        temp = current_state.apply_action(
                                            [[a, b, c, d], [e, f, g, h]])
                                        util = temp[0].utility(x)
                                        if (best > util): best = util
                                        if (worst < util): worst = util
                                        average += util

                        average /= (len(e) * len(f) * len(g) * len(h))
                        util = self.AggressiveWeight * best + self.DefensiveWeight * worst + self.NominalWeight * average
                        #analysis[[a,b,c,d]] = util
                        analysis.append(([a, b, c, d], util))

        optkey = [None, None, None, None]
        optval = float("-inf")
        for item in analysis:
            key = item[0]
            val = item[1]
            if (val > optval):
                optkey = key
                optval = val

        return optkey
Пример #2
0
    def choose(self,game,x):
    
        #Debug stuff
        game.OfficialState.report_teams()
        
        current_state = game.OfficialState
        FinalAnswer = [None,None,None,None]
        
        MyActions = [current_state.get_actions(x,i) for i in range(4)]
        TheirActions = [current_state.get_actions((x+1)%2,i) for i in range(4)]

        AllActions = []        
        if(x == 0):
            AllActions = [MyActions,TheirActions]
        else:
            AllActions = [TheirActions,MyActions]

        #MUST REDUCE HERE
        
        """
        Ideas for reduction:
        
        (1) Mages, Wizards, and Healers will NOT basic-attack if they have mana
        (2) Thieves will only poison OR attack, never both.
        
        
        """

                
        j1 = [current_state.Teams[x][i].job for i in range(4)]
        j2 = [current_state.Teams[(x+1)%2][i].job for i in range(4)]
        
        #printf("ME: %s  %s  %s  %s\n",j1[0],j1[1],j1[2],j1[3])
        #printf("THEM: %s  %s  %s  %s\n",j2[0],j2[1],j2[2],j2[3])
        
        for i in range(2):
            for j in range(4):
                if(AllActions[i][j] == [None]): continue
                #printf("WHat the hell %d %d\n",i,j)
                #printf("Surprise! It's %s\n", AllActions[i][j])
            
            
                guy = current_state.Teams[i][j]
                if (guy.job == "Wizard" or guy.job == "Healer" or guy.job == "Mage"):
                    if(guy.mp[0] > 0):
                        c1 = len(AllActions[i][j])
                        list_tuple_truncate(AllActions[i][j],1,0) #Truncate all Attack commands
                        c2 = len(AllActions[i][j])
                        if(c1 == c2):
                            printf("OH SHIT!!!!\n")
                   
                if(guy.job == "Thief" and guy.mp[0] > 0):
                    
                
                    for k in range(4):
                        if(current_state.Teams[(i+1)%2][k].statuses[0]): continue
                    
                        #if poisoned, kill Poison
                        if (current_state.Teams[(i+1)%2][k].statuses[3]): 
                            AllActions[i][j].remove(((i,j),8,((i+1)%2,k))) #If Poisoned, drop Poison
                    
                        #else if max HP above 150, then drop Attack
                        else:
                        #elif (current_state.Teams[(i+1)%2][k].hp[1] >= 150): 
                            AllActions[i][j].remove(((i,j),0,((i+1)%2,k)))
                    
                        #else drop Poison
                        #else: 
                            #AllActions[i][j].remove(((i,j),8,((i+1)%2,k)))
        
        #end for
        
     
        analysis = []
        
        myproduct = len(MyActions[0])*len(MyActions[1])*len(MyActions[2])*len(MyActions[3])
        theirproduct = len(TheirActions[0])*len(TheirActions[1])*len(TheirActions[2])*len(TheirActions[3])
        lolproduct = myproduct * theirproduct
        
        a = len(MyActions[0])
        b = len(MyActions[1])
        c = len(MyActions[2])
        d = len(MyActions[3])
        
        e = len(TheirActions[0])
        f = len(TheirActions[1])
        g = len(TheirActions[2])
        h = len(TheirActions[3])
        
        
        #printf("ALERT! THE PERMUTATION POOL IS (%d * %d * %d * %d) * (%d * %d * %d * %d) = %d * %d = %d!!!\n\n", a,b,c,d,e,f,g,h,myproduct, theirproduct, lolproduct)

        contenders = snag_choices(TheirActions,self.depth)
        
        for a in MyActions[0]:
            printf("ding!\n")
            for b in MyActions[1]:
                #printf("dong!\n")
                for c in MyActions[2]:
                    for d in MyActions[3]:
                        
                        best = float("-inf")
                        worst = float("inf")
                        average = 0
                        util = 0
                       
                        for act in contenders:
                            temp = None
                            if (x ==0):
                                temp = current_state.apply_action([[a,b,c,d],act])
                            elif (x == 1):
                                temp = current_state.apply_action([act,[a,b,c,d]])
                            util = temp[0].utility(x)
                            #printf("GOD DAMN IT %d\n\n",util)
                            if(util > best): 
                                best = util
                            if(util < worst): 
                                worst = util
                            average = average + util
                        
                        average /= self.depth
                        #printf("WHYYYY %d %d %d\n",best,worst,average)
                        util = self.AggressiveWeight*best + self.DefensiveWeight*worst + self.NominalWeight*average
                        #analysis[[a,b,c,d]] = util
                        analysis.append(([a,b,c,d],util))
                        #printf("Oh come on %s decomposing into %s  %s\n",analysis[-1],analysis[-1][0],analysis[-1][1])
        
        optkey = [None,None,None,None]
        optval = float("-inf")
        for item in analysis:
            key = item[0]
            val = item[1]
            if(val > optval):
                optkey = key
                optval = val

        printf("OPTKEY IS %s\n\n",optkey)
        return optkey
    def choose(self, game, x):

        #Debug stuff
        game.OfficialState.report_teams()

        current_state = game.OfficialState
        FinalAnswer = [None, None, None, None]

        #printf("GOD DAMN IT!!!    %s\n\n\n\n",x)

        TheActions = self.get_good_options(game, x)

        MyActions = TheActions[0]
        TheirActions = TheActions[1]

        random.shuffle(TheirActions)

        AllActions = []
        if (x == 0):
            AllActions = [MyActions, TheirActions]
        else:
            AllActions = [TheirActions, MyActions]

        #MUST REDUCE HERE
        """
        Ideas for reduction:
        
        (1) Mages, Wizards, and Healers will NOT basic-attack if they have mana
        (2) Thieves will only poison OR attack, never both.
        
        
        """

        analysis = []

        #printf("ALERT! THE PERMUTATION POOL IS (%d * %d * %d * %d) * (%d * %d * %d * %d) = %d * %d = %d!!!\n\n", a,b,c,d,e,f,g,h,myproduct, theirproduct, lolproduct)

        #contenders = snag_choices(TheirActions,self.depth)

        ide = 0
        for lol in MyActions:
            ide += 1
            if (ide % 50 == 0):
                printf("ding %s/%s!\n", ide, len(MyActions))
            best = float("-inf")
            worst = float("inf")
            average = 0
            util = 0

            for act in TheirActions[:self.depth]:

                #printf('OH COME ON %s    %s\n\n\n\n',lol,act)
                temp = None
                if (x == 0):
                    temp = current_state.apply_action([lol, act])
                elif (x == 1):
                    temp = current_state.apply_action([act, lol])
                util = temp[0].utility(x)
                #printf("GOD DAMN IT %d\n\n",util)
                if (util > best):
                    best = util
                if (util < worst):
                    worst = util
                average = average + util

            average /= self.depth
            #printf("WHYYYY %d %d %d\n",best,worst,average)
            util = self.AggressiveWeight * best + self.DefensiveWeight * worst + self.NominalWeight * average
            #analysis[[a,b,c,d]] = util
            analysis.append((lol, util, best - worst))
            #printf("Oh come on %s decomposing into %s  %s\n",analysis[-1],analysis[-1][0],analysis[-1][1])

        optkey = [None, None, None, None]
        #if(len(analysis) == 0):
        #printf("NO NO NO NO NOOOO!!!!!\n\n\n")
        #raw_input()
        optval = float("-inf")
        opttie = 0
        for item in analysis:
            #printf("wgwegwoij %s\n",item)
            key = item[0]
            val = item[1]
            tie = item[2]

            if (val > optval):
                optkey = key
                optval = val
                opttie = tie
            elif (val == optval):
                if (tie < opttie):
                    optkey = key
                    opttie = tie

        printf("OPTKEY IS %s\n\n", optkey)
        #raw_input()
        return optkey
Пример #4
0
    def choose(self, game, x):

        if x == 0:
            return

        current_state = game.OfficialState
        FinalAnswer = [None, None, None, None]

        MyActions = [current_state.get_actions(x, i) for i in range(4)]
        TheirActions = [
            current_state.get_actions((x + 1) % 2, i) for i in range(4)
        ]

        AllActions = []
        if (x == 0):
            AllActions = [MyActions, TheirActions]
        else:
            AllActions = [TheirActions, MyActions]

        j1 = [current_state.Teams[x][i].job for i in range(4)]
        j2 = [current_state.Teams[(x + 1) % 2][i].job for i in range(4)]

        printf("ME: %s  %s  %s  %s\n", j1[0], j1[1], j1[2], j1[3])
        printf("THEM: %s  %s  %s  %s\n", j2[0], j2[1], j2[2], j2[3])

        analysis = []

        myproduct = len(MyActions[0]) * len(MyActions[1]) * len(
            MyActions[2]) * len(MyActions[3])
        theirproduct = len(TheirActions[0]) * len(TheirActions[1]) * len(
            TheirActions[2]) * len(TheirActions[3])
        lolproduct = myproduct * theirproduct

        a = len(MyActions[0])
        b = len(MyActions[1])
        c = len(MyActions[2])
        d = len(MyActions[3])

        e = len(TheirActions[0])
        f = len(TheirActions[1])
        g = len(TheirActions[2])
        h = len(TheirActions[3])

        #printf("ALERT! THE PERMUTATION POOL IS (%d * %d * %d * %d) * (%d * %d * %d * %d) = %d * %d = %d!!!\n\n", a,b,c,d,e,f,g,h,myproduct, theirproduct, lolproduct)

        for a in MyActions[0]:
            #printf("ding!\n")
            for b in MyActions[1]:
                #printf("dong!\n")
                for c in MyActions[2]:
                    for d in MyActions[3]:

                        best = float("-inf")
                        worst = float("inf")
                        average = 0
                        util = 0

                        temp = current_state.apply_action(
                            [game.Actions[0], [a, b, c, d]])

                        util = temp[0].utility(x)

                        if (util > best):
                            best = util
                        if (util < worst):
                            worst = util
                        average = average + util

                        #average /= (len(e)*len(f)*len(g)*len(h))
                        #printf("WHYYYY %d %d %d\n",best,worst,average)
                        util = self.AggressiveWeight * best + self.DefensiveWeight * worst + self.NominalWeight * average
                        #analysis[[a,b,c,d]] = util
                        analysis.append(([a, b, c, d], util))
                        #printf("Oh come on %s decomposing into %s  %s\n",analysis[-1],analysis[-1][0],analysis[-1][1])

        optkey = [None, None, None, None]
        optval = float("-inf")
        for item in analysis:
            key = item[0]
            val = item[1]
            if (val > optval):
                optkey = key
                optval = val

        printf("OPTKEY IS %s\n\n", optkey)
        return optkey
Пример #5
0
def manual_choice(game, team):
    returnme = [None, None, None, None]

    # Now to actually describe the actions
    thestate = game.OfficialState
    for i in range(4):
        os.system('cls' if os.name == 'nt' else 'clear')

        for guy in thestate.Teams[0] + thestate.Teams[1]:
            printf("%s:    HP:%d/%d    MP:%d/%d    ", guy.name, guy.hp[0],
                   guy.hp[1], guy.mp[0], guy.mp[1])
            if (guy.statuses[0]):
                printf("DEAD ")
            if (guy.statuses[3]):
                printf("POISONED ")
            if (guy.statuses[4]):
                printf("LOCKED")
            printf("\n")

        printf("\n\n")

        if (thestate.Teams[team][i].hp < 0
                or thestate.Teams[team][i].statuses[0]):
            pass
        else:  #if actual thingie

            blahlist = thestate.get_actions(team, i)

            a = thestate.Teams[team][i]
            printf("%s's Turn: \n\n", a)
            for j in range(10):
                if (a.actions[j] != 0 and ability.Costs[j] <= a.mp[0]
                        and list_tuple_find(blahlist, 1, j)):
                    printf("%d: %s\n", j, ability.Names[j])
            validaction = False
            s = -1
            while (not validaction):
                printf("Pick Ability")
                s = raw_input(': ')
                if (not isuint(s)):
                    s = '9999'
                s = int(s)
                validaction = (s < 10 and a.actions[s] != 0
                               and ability.Costs[s] <= a.mp[0]
                               and list_tuple_find(blahlist, 1, s))

            #Now that the action has been made:

            if (ability.targetingType(s) == 0):
                returnme[i] = ((team, i), s, (team, i))

            elif (ability.targetingType(s) == 2):  #AE ally
                returnme[i] = ((team, i), s, (team, ))

            elif (ability.targetingType(s) == 4):  #AE enemy
                returnme[i] = ((team, i), s, ((team + 1) % 2, ))

            else:  #Begin Selection of targets

                validtarget = False

                blahlist = thestate.get_actions(team, i)

                targetlist = []
                for item in blahlist:
                    #printf("%s\n",item)
                    if (item[1] == s):
                        targetlist.append(item)
                #now that the target list is cleaned

                for j in range(len(targetlist)):
                    #printf("%s\n",targetlist[j])
                    printf("%d: %s\n", j,
                           namedisplay(thestate, targetlist[j][2]))
                t = -1

                while (not validtarget):
                    printf("Pick Target", )
                    t = raw_input(': ')
                    if (not isuint(t)):
                        t = '9999'
                    t = int(t)
                    validtarget = (t < len(targetlist))
                returnme[i] = (targetlist[t])

    return returnme
Пример #6
0
    def playGame(self, redagent, blueagent, verbose=False):
        self.Verbose = verbose
        self.Agents[0] = redagent
        self.Agents[1] = blueagent
        self.OfficialState = GameState()

        while (self.OfficialState.teamscore(0) > 0
               and self.OfficialState.teamscore(1) > 0
               ):  #While not a terminal state
            self.PlayByPlay = []

            for i in range(2):
                for j in range(4):
                    self.OfficialState.Teams[i][j].statuses[1] = None
                    self.OfficialState.Teams[i][j].statuses[2] = None

            self.Actions[0] = self.Agents[0](self, 0)
            self.Actions[1] = self.Agents[1](self, 1)

            temp = self.OfficialState.apply_action(self.Actions)

            self.OfficialState = temp[0]
            self.PlayByPlay = temp[1]

            if (verbose):
                os.system('cls' if os.name == 'nt' else 'clear')
                for item in self.PlayByPlay:
                    if (item[0] is None):
                        printf("ALERT: %s takes %d damage from poison!\n",
                               item[3][0], item[4][0])
                    else:
                        printf("%s uses %s!\n", item[0],
                               ability.Names[item[1]])

                        if (item[1] == 1):  #if guard
                            continue

                        for i in range(len(item[3])):
                            if (item[2][i] != item[3][i]):
                                printf("    %s is protected by %s!\n",
                                       item[2][i], item[3][i])
                            if (item[4][i] is True):
                                if (item[1] == 2):  #if Cover
                                    printf("    %s protects %s!\n", item[0],
                                           item[3][i])

                            else:
                                if (item[4][i] > 0):
                                    printf("    %s takes %d damage!\n",
                                           item[3][i], item[4][i])
                                    if (item[1] == 8):  #if Poison
                                        printf("        %s is poisoned!\n",
                                               item[3][i])
                                    if (item[3][i].statuses[0]):
                                        printf("        %s has fallen!\n",
                                               item[3][i])

                                if (item[4][i] < 0):
                                    printf("    %s heals %d HP!\n", item[3][i],
                                           -item[4][i])
                                    if (item[3][i].statuses[0]):
                                        printf(
                                            "        Unfortunately, %s remains dead.\n",
                                            item[3][i])

                blah = raw_input('Press ENTER to continue: ')
                os.system('cls' if os.name == 'nt' else 'clear')

        if (self.OfficialState.teamscore(0) > 0):
            return 0
        if (self.OfficialState.teamscore(1) > 0):
            return 1
        return -1
Пример #7
0
 def report_teams(self):
     os.system('cls' if os.name == 'nt' else 'clear')
     for guy in self.Teams[0] + self.Teams[1]:
         printf("%s:    HP:%d/%d    MP:%d/%d    ", guy.name, guy.hp[0],
                guy.hp[1], guy.mp[0], guy.mp[1])
         if (guy.statuses[0]):
             printf("DEAD ")
         if (guy.statuses[3]):
             printf("POISONED ")
         if (guy.statuses[4]):
             printf("LOCKED")
         printf("\n")
     printf("\n\n")