Skip to content

Commit b8a471f

Browse files
committed
connect: Follow flake8
1 parent b2bc11e commit b8a471f

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

exercises/connect/example.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11

22
class ConnectGame:
33

4-
directions = [(0,1), (0,-1), (1,0), (-1,0), (1,-1), (-1,1)]
4+
directions = [(0, 1), (0, -1), (1, 0), (-1, 0), (1, -1), (-1, 1)]
55
white = "O"
66
black = "X"
77
none = ""
88

99
def __init__(self, lines):
1010
self.board = self.make_board(lines)
11-
assert(len(self.board) > 0)
11+
assert len(self.board) > 0
1212

1313
self.width = len(self.board[0])
1414
self.height = len(self.board)
15-
assert(self.width > 0 and self.height > 0)
15+
assert self.width > 0 and self.height > 0
1616

1717
for l in self.board:
18-
assert(len(l) == self.width)
18+
assert len(l) == self.width
1919

2020
def valid(self, x, y):
2121
return x >= 0 and x < self.width and y >= 0 and y < self.height
@@ -40,14 +40,18 @@ def walk_board(self, player, x, y, visited=[]):
4040
return True
4141

4242
for d in self.directions:
43-
if self.walk_board(player, x + d[0], y + d[1], visited + [(x,y)]):
43+
if self.walk_board(player, x + d[0], y + d[1], visited + [(x, y)]):
4444
return True
4545

4646
def check_player_is_winner(self, player):
4747
if player == self.black:
48-
return any([self.walk_board(player, 0, y) for y in range(self.height)])
48+
for y in range(self.height):
49+
if self.walk_board(player, 0, y):
50+
return True
4951
if player == self.white:
50-
return any([self.walk_board(player, x, 0) for x in range(self.width)])
52+
for x in range(self.width):
53+
if self.walk_board(player, x, 0):
54+
return True
5155

5256
def get_winner(self):
5357
if self.check_player_is_winner(self.black):
@@ -56,6 +60,7 @@ def get_winner(self):
5660
return self.white
5761
return self.none
5862

63+
5964
def play(board):
6065
game = ConnectGame(board)
6166
return game.get_winner()

0 commit comments

Comments
 (0)