Reputation: 123
if i have
int win[][] ={{1,2,3},{4,5,6},{7,8,9},{1,4,7},{2,5,8},{3,6,9},{1,5,9},{3,5,7}};
Can I put condition in this way?
if(((win[0][0]) && (win[0][1]) && (win[0][2]))||
((win[1][0]) && (win[1][1]) && (win[1][2]))||
((win[2][0]) && (win[2][1]) && (win[2][2]))||
((win[3][0]) && (win[3][1]) && (win[3][2]))||
((win[4][0]) && (win[4][1]) && (win[4][2]))||
((win[5][0]) && (win[5][1]) && (win[5][2]))||
((win[6][0]) && (win[6][1]) && (win[6][2]))||
((win[7][0]) && (win[7][1]) && (win[7][2]))||
((win[8][0]) && (win[8][1]) && win[8][2])))
Upvotes: 0
Views: 363
Reputation: 134694
For a clearer version of this, why not try:
for(int i = 0; i < 8; i++) {
if(win[i][0] && win[i][1] && win[i][2]) {
doStuff();
break;
}
}
Upvotes: 1
Reputation: 40218
Your array is 8x3, means last element will be win[7][2]
. So calling win[8][0]
will throw an ArrayIndexOutOfBounds
exception. If you correct this error, your code will work. Hope this helps.
Upvotes: 2