# tic tac toe check winner

Show 80 post(s) from this thread on one page
Page 2 of 2 First 12
• 12-18-2009
Elysia
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.

Quote:

Originally Posted by QuestionKing
lol @ wiki

Did you check the wiki? I can see no such thing ;)
• 12-19-2009
dhardin
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!
• 12-20-2009
dhardin
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:
Code:

``` //adjust move to the corresponding row and columns                 rowSelect = (move - 1) / 3;                 columnSelect = (move + 2) % 3;```
I only have one question regarding the method that pelicanpie used.

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; }```
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.

Thanks again!
Show 80 post(s) from this thread on one page
Page 2 of 2 First 12