redribben

Untitled

Nov 2nd, 2015
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. - (int)checkForWin {//Now, think about how much more compact this could be if X, O and the other unstated were numbers!  For example: if untaken is 0, X is 4, O is 1: if it adds up to 3, it's O: if 12, it's X, otherwise, it doesn't matter.
  2.     NSUInteger winArray[24]={0,1,2, 3,4,5, 6,7,8, 0,3,6, 1,4,7, 2,5,8, 0,4,8, 2,4,6};
  3.     for(NSUInteger i=0;i<24; i+=3){
  4.         NSString* testObject=[xoSpots objectAtIndex:winArray[i]];
  5.         if([testObject isEqualToString:xoSpots[winArray[i+1]]]&&[testObject isEqualToString:xoSpots[winArray[i+2]]]) {
  6.             if([testObject isEqualToString:@"x"])
  7.                 return 2;
  8.             else if([testObject isEqualToString:@"o"])
  9.                 return 1;
  10.         }
  11.     }
  12.     return 0;
  13. }
Advertisement
Add Comment
Please, Sign In to add comment