I need to print a two-dimensional list for a connect four game with 7 columns and 6 rows. Here is my code but it only prints a 6x6 table. The global constants from the connectfour module are: BOARD_ROWS = 6 and BOARD_COLUMNS = 7
def print_board(game_state: list)-> None:
for i in range(connectfour.BOARD_ROWS):
for j in range(connectfour.BOARD_COLUMNS):
if j != connectfour.BOARD_COLUMNS -1:
if game_state[j][i] == connectfour.NONE:
print('.', end=' ')
elif game_state[j][i] == connectfour.RED:
print('R', end=' ')
elif game_state[j][i] == connectfour.YELLOW:
print('Y', end=' ')
else:
print('\n',end='')
This is the output I get:
. . . . . .
. . . . . .
Y . . . . .
R . . . . .
R . . . . .
R R R Y Y Y
As you can see there are only 6 columns. However I know the 7th one is there because in this particular output the "Y" player won after dropping a piece in the 7th column. I just don't understand why it doesn't print the 7th column. Thanks in advance for the help.
if j != connectfour.BOARD_COLUMNS -1:
means you are specifically excluding the last column. Remove that if
construction and undent the following if
s and you should be good.