Skip to content

Instantly share code, notes, and snippets.

@jkhowland
Last active August 29, 2015 14:02
Show Gist options
  • Save jkhowland/715845b34014aa7f54ef to your computer and use it in GitHub Desktop.
Save jkhowland/715845b34014aa7f54ef to your computer and use it in GitHub Desktop.
Code to check if tic tac toe game has been won
// See tic tac toe by Lenli https://github.com/lenli/tictactoe
-(BOOL)isGameOver {
NSArray *winCombinations = [[NSArray alloc] initWithObjects: @[@1,@2,@3], @[@4,@5,@6], @[@7,@8,@9],
@[@1,@4,@7], @[@2,@5,@8], @[@3,@6,@9],
@[@1,@5,@9], @[@3,@5,@7], nil];
for (NSArray *winCombination in winCombinations) {
BOOL isWinner = TRUE;
for (NSNumber *winIndex in winCombination) {
NSInteger winIndexInteger = [winIndex integerValue]-1;
if ([self.boardPlays[winIndexInteger] isEqualToString:self.currentTurn]) {
isWinner = FALSE;
}
}
if (isWinner == TRUE) return TRUE;
}
return FALSE;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment