Linted
[menace.git] / nac-trinket / nac.py
index 64cf504f147c6211df7653ce9e524f96fab8a4c3..3683aad1073ab4a7387f234ee1895c27db2583aa 100644 (file)
@@ -1,7 +1,5 @@
 import itertools
-import functools
-import collections
-import random
+
 
 def xo_count(board):
     xs = 0
@@ -13,18 +11,20 @@ def xo_count(board):
             os += 1
     return xs, os
 
+
 def valid_board(board):
     xs, os = xo_count(board)
     return (xs - os) == 0 or (xs - os) == 1
 
+
 def empty_board():
     return tuple('.' * 9)
 
 
 def all_boards():
     return [b for b in itertools.product('.xo', repeat=9)
-           if valid_board(b)
-           ]
+            if valid_board(b)]
+
 
 def winner(board):
     winning_player = None
@@ -51,6 +51,7 @@ def show_board(b):
     s = ''.join(b)
     return s[0:3] + '\n' + s[3:6] + '\n' + s[6:9]
 
+
 def show_boards(bs):
     rows = [[], [], []]
     for b in bs:
@@ -71,6 +72,7 @@ inverse_rotation = {t: f for f, t in rotation.items()}
 # 6 7 8    8 7 6
 reflection = {0: 2, 1: 1, 2: 0, 3: 5, 4: 4, 5: 3, 6: 8, 7: 7, 8: 6}
 
+
 def rotate(board, n=1):
     b = board
     for _ in range(n):
@@ -84,29 +86,34 @@ def reflect(board, r=True):
     else:
         return board
 
+
 def transform(board, n, r):
     b = rotate(board, n)
     return reflect(b, r)
 
+
 def untransform(board, n, r):
     b = reflect(board, r)
     return rotate(b, abs(4-n))
 
+
 def all_transforms(board):
     return [(transform(board, rot, ref), rot, ref)
             for rot in range(4)
             for ref in [False, True]]
 
+
 def score(board):
     return ''.join(board)
 
+
 def canonical(board):
     return max(all_transforms(board), key=lambda brf: score(brf[0]))
 
+
 def non_winning_boards():
     return set([canonical(b)[0] for b in all_boards()
-           if not winner(b)
-           ])
+                if not winner(b)])
 
 
 def successors(board):
@@ -133,9 +140,9 @@ def vacants(board):
 def apply_move(board, position, piece):
     return tuple(board[:position] + (piece,) + board[position+1:])
 
+
 def token_for_player(is_player_1):
     if is_player_1:
         return 'x'
     else:
         return 'o'
-        
\ No newline at end of file