diff options
author | lonkaars <l.leblansch@gmail.com> | 2021-04-11 18:03:11 +0200 |
---|---|---|
committer | lonkaars <l.leblansch@gmail.com> | 2021-04-11 18:03:11 +0200 |
commit | deb09e5c749e3353c927d7fe94bbd35f25ff85ee (patch) | |
tree | 702ba982530aa98a96ddece365a32be842dae3c2 /voerbak | |
parent | 28f104de9ae9abe4b42abafbf3865ede5687996c (diff) |
dprint yapf continuation align style edit
Diffstat (limited to 'voerbak')
-rw-r--r-- | voerbak/main.py | 46 | ||||
-rw-r--r-- | voerbak/test.py | 2 | ||||
-rw-r--r-- | voerbak/v2.py | 40 |
3 files changed, 44 insertions, 44 deletions
diff --git a/voerbak/main.py b/voerbak/main.py index d802603..2ca473e 100644 --- a/voerbak/main.py +++ b/voerbak/main.py @@ -12,62 +12,62 @@ class bord: self.width = w self.height = h self.board = [ - [EMPTY for x in range(self.width)] for u in range(self.height) + [EMPTY for x in range(self.width)] for u in range(self.height) ] def print(self): print( - "\n".join( - [ - " ".join(self.board[y]) - for y in range(len(self.board) - 1, -1, -1) - ] - ) + "\n".join( + [ + " ".join(self.board[y]) + for y in range(len(self.board) - 1, -1, -1) + ] + ) ) def outside_board(self, coords): return coords[0] < 0 or \ - coords[1] < 0 or \ - coords[0] > self.height - 1 or \ - coords[1] > self.width - 1 + coords[1] < 0 or \ + coords[0] > self.height - 1 or \ + coords[1] > self.width - 1 def recursive_solve(self, coords, check_for, direction, current_length): new_position = (coords[0] + direction[0], coords[1] + direction[1]) if self.outside_board(new_position) or self.board[new_position[0]][ - new_position[1]] != check_for: + new_position[1]] != check_for: return current_length else: return self.recursive_solve( - new_position, check_for, direction, current_length + 1 + new_position, check_for, direction, current_length + 1 ) def check_win(self, coords): directions = [ - (1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1), (0, -1), - (1, -1) + (1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1), (0, -1), + (1, -1) ] values = list() for direction in directions: values.append( - self.recursive_solve( - coords, self.board[coords[0]][coords[1]], direction, 0 - ) + self.recursive_solve( + coords, self.board[coords[0]][coords[1]], direction, 0 + ) ) joined_directions = [ - values[0] + values[4], values[1] + values[5], - values[2] + values[6], values[3] + values[7] + values[0] + values[4], values[1] + values[5], + values[2] + values[6], values[3] + values[7] ] won = any(i >= 3 for i in joined_directions) if won: for i, value in enumerate(joined_directions): if value >= 3: start_pos = ( - coords[0] + directions[i][0] * values[i], - coords[1] + directions[i][1] * values[i], + coords[0] + directions[i][0] * values[i], + coords[1] + directions[i][1] * values[i], ) end_pos = ( - coords[0] + directions[i + 4][0] * values[i + 4], - coords[1] + directions[i + 4][1] * values[i + 4], + coords[0] + directions[i + 4][0] * values[i + 4], + coords[1] + directions[i + 4][1] * values[i + 4], ) print(start_pos, end_pos) diff --git a/voerbak/test.py b/voerbak/test.py index 6481817..430c24b 100644 --- a/voerbak/test.py +++ b/voerbak/test.py @@ -5,7 +5,7 @@ h = 6 column = 3 process = subprocess.Popen( - ["./voerbak"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=None + ["./voerbak"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=None ) process.stdin.write(bytearray(f"{w} {h}\n", "utf-8")) diff --git a/voerbak/v2.py b/voerbak/v2.py index 26030f5..67480e0 100644 --- a/voerbak/v2.py +++ b/voerbak/v2.py @@ -30,28 +30,28 @@ class bord: if self.board[new_position] != check_for: return current_length return self.recursive_solve( - new_position, check_for, direction, current_length + 1 + new_position, check_for, direction, current_length + 1 ) def check_win(self, pos): directions = [ - self.width, # north - self.width + 1, # northeast - 1, # east - -self.width + 1, # southeast - -self.width, # south - -self.width - 1, # southwest - -1, # west - self.width - 1, # northwest + self.width, # north + self.width + 1, # northeast + 1, # east + -self.width + 1, # southeast + -self.width, # south + -self.width - 1, # southwest + -1, # west + self.width - 1, # northwest ] values = list() for direction in directions: values.append( - self.recursive_solve(pos, self.board[pos], direction, 0) + self.recursive_solve(pos, self.board[pos], direction, 0) ) joined_directions = [ - values[0] + values[4], values[1] + values[5], - values[2] + values[6], values[3] + values[7] + values[0] + values[4], values[1] + values[5], + values[2] + values[6], values[3] + values[7] ] won = any(i >= 3 for i in joined_directions) if won: @@ -67,14 +67,14 @@ class bord: def debug(self, pos): self.board[pos] = "x" directions = [ - self.width, # 0: north - self.width + 1, # 1: northeast - 1, # 2: east - -self.width + 1, # 3: southeast - -self.width, # 4: south - -self.width - 1, # 5: southwest - -1, # 6: west - self.width - 1, # 7: northwest + self.width, # 0: north + self.width + 1, # 1: northeast + 1, # 2: east + -self.width + 1, # 3: southeast + -self.width, # 4: south + -self.width - 1, # 5: southwest + -1, # 6: west + self.width - 1, # 7: northwest ] for index, direction in enumerate(directions): |