Last active
June 3, 2020 15:32
-
-
Save cashlo/20a47f46c6deee5d222b1315a407d555 to your computer and use it in GitHub Desktop.
Printing a gomoku board
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
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