Skip to content

Instantly share code, notes, and snippets.

@veiset
Last active August 29, 2015 14:10
Show Gist options
  • Select an option

  • Save veiset/7924427256b869095bca to your computer and use it in GitHub Desktop.

Select an option

Save veiset/7924427256b869095bca to your computer and use it in GitHub Desktop.
BLACK = True
WHITE = False
SIZE = 10
pos = [0, 0]
board = [[WHITE for _ in range(SIZE)] for _ in range(SIZE)]
def moves(x,y):
return [[x-2, y-1],[x-2, y+1],[x-1, y-2],[x-1, y+2],
[x+1, y-2],[x+1, y+2],[x+2, y-1],[x+2, y+1]]
def validMove(x, y): return SIZE > x >= 0 and SIZE > y >= 0
def color(board, x, y): return board[x][y]
def toggleColor(board, x, y): board[x][y] = not board[x][y]
def smallestOfSameColor(board, pos):
for move in moves(*pos):
valid = validMove(*move)
if valid and color(board, *move) == color(board, *pos):
return move
def highestValidMove(pos):
for move in moves(*pos)[::-1]:
if validMove(*move):
return move
for _ in range(200):
move = smallestOfSameColor(board, pos) or highestValidMove(pos)
toggleColor(board, *pos)
pos = move
print sum(map(sum, board))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment