Aug-16-2019, 10:27 AM
This is the start of a 4 in a row game / connect 4. I am experiencing the error:
line 10, in is_valid_location
if board[bottom_row][column] == 0:
IndexError: index 5 is out of bounds for axis 0 with size 5
I would really appreciate some help thanks.
line 10, in is_valid_location
if board[bottom_row][column] == 0:
IndexError: index 5 is out of bounds for axis 0 with size 5
I would really appreciate some help thanks.
import numpy as np turn = 0 game_over = False def board_create(column, row): board = np.zeros((row,column)) return board def is_valid_location(column_choice, board, bottom_row): if board[bottom_row][column] == 0: return False else: return True row = 5 column = int(input("How many columns: ")) board = board_create(column, row) while not game_over: if turn == 0: invalid = True bottom_row = row while invalid == True: column = str(column) column_choice = int(input("Player 1 make your selection (1-"+column+"):")) column = int(column) invalid = is_valid_location(column_choice, board, bottom_row) else: while invalid == True: column = str(column) column_choice = int(input("Player 2 make your selection (1-"+column+"):")) column = int(column) invalid = is_valid_location(column_choice, board, bottom_row) turn = turn + 1 turn = turn % 2