Last active
August 29, 2015 14:02
-
-
Save jkhowland/715845b34014aa7f54ef to your computer and use it in GitHub Desktop.
Code to check if tic tac toe game has been won
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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