Hey! I'm new on this forum, so if i make a mistake please don't be angry with me.
I'm making a simple game, just two ships trying to "touch" a tin wich run over the screen.

OK, here's the thing: I have problems about how the tin avoid the ships. I recently implement a algorithm that uses Pythagoras to get the distances between the tin and each ship.

I talk spanish so the variables are "nave" (for ships) and "lata" (for tin).
This is the code which calculate the next position of the tin (obviously minimized):
Code:
#include <time.h>
#include <math.h>

#define VEL_LATA 5              //[Pix/Frame]
#define TOLERANCIA 40           //[Pix]
#define TOLERANCERCA 36  //[Pix]

#define ALTO 480                //[Pix]


#define ANCHO 640               //[Pix]
#define SIZE_LATAX 17
#define SIZE_LATAY 25

struct POSITION{
    POSITION(){/* sin acción */}
    POSITION(int nx, int ny){x=nx; y=ny;}
    int x;
    int y;
};

class CSprite{
    public:
        POSITION getPos() {return Position;}
        void setPos(POSITION pPos) {Position=pPos;}
    private:
        POSITION Position;
};

CSprite lata;

void Move(CSprite &nave1, CSprite &nave2);
void ClosertoDestination(POSITION &Source, POSITION &Destination);
bool AreCloser(POSITION &v1, POSITION &v2);
bool AreVeryCloser(POSITION &v1, POSITION &v2);

void Move(CSprite &nave1, CSprite &nave2) {
    static POSITION Destination=lata.getPos();
    POSITION Source=lata.getPos();
    POSITION p1=nave1.getPos(), p2=nave2.getPos();


    if(    (Source.y==Destination.y &&Source.x==Destination.x)  ||
            (AreCloser(p1, Source) ||
             AreCloser(p2, Source))

      ) {
        do {
            Source=lata.getPos();
            Destination.x=rand() % ANCHO-SIZE_LATAX+1;
            Destination.y=rand() % ALTO-SIZE_LATAY+1;
            Destination.x-=Destination.x % VEL_LATA;
            Destination.y-=Destination.y % VEL_LATA;
            ClosertoDestination(Source, Destination);
        } while(AreVeryCloser(p1, Source) ||
                AreVeryCloser(p2, Source));
    }
    else{
        ClosertoDestination(Source, Destination);
    }

    lata.setPos(Source);
}


void ClosertoDestination(POSITION &Source, POSITION &Destination) {
    if (Source.x<Destination.x)
        Source.x+=VEL_LATA;
    else if (Source.x>Destination.x)
        Source.x-=VEL_LATA;

    if (Source.y<Destination.y)
        Source.y+=VEL_LATA;
    else if (Source.y>Destination.y)
        Source.y-=VEL_LATA;
}

bool AreCloser(POSITION &v1, POSITION &v2) {
    return (sqrt(pow((v2.x-v1.x),2) + pow((v2.y-v1.y),2) )<TOLERANCIA);
}

bool AreVeryCloser(POSITION &v1, POSITION &v2) {
    return (sqrt(pow((v2.x-v1.x),2) + pow((v2.y-v1.y),2) )<TOLERANCIACERCA);
}
Sometimes when the tin approaches a ship (or vice versa) the game stay in the central while and i can´t solve that.
Anyway, if anyone has in mind a better algorithm than mine can say it, because i don't know how "powerful" is this.