You are making your very own boardgame. The game is played by two opposing players, featuring a 6 x 6 tile system, with the players taking turns to move their pieces (similar to chess). The design is finished, now it's time to actually write and implement the features. Being the good programmer you are, you carefully plan the procedure and break the program down into smaller managable sections. You decide to start coding the logic for resolving "fights" when two pieces engage in combat on a tile. 

Your boardgame features four unique pieces: 

Swordsman, Cavalry, Archer and Pikeman

Each piece has unique movement and has advantages and weaknesses in combat against one of the other pieces. 

Task

You must write a function ```fightResolve``` that takes the attacking and defending piece as input parameters, and returns the winning piece. It may be the case that both the attacking and defending piece belong to the same player, after which you must return an error value to indicate an illegal move. 

In C++ and C, the pieces will be represented as ```chars```. Values will be case-sensitive to display ownership. Let the following char values represent each piece from their respective player.

Player 1:  ```p```= Pikeman, ```k```= Cavalry, ```a```= Archer, ```s```= Swordsman 

Player 2:  ```P```= Pikeman, ```K```= Cavalry, ```A```= Archer, ```S```= Swordsman 

The outcome of the fight between two pieces depends on which piece attacks, the type of the attacking piece and the type of the defending piece. Archers always win against swordsmens, swordsmen always win against pikemen, pikemen always win against cavalry and cavalry always win against archers. If a matchup occurs that was not previously mentioned (for example Archers vs Pikemen) the attacker will always win. This table represents the winner of each possible engagement between an attacker and a defender.


(Attacker→)
    (Defender↓)
Archer
Pikeman
Swordsman
Knight


Knight
Defender
Attacker
Attacker
Attacker


Swordsman
Attacker
Defender
Attacker
Attacker


Archer
Attacker
Attacker
Defender
Attacker


Pikeman
Attacker
Attacker
Attacker
Defender



If two pieces from the same player engage in combat, i.e P vs S or k vs a, the function must return -1 to signify and illegal move. Otherwise assume that no other illegal values will be passed.

Examples

Function prototype: fightResolve(defender, attacker)
1. fightResolve('a', 'P') outputs 'P'. No interaction defined between Pikemen and Archer. Pikemen is the winner here because it is the attacking piece.

2. fightResolve('k', 'A') outputs 'k'. Knights always defeat archers, even if Archer is the attacking piece here.

3. fightResolve('S', 'A') outputs -1. Friendly units don't fight. Return -1 to indicate error.

Difficulty: introductory

Starter code:

def fight_resolve(defender, attacker):
	

Solutions:
def fight_resolve(d, a):
    return -1 if d.islower() == a.islower() else d if d.lower() + a.lower() in "ka sp as pk" else a

def fight_resolve(d, a):
    return -1 if d.islower() == a.islower() else d if f"{d}{a}".lower() in "aspka" else a

def fight_resolve(defender, attacker):
    res = attacker
    if defender.islower() and attacker.islower() or defender.isupper() and attacker.isupper():
        return -1
    elif attacker.lower() == 'a':
        if defender.lower() == 'k':
            res = defender
    elif attacker.lower() == 'p':
        if defender.lower() == 's':
            res = defender
    elif attacker.lower() == 's':
        if defender.lower() == 'a':
            res = defender
    elif attacker.lower() == 'k':
        if defender.lower() == 'p':
            res = defender
    return res


def fight_resolve(defender, attacker): 
    if (attacker.isupper() and defender.isupper()) or (attacker.islower() and defender.islower()):
        return -1
    att = {"A":1, "P":2, "S":3, "K":4}
    dff = {"K":1, "S":2, "A":3, "P":4}
    
    if att[attacker.upper()] == dff[defender.upper()]:
        return defender
    else:
        return attacker
    #pass


p1 = ['p', 'k', 'a', 's']
p2 = ['P', 'K', 'A', 'S']
ar = ['a', 'A']
sm = ['s', 'S']
pm = ['p', 'P']
cy = ['k', 'K']

def fight_resolve(d, a): 
    if (d in p1 and a in p1) or (d in p2 and a in p2):
        return -1
    if a in ar:
        return d if d in cy else a
    elif a in pm:
        return d if d in sm else a
    elif a in sm:
        return d if d in ar else a
    elif a in cy:
        return d if d in pm else a


def fight_resolve(defender, attacker): 

    if defender.isupper() == attacker.isupper():
        return -1

    battle = dict(zip('ksapKSAP', 'APSKapsk'))
    return defender if battle[defender] == attacker else attacker

def fight_resolve(defender, attacker): 
    if defender.islower() == attacker.islower(): return -1
    return defender if f"{defender}{attacker}".lower() in "aspka" else attacker

fight_resolve=lambda d,a:d.islower()^a.islower()and(a,d)[(d+a).lower()in'aspka']or-1

def fight_resolve(d, a): 
    if d.islower() == a.islower(): return -1
    map = {"a":"s", "k":"a", "p":"k", "s":"p"}
    return d if map[d.lower()] == a.lower() else a

def fight_resolve(defender, attacker): 
    fight = (defender + attacker).lower()
    d_low = defender == defender.lower()
    a_low = attacker == attacker.lower()
    
    if (d_low and a_low) or (not d_low and not a_low):
        return -1
    
    if ("a" in defender.lower()) and ("s" in attacker.lower()):
        winner = defender
    elif "s" in defender.lower() and "p" in attacker.lower():
        winner = defender
    elif "p" in defender.lower() and "k" in attacker.lower():
        winner = defender
    elif "k" in defender.lower() and "a" in attacker.lower():
        winner = defender
    else:
        winner = attacker
    
    return winner