I'm attempting to make a game of 3D chess, in which there are piece, board, and coordinates classes. In the board class, there is an [8][8][8] array of pointers to pieces. In the piece's constructor, I have the relevant pointer in the board point to the piece, but it doesn't seem to work correctly. When I try to print the name, it gives me a strange character, which when cast to int is -52, instead of 'Q'. Here is the relevant code:
piece:iece(char id, bool team, coordinates c) {
this->name = id;
//otherdata = 0; //Stored: **** T M C M(m)
//otherdata |= (team&1)<<3;
//otherdata |= findMultiMove()&1;
//loadMoveTypes();
//location = c;
//whereMove = whereCapt = whereCast = 0;
//findMoves(true);
homeBoard->place(*this,c);
}
Board.cpp:
piece* board::lookup(coordinates c) const {
return lookup(c.getX(), c.getY(), c.getZ());
}
piece* board::lookup(int x, int y, int z) const {
if(0<=x && x<=7 && 0<=y && y<=7 && 0<=z && z<=7) return table[x][y][z];
return 0;
}
void board:lace(piece p, int x, int y, int z) {
table[x][y][z] = &p;
}
Does anybody know what went wrong? Also, the coordinates class is working perfectly, no matter what I throw at it, so I don't think it's that. And the header files work too.
Bookmarks