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!



LinkBack URL
About LinkBacks


