Misc other comments...
I agree with all the above, including the one about int main() -- even though the GCC compiler allows you to be lazy, for backward compatibility reasons, you should get into the habit of usig the ANSI compliant forms of main: either int main() or int main(int argc, char* argv[]), with a return!
1. Long lines of code should be folded (this helps make them more readable not only in your IDE but here on cplusplus.com)
1 2 3 4 5 6 7 8
|
/* Checking condition obliquelly */
for(int row=5; row>=0; row--){
for(int column=0; column<=3; column++){
if(multiArray[row][column] == markerX && multiArray[row-1][column+1] == markerX &&
multiArray[row-2][column+2] == markerX && multiArray[row-3][column+3] == markerX){
checkX = true;
break;
}
| |
or even
1 2 3 4 5 6 7 8 9 10
|
/* Checking condition obliquelly */
for(int row=5; row>=0; row--){
for(int column=0; column<=3; column++){
if(multiArray[row][column] == markerX &&
multiArray[row-1][column+1] == markerX &&
multiArray[row-2][column+2] == markerX &&
multiArray[row-3][column+3] == markerX){
checkX = true;
break;
}
| |
rather than
1 2 3 4 5 6 7
|
/* Checking condition obliquelly */
for(int row=5; row>=0; row--){
for(int column=0; column<=3; column++){
if(multiArray[row][column] == markerX && multiArray[row-1][column+1] == markerX && multiArray[row-2][column+2] == markerX && multiArray[row-3][column+3] == markerX){
checkX = true;
break;
}
| |
(A limit of 80 characters per line was common in the past, when screens were smaller and people mostly used console-based text editors. In the days of IDEs and large screens, you can use slightly longer rows, but still want to be able to see your code, the debugger output, and you app's window all at the same time -- and be able to see the whole line of code without scrolling.)
2. C++ coders usually use
if(checkX){
rather than
if(checkX == true){
as checkX is already a boolean, you don't need to compare it against true. The result of operator== is a bool value. e.g.
value = (checkZ == true)
--> true or false
also, it save a bit of typing (you did say you're lazy!)
3. Some of the variable and function names could be improved.
All variable names should say what they are, function names what they do.
e.g. checkX -> check what?
hasLineX might be better?
And "displayBoard" is a good function name, but "turn" is not. Turn what?
4. You should use pre-increment rather than post-increment
There are cases where the post-increment for performs worse, so it's a good habit to use ++i rather than i++
Same deal for decrement.
5. You could replace literals with meaningful contants
const int numRows = 6;
const int numCols = 7;
char board[numRows][numCols];
rather than
char board[6][7];
and then use them in you loops.
6. From a object oriented point of view, rather than a C++ syntax point of view... If you plan on a version 2 of you game, you should consider factoring out the board specific code into its own (Board) class, rather than using the char array directly (ie encapsulate the board).
Andy