Original Post
Hi, I was not sure which forum to put this in, but anyway, here goes: I've got a program that moves around little tanks, with the objective of picking up pellets. Ideally, they are supposed to all start at random locations. When I'm using two, they start at random places, but when I add more, they overlap, and since the logic is the same, they move the same too. Any idea what the problem is? here's the source for the initialization, the classes and some of the logic. And there is an 'srand(time(NULL))' at the beginning of the winmain about the angles and all, don't ask, the way i did it, it inverted the y-axis, so i had to change a bunch of angle to make them correct... I don't see what could be wrong, some insight would really give me a hand... Ps. I know this is a lot of code to look at, but i'd really apprciate it PPs. You can control one of the tanks with the arrows
inline double RandDble() {return (rand()/(RAND_MAX));}
class TANK
{
protected:
NEURALNET ANN;
TARGET_MANAGER *TM;
TARGET* targeted;
float tdist, tangle;
unsigned int fitness;
public:
TANK(bool randstart=true);
float position[2];
float angle;
TARGET* target;
void RunLogic(void);
void LockOn(void);
void Draw(void);
void Acquire(TARGET* target);
unsigned int GetFitness();
float GetTangle();
float GetAngle();
};
TANK::TANK(bool randstart):ANN(5, 1, 1, 5), angle(0.0f)// in(pos,angle,tarangle,tardist),out(tleft,tright),1hid,5/hid
{
TM=TARGET_MANAGER::GetInstance();
if(randstart)
{
position[0] = (float)(RandDble()*50-25);
position[1] = (float)(RandDble()*50-25);
angle = (float)(RandDble()*360);
}
else
{position[0] = 0; position[1] = 0;}
}
void TANK::RunLogic(void)
{
LockOn();
//Finite State Machine
float temp;
temp = tangle + 180;
if (temp > 360)
temp -= 360;
if(temp - angle < 0)
angle -= 2;
else if(temp - angle > 0)
angle += 2;
if(angle > 370) angle = 10;
if(angle < -10) angle = 350;
position[0] += (float)(0.05f*cos((double)(angle*PI/180)));
if(position[0] > 50)
position[0] = -50;
else if(position[0] < -50)
position[0] = 50;
position[1] -= (float)(0.05f*sin((double)(angle*PI/180)));
if(position[1] > 35)
position[1] = -30;
else if(position[1] < -35)
position[1] = 30;
Acquire(targeted);
}