Did I say it was improper? I did not.
I linked to an article, and if you be bothered to read it, it actually covers your point, too.
Did you check the wiki? I can see no such thing ;)
Printable View
okay, thanks a lot for all who replied! I will be taking a look at my code and try to add in your advice (stuff that I understand more of course). Will post my code when i'm done.
thanks again!
Alright, so far I have used pelicanpie's method of checking for a winner (using a separate function call). On top of that, I fixed my rowSelect and columnSelect variables so that when a user enters a move between 1-9, it uses that number to select a row and column in my 2D array. So no more if/else statements (YAY!).
check it out:
I only have one question regarding the method that pelicanpie used.Code://adjust move to the corresponding row and columns
rowSelect = (move - 1) / 3;
columnSelect = (move + 2) % 3;
I do not yet understand the t<< or t>> statements. Can someone please explain this? I might have read about it, but I'm not sure.Code:char winner(char arr[3][3], char ch)
{
unsigned t = 0;
for(int i=0; i<3; i++)
for(int j=0; j<3; j++)
(t<<=1) += (arr[i][j] == ch);
for(int i=0; i<3; i++)
for(int j=0; j<3; j++)
(t<<=1) += (arr[j][i] == ch);
for(int i=0; i<3; i++)
(t<<=1) += (arr[i][i] == ch);
for(int i=0; i<3; i++)
(t<<=1) += (arr[i][3-i-1] == ch);
t <<= 8;
for(int i=0; i<8; i++)
{
switch(t >> 29)
case 7:
return ch;
t <<= 3;
}
return 0;
}
Thanks again!