So i am developing the game connect 4 and i need to rid of negative indexing because it causes the game to act funny. Basically, the column a player accesses is based on a group of list combined into one single list to form an array. e.g
grid1 = ['A','B','C','1']grid2 = ['D','E','F','2']grid3 = ['G','H','I','3']grid4 = ['J','K','L','4']# Now if we combine all three lists, we getTotal_Grid = [['A','B','C','1']['D','E','F','2']['G','H','I','3']['J','K','L','4']]# We have a total of 4 columns and 4 rows in this grid# Here is the format of how we access values in list Total_Grid[row][col]
So to access letter 'G', we do Total_Grid[2][0]. because 'G' is in row 2, column 0. Drawing out the actual grid, we have:
| | | | |-------------| | | | |-------------| | | | |-------------| | | | |-------------# As you can see, the grid is 4x4
Now because in connect 4, you don't get to choose what row the counter goes in, (it usually drops to the bottom of the grid), we will designate a value for row.
row = 3# Lets ask the user for inputcol = input("What column would you like to drop your counter in? ")# let's say user inputs 3, the counter will drop to [3][3] in the gridcol = 3| | | | |-----------------| | | | |-----------------| | | | |-----------------| | | | X |-----------------
My problem now arises because for instance, if the user enters a negative number for the column value, it still works because it indexes backward but i want to disable this because it messes up the game when the AI tries to block the player from connecting 4 dots