Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- - (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.
- 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};
- for(NSUInteger i=0;i<24; i+=3){
- NSString* testObject=[xoSpots objectAtIndex:winArray[i]];
- if([testObject isEqualToString:xoSpots[winArray[i+1]]]&&[testObject isEqualToString:xoSpots[winArray[i+2]]]) {
- if([testObject isEqualToString:@"x"])
- return 2;
- else if([testObject isEqualToString:@"o"])
- return 1;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment