Created
March 10, 2012 00:20
-
-
Save Fluxx/2009434 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| import json | |
| import sys | |
| from pprint import pprint as pp | |
| # io = open('board.json') | |
| io = sys.stdin | |
| board = json.loads(io.read()) | |
| def connceted_four(x, y, char, seen=1): | |
| if seen is 4: | |
| return True | |
| for x_dir in (-1, 0, 1): | |
| for y_dir in (-1, 0, 1): | |
| new_x = x + x_dir | |
| new_y = y + y_dir | |
| if seen >= 4: | |
| return True | |
| elif new_x < 0 or new_y < 0: | |
| return False | |
| elif board[new_x][new_y] == char: | |
| seen += 1 | |
| return connceted_four(new_x, new_y, char, seen) | |
| else: | |
| return False | |
| def run(): | |
| for row in range(6): | |
| for col in range(7): | |
| for char in ('X', 'O'): | |
| if connceted_four(row, col, char): | |
| return 'Winner: %s' % char | |
| return 'No winner.' | |
| print run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment