Skip to content

Instantly share code, notes, and snippets.

@Fluxx
Created March 9, 2012 22:39
Show Gist options
  • Select an option

  • Save Fluxx/2009086 to your computer and use it in GitHub Desktop.

Select an option

Save Fluxx/2009086 to your computer and use it in GitHub Desktop.
import json
from pprint import pprint as pp
io = open('board.json')
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