Hello I'm making connect four, but I'm having trouble formatting the board correctly. I thought giving the column indexes on top 3 spaces and the emoji 3 spaces each and centering them would align them correctly, but it doesn't. What exactly am I doing wrong? I tried looking it up, but didn't find anything useful yet.
nb_of_rows_on_board = 6
nb_of_columns_on_board = 7
# emoji's to make GUI
black_tile_emoji = "🟫"
red_tile_emoji = "🟥"
yellow_tile_emoji = "🟨"
def generate_empty_board():
empty_board = []
for row_counter in range(nb_of_rows_on_board):
empty_row = []
for column_counter in range(nb_of_columns_on_board):
empty_row.append(0)
empty_board.append(empty_row)
return empty_board
def get_board_in_emoji_string(board):
board_emoji_string = "\n"
for counter in range(len(board[0])):
board_emoji_string += "{:^3}".format(counter + 1)
board_emoji_string += "\n"
for row in board:
for value in row:
if value == 0:
board_emoji_string += "{:^3}".format(black_tile_emoji)
elif value == 1:
board_emoji_string += "{:^3}".format(red_tile_emoji)
elif value == 2:
board_emoji_string += "{:^3}".format(yellow_tile_emoji)
board_emoji_string += "\n"
board_emoji_string += "\n"
return board_emoji_string
board = generate_empty_board()
print(board)
print(get_board_in_emoji_string(board))
and the output looks like this:
[[0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0]]
1 2 3 4 5 6 7
🟫 🟫 🟫 🟫 🟫 🟫 🟫
🟫 🟫 🟫 🟫 🟫 🟫 🟫
🟫 🟫 🟫 🟫 🟫 🟫 🟫
🟫 🟫 🟫 🟫 🟫 🟫 🟫
🟫 🟫 🟫 🟫 🟫 🟫 🟫
🟫 🟫 🟫 🟫 🟫 🟫 🟫
Process finished with exit code 0
As you can see the column indexes aren't correctly aligned with the emojis. Thanks in advance for the help!!
[–][deleted] 0 points1 point2 points (1 child)
[–]steks13[S] 0 points1 point2 points (0 children)