You and your friends have been battling it out with your Rock 'Em, Sock 'Em robots, but things have gotten a little boring. You've each decided to add some amazing new features to your robot and automate them to battle to the death.

Each robot will be represented by an object. You will be given two robot objects, and an object of battle tactics and how much damage they produce. Each robot will have a name, hit points, speed, and then a list of battle tacitcs they are to perform in order. Whichever robot has the best speed, will attack first with one battle tactic. 

Your job is to decide who wins.

Example:
```python
 robot_1 = {
  "name": "Rocky",
  "health": 100,
  "speed": 20,
  "tactics": ["punch", "punch", "laser", "missile"]
 }
 robot_2 = {
   "name": "Missile Bob",
   "health": 100,
   "speed": 21,
   "tactics": ["missile", "missile", "missile", "missile"]
 }
 tactics = {
   "punch": 20,
   "laser": 30,
   "missile": 35
 }
 
 fight(robot_1, robot_2, tactics) -> "Missile Bob has won the fight."
```

robot2 uses the first tactic, "missile" because he has the most speed. This reduces robot1's health by 35. Now robot1 uses a punch, and so on. 

**Rules**

- A robot with the most speed attacks first. If they are tied, the first robot passed in attacks first.
- Robots alternate turns attacking. Tactics are used in order.
- A fight is over when a robot has 0 or less health or both robots have run out of tactics.
- A robot who has no tactics left does no more damage, but the other robot may use the rest of his tactics.
- If both robots run out of tactics, whoever has the most health wins. Return the message "{Name} has won the fight."
- If both robots run out of tactics and are tied for health, the fight is a draw. Return "The fight was a draw."

**To Java warriors**

`Robot` class is immutable.


Check out my other 80's Kids Katas:


80's Kids #1: How Many Licks Does It Take
80's Kids #2: Help Alf Find His Spaceship
80's Kids #3: Punky Brewster's Socks
80's Kids #4: Legends of the Hidden Temple
80's Kids #5: You Can't Do That on Television
80's Kids #6: Rock 'Em, Sock 'Em Robots
80's Kids #7: She's a Small Wonder
80's Kids #8: The Secret World of Alex Mack
80's Kids #9: Down in Fraggle Rock 
80's Kids #10: Captain Planet

Difficulty: introductory

Starter code:

def fight(robot_1, robot_2, tactics):
	

Solutions:
from operator import itemgetter

def fight(r1, r2, tactics):
    
    i, bots = 0, sorted((r2,r1), key=itemgetter('speed'))                    # Get the bots in reversed order!
    for r in bots: r['tactics'] = r['tactics'][::-1]                         # Reverse the tactics to use pop()
    
    while 1:
        i ^= 1                                                               # Swapper
        if bots[i]['tactics']:
            bots[i^1]['health'] -= tactics[ bots[i]['tactics'].pop() ]       # Hit
        
        if bots[i^1]['health'] <= 0 or all(not r['tactics'] for r in bots):  # other bot is dead or no tactics for both of them
            break
    
    a,b = bots
    cmp = (a['health'] < b['health']) - (a['health'] > b['health'])          # 1: b wins / -1: a wins / 0: tie
    
    return "The fight was a draw." if not cmp else f"{bots[max(cmp,0)]['name']} has won the fight."

def fight(robot_1, robot_2, tactics):
    attack, defend = (robot_1, robot_2) if robot_1['speed'] >= robot_2['speed'] else (robot_2, robot_1)
    
    while attack['health'] > 0:
        if attack['tactics']:
            defend['health'] -= tactics[attack['tactics'].pop()]
        elif not defend['tactics']:
            break
        attack, defend = defend, attack

    if attack['health'] == defend['health']:
        return "The fight was a draw."
    return "{} has won the fight.".format((defend if attack['health'] < defend['health'] else attack)['name'])



