What function outputs the biggest number for two given numbers taking care of both the sum and the difference of both?

30 Views Asked by At

Let's say I have a tuple (a,b),

I want a fuction that combines:

f(a,b) grows with a+b
f(a,b) decreases with (a/b)
and
f(a,b) decreases with (b/a)

In other words I need a function that rewards not only the independent values of a and b but also their equality.

The reason for this is that I'm developing an adversarial evolutive algorithm of entities playing chess and I'm looking to minimize the explotation of any whites/blacks initial advantadge, or in other words I need to reward those entities that win most matches independently of which side they play.

At the time I came with this: By defining an absolute multiplicative value out of the sleave:

if 1 < x,
  @x@=x
and
if x < 1,
  @x@=1/x
and then:
if 0 < a + b,
    f(a,b)=(a+b)/|@a/b@|
and
if a+b < 0,
    f(a,b)=(a+b)+((a+b)/|@a/b@|)

My python fuction looks like this:

def mash(score):
    white=score[0]
    black=score[1]
    if (white==0) or (black==0):
      ratio=.1

    else:
        ratio=abs(white/black)
        if 1 < ratio:
           ratio=1/ratio

    if (white==0) and (black==0):
      ratio=0
    suma=black+white  
    if suma < 0:
        return (black+white)*(1+ratio)
    else:
        return (black+white)*ratio

mash([10,5])