I fail to see what I am doing wrong! it just crashes, and when I try to debug it, it just runs it and then says "program returned 3" even if I set a breakpoint!
here is my class:
Code: Select all
class Robot{
unsigned char brain_code[BRAIN_SIZE];
unsigned char ext_memory[EXT_MEM_SIZE];
unsigned char mating_code[4]; //there is the initial one,the negated one, then the plus and minus 0x44 one
int posx,posy;
unsigned char hp;
unsigned char attack_power;
unsigned char rotation:2;
public:
bool turn;
unsigned int r[8]; //r0-r7 for registers..
unsigned int ip;
Robot(int init_x,int init_y,const unsigned char *brain); //initial robots and mutations
Robot(int init_x, int init_y,const Robot &parent1,const Robot &parent2);
~Robot();
//void Create(int init_x, int init_y, unsigned char *brain, unsigned char mate_code);
unsigned int ChangeHp(signed int amount); //this is relational!
unsigned int const GetHp(){return hp;}
//It is constructed to bring to life and destructed to kill?
int Move(signed int amount); //returns actual amount moved(in case something is in the way)
void Rotate(bool way); //way is one for CW and zero for CCW
char const GetDirection(){return rotation;} //returns RIGHT, LEFT, or UP or DOWN...
//void Kill(); //this kills the Robot. Because of the way robots are linked in a list, we can't destruct it..
void EndTurn(); //This decrements the hp for each turn
void Attack(Robot &victim);
unsigned char GetFrontPixel();
unsigned char GetBackPixel();
void Kill(void); //?
unsigned char GetCurrentByte(){return brain_code[ip];}
unsigned char GetByte(int pos){return brain_code[pos];}
};
Code: Select all
Robot::Robot(int init_x,int init_y,const unsigned char *brain){
cout <<"t";
attack_power=5;
memcpy(brain_code,brain,BRAIN_SIZE); //copy brain code
if(display.GetPoint(init_x,init_y)!=FREESPACE_COLOR){
/**Means that the requested coordinates are actually filled.**/
cout << "Error: Requested coordinates for robot not valid!" << endl;
exit(1);
}
rotation=UP;
hp=HP_INIT;
//have to setup matin gcode too!
}
Code: Select all
void DoRobot(){
InitLogiCode();
Robot cbot(5,2,test_brain); //works
Robot *tbot=new Robot(5,2,test_brain); //crashes
//crobot=new Robot(5,2,test_brain);
for(;;){
//DoBrain(*crobot);
}
}