def fight(robot_1, robot_2, tactics):
    # Determine the fastest robot for the rest of the fight
    if robot_2['speed'] > robot_1['speed']:
        robot_first = robot_2
        robot_second = robot_1
    else:
        robot_first = robot_1
        robot_second = robot_2
    
    while ((len(robot_first['tactics']) > 0) or (len(robot_second['tactics']) > 0)):
          if len(robot_first['tactics']) > 0:
              robot_second['health'] -= tactics[robot_first['tactics'].pop(0)]
          if robot_second['health'] <= 0:
              return f"{robot_first['name']} has won the fight." 
          
          if len(robot_second['tactics']) > 0:
              robot_first['health'] -= tactics[robot_second['tactics'].pop(0)]
          if robot_first['health'] <= 0:
              return f"{robot_second['name']} has won the fight." 
    else:
        if robot_first['health'] == robot_second['health']:
            return "The fight was a draw."
        else: 
            winner = robot_first['name'] if robot_first['health'] > robot_second['health'] else robot_second['name']
            return f'{winner} has won the fight.'


class Fighter(object):
    
    def __init__(self, dict  ):
        self.name   = dict[  'name' ] 
        self.health = dict[ 'health']
        self.speed  = dict[ 'speed' ]
        self.tact   = dict['tactics']
        self.still_alive = True
        
    def battle(self, punch, point):
        self.health -= point.get(punch, 0) 
    
    def raund(self, other, tact):
        if all((self.health > 0 , self.tact)):
            punch = self.tact.pop(0)
            other.battle( punch, tact) 
        else:
            self.still_alive = False
    
def fight(robot_1, robot_2, tactics):
    f1, f2 = Fighter(robot_1), Fighter(robot_2)
    fght = [ sorted([f1  , f2], key = lambda e: e.speed)[::-1] , [f1,f2] ][f1.speed == f2.speed]

    while fght[0].still_alive:
        fght[0].raund( fght[1], tactics)  
        fght = fght[::-1] 
          
    winer = [f1.name, f2.name][ f2.health > f1.health ]
    return [f'{winer} has won the fight.', 'The fight was a draw.'][f1.health == f2.health]


import pprint
def fight(robot_1, robot_2, tactics):
    if robot_1['speed'] < robot_2['speed']:
        robot_1, robot_2 = robot_2, robot_1
    robot_1_turn = True
    
    while ((robot_1['health'] > 0 and robot_2['health'] > 0) and 
        (len(robot_1['tactics']) > 0 or len(robot_2['tactics']) > 0)):
        if robot_1_turn and len(robot_1['tactics']) > 0:
            robot_2['health'] -= tactics[robot_1['tactics'][0]]
            robot_1['tactics'].pop(0)
        elif len(robot_2['tactics']) > 0:
            robot_1['health'] -= tactics[robot_2['tactics'][0]]
            robot_2['tactics'].pop(0)
        robot_1_turn = not robot_1_turn
    
    if robot_1['health'] <= 0 or robot_1['health'] < robot_2['health']:
        return  robot_2['name'] + ' has won the fight.'
    elif robot_2['health'] <= 0 or robot_2['health'] < robot_1['health']:
        return  robot_1['name'] + ' has won the fight.'
    else:
        return  'The fight was a draw.'


def fight(A, B, damage):
    if B['speed'] > A['speed']: A, B = B, A

    while A['tactics'] or B['tactics']:
        for attack, defend in [(A, B), (B, A)]:
            if attack['tactics']:
                defend['health'] -= damage[attack['tactics'][0]]
                attack['tactics'] = attack['tactics'][1:]
                if defend['health'] <= 0: return attack['name'] + ' has won the fight.'
                
    return 'The fight was a draw.' if A['health'] == B['health'] else [B, A][A['health'] > B['health']]['name'] + ' has won the fight.'    

