Last active
August 29, 2015 14:10
-
-
Save veiset/7924427256b869095bca 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
| 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