#!/usr/bin/env python

good = ['Yamcha', 'Teshin', 'Chaos', 'Picolo', 'Krillin', 'Goku']
evil = ['Saijaman1', 'Saijaman2', 'Saijaman3', 'Nappa', 'Vegeta']

kiGood = [90, 140, 50, 200, 100, 1000]
kiEvil = [300, 300, 300, 500, 1200]

#A copy of the lists, to compare which survived the battle
originalGood = good[:] #copy list is tricky, you need the
                       #[]. otherwise only the 'name' is copied but
                       #not the content
originalEvil = evil[:]

while len(good)>0 and len(evil)>0:

  print "\nThe list of good figthers is:", good
  success = False
  while success is False:
    nameGood = raw_input("Name of the good fighter: ")
    if nameGood in good:
      success = True
  indGood =  good.index(nameGood)

  print "\nThe list of evil figthers is:", evil
  success = False
  while success is False:
    nameEvil = raw_input("Name of the evil fighter: ")
    if nameEvil in evil:
      success = True 
  indEvil =  evil.index(nameEvil)

  print '\n', good[indGood], 'v/s', evil[indEvil], '...'
  ki1, ki2 = kiGood[indGood], kiEvil[indEvil]
  kiGood[indGood] = ki1 - ki2
  kiEvil[indEvil] = ki2 - ki1
  
  if kiGood[indGood] < 0 and kiEvil[indEvil] > 0:
    loser = good.pop(indGood)
    kiGood.pop(indGood)
    winner = evil[indEvil]
  elif kiGood[indGood] > 0 and kiEvil[indEvil] < 0:
    loser = evil.pop(indEvil)
    kiEvil.pop(indEvil)
    winner = good[indGood]
  else: #la unica posibilidad es que los 2 se mueran
    loser = evil.pop(indEvil)
    kiEvil.pop(indEvil)
    # le devoldveremos el Ki al buerno
    kiGood[indGood] = kiGood[indGood] + ki2
    winner = good[indGood]
    print  winner + " used Senju beans (cheating!)"

  print winner, 'defeated', loser

if len(good)> 0:
  while len(originalGood) > 0:
    name = originalGood.pop(0)
    if name not in good:
      good.append(name + '(RIP)')
  print 'the winner where the good guys:', good

else:
  while len(originalEvil) > 0:
    name = originalEvil.pop(0)
    if name not in evil:
      evil.append(name + '(RIP)')
  print 'the winner where the evil team:', evil

