As the title suggests im having trouble with writing from an array.
It seems as if even the i give the board[x][y] the correct values it's still reading from
the wrong point, i've looked through my code and cant find anything that's wrong, maybe you can help?
This is a simplified version of the code, with only the areas that are a problem.
Code:#include <iostream> #define WHITE_KING 6 // define all chess pieces for ease of use #define WHITE_QUEEN 5 #define WHITE_TOWER 4 #define WHITE_RUNNER 3 #define WHITE_HORSE 2 #define WHITE_PEASANT 1 #define EMPTY 0 #define BLACK_PEASANT -1 #define BLACK_HORSE -2 #define BLACK_RUNNER -3 #define BLACK_TOWER -4 #define BLACK_QUEEN -5 #define BLACK_KING -6 using namespace std; void initboard(void); void drawboard(void); int board[7][7];//global board variable int main() { initboard(); drawboard(); system("PAUSE");//hold } void initboard(void)//initiate the board { int x,y; for(y=0;y<=7;y++)//make sure all values are at zero { for(x=0;x<=7;x++)//loop through columns values, then go to the next row and redo { board[x][y]=EMPTY; } } for(x=0;x<=7;x++)board[x][1]=WHITE_PEASANT;//white should be at the top rows for(x=0;x<=7;x++)board[x][6]=BLACK_PEASANT;//black should be at the bottom rows board[0][7]=BLACK_TOWER;//boring initialization stuff board[1][7]=BLACK_HORSE; board[2][7]=BLACK_RUNNER; board[3][7]=BLACK_QUEEN; board[4][7]=BLACK_KING; board[5][7]=BLACK_RUNNER; board[6][7]=BLACK_HORSE; board[7][7]=BLACK_TOWER; board[0][0]=WHITE_TOWER; board[1][0]=WHITE_HORSE; board[2][0]=WHITE_RUNNER; board[3][0]=WHITE_QUEEN; board[4][0]=WHITE_KING; board[5][0]=WHITE_RUNNER; board[6][0]=WHITE_HORSE; board[7][0]=WHITE_TOWER; } void drawboard(void) { int x,y; cout << " ";//proper alignment for(x=0;x<=7;x++)cout << " " << x << " "; // the numbers above cout << endl;// new row for layout for(y=0;y<=7;y++) { cout << y;//numbers at the side of the grid for(x=0;x<=7;x++)//loop through columns values, then go to the next row and redo { if(board[x][y]>=0)cout << " | " << board[x][y] << " | "; else cout << " |" << board[x][y] << " | ";//one less space for negative value alignment } cout << endl; } }
If anyone has encountered this problem (or simply knows that i am doing something wrong) please do tell! I've been trying to fix this for a long while!
Thanks in advance.



LinkBack URL
About LinkBacks