def fight(robot_1, robot_2, tactics):
    # your code

    "who has the higher speed"
    if robot_1["speed"]>=robot_2["speed"]:
        robotfast = robot_1
        robotslow = robot_2
    else:
        robotfast = robot_2
        robotslow = robot_1    
        
    
    def roundfight(robotfast, robotslow, tactics):
        
        if len(robotfast["tactics"])>0:
            tactic = robotfast["tactics"][0]
            damage = tactics[tactic]
            robotfast["tactics"].pop(0)
            robotslow["health"] -= damage
            "attack 1" "robot fast"
            "how much damage by attack"
            "robot slow loses health"
        
        "is robotslow alive"
        if robotslow["health"]<=0:
            return robotfast["name"]  + " has won the fight."  
        
        if len(robotslow["tactics"])>0:
            tactic = robotslow["tactics"][0]
            damage = tactics[tactic]
            robotslow["tactics"].pop(0)
            robotfast["health"] -= damage        

        if robotfast["health"]<=0:
            return robotslow["name"] + " has won the fight."        
        
        "special case: out of tactics"
        if len(robotfast["tactics"])==0 & len(robotslow["tactics"])==0:
            if robotfast["health"] == robotslow["health"]:
                return "The fight was a draw."
            elif robotfast["health"] > robotslow["health"]:
                return robotfast["name"] + " has won the fight."
            else:
                return robotslow["name"] + " has won the fight."
                
        
        
        
        else: 
            return roundfight(robotfast, robotslow, tactics)
        
    return roundfight(robotfast, robotslow, tactics)


def fight(robot_1, robot_2, tactics):
    if robot_1['speed'] >= robot_2['speed']:
        while(robot_2['tactics'] or robot_1['tactics']):
            try:
                robot_2['health'] -= tactics[robot_1['tactics'].pop(0)]
            except:
                pass
            if robot_2['health'] <= 0:
                return "Rocky has won the fight."
            try:
                robot_1['health'] -= tactics[robot_2['tactics'].pop(0)]
            except:
                pass
            if robot_1['health'] <= 0:
                return "Missile Bob has won the fight."
    else:
        while(robot_2['tactics'] or robot_1['tactics']):
            try:
                robot_1['health'] -= tactics[robot_2['tactics'].pop(0)]
            except:
                pass
            if robot_1['health'] <= 0:
                return "Missile Bob has won the fight."
            try:
                robot_2['health'] -= tactics[robot_1['tactics'].pop(0)]
            except:
                pass
            if robot_2['health'] <= 0:
                return "Rocky has won the fight."
            
    if robot_1['health'] > robot_2['health']:
        return "Rocky has won the fight."
    elif robot_2['health'] > robot_1['health']:
        return "Missile Bob has won the fight."
    return "The fight was a draw."

def fight(robot_1, robot_2, tactics):
    # your code
    robot1_health = robot_1['health']
    robot2_health = robot_2['health']
    if len(robot_1['tactics']) < len(robot_2['tactics']):
        return '{} has won the fight.'.format(robot_2['name'])
    elif len(robot_1['tactics']) > len(robot_2['tactics']):
        return '{} has won the fight.'.format(robot_1['name'])
    else:
        if robot_1['speed'] < robot_2['speed']:
            for tactic in zip(robot_1['tactics'], robot_2['tactics']):
                robot1_health -= tactics[tactic[1]]
                if robot1_health <= 0:
                    return '{} has won the fight.'.format(robot_2['name'])
                robot2_health -= tactics[tactic[0]]
                if robot2_health <= 0:
                    return '{} has won the fight.'.format(robot_1['name'])
        else:
            for tactic in zip(robot_1['tactics'], robot_2['tactics']):
                robot2_health -= tactics[tactic[0]]
                if robot2_health <= 0:
                    return '{} has won the fight.'.format(robot_1['name'])
                robot1_health -= tactics[tactic[1]]
                if robot1_health <= 0:
                    return '{} has won the fight.'.format(robot_2['name'])
    if robot1_health < robot2_health:
        return '{} has won the fight.'.format(robot_2['name'])
    elif robot1_health > robot2_health:
        return '{} has won the fight.'.format(robot_1['name'])
    else:
        return "The fight was a draw."

def fight(robot_1, robot_2, tactics):
    if robot_1["speed"]>= robot_2["speed"]:
        active = robot_1
        passive = robot_2
    else:
        active,passive = robot_2, robot_1
    while robot_1["tactics"] or robot_2["tactics"]:
        if active["tactics"]:
            move = active["tactics"].pop()
            passive["health"] -= tactics[move]
            if passive["health"] <= 0:
                return active["name"] + " has won the fight."
        active, passive = passive,active
    if robot_1["health"] > robot_2["health"]:
        return robot_1["name"] + " has won the fight."
    elif robot_2["health"] > robot_1["health"]:
        return robot_2["name"] + " has won the fight."
    else:
        return "The fight was a draw."