Skip to content

Instantly share code, notes, and snippets.

@cashlo
Last active June 3, 2020 15:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cashlo/20a47f46c6deee5d222b1315a407d555 to your computer and use it in GitHub Desktop.
Save cashlo/20a47f46c6deee5d222b1315a407d555 to your computer and use it in GitHub Desktop.
Printing a gomoku board
def print(self):
header = ' '
for x in range(self.size):
if self.last_move is not None and x == self.last_move%self.size:
header += '▼ '
else:
header += f'{x+1} '
print(header)
for y in range(self.size):
row_name = y+1 if self.last_move is None or self.last_move//self.size != y else ' ►'
row = f'{row_name:2} '
for x in range(self.size):
cell = self.board[self.size*y+x]
if cell == Gomoku.BLACK:
row += '○'
elif cell == Gomoku.WHITE:
row += '●'
elif x == 0 and y == 0:
row += '┌ '
elif x == 0 and y == self.size-1:
row += '└ '
elif x == self.size-1 and y == 0:
row += '┐'
elif x == self.size-1 and y == self.size-1:
row += '┘'
elif x == 0:
row += '├ '
elif y == 0:
row += '┬ '
elif x == self.size-1:
row += '┤'
elif y == self.size-1:
row += '┴ '
else:
row += '┼ '
print(row)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment