Python Forum
Thread Rating:
  • 2 Vote(s) - 2.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
GameBoard coding
#1
I'm have to create connect 4 as an assignment. We have been given code to tic tac toe to base it on. I have adjusted the board code but keep getting this error message


Error:
Traceback (most recent call last):   File "C:\Users\Brett Bullman\Desktop\Programming\Lab 6\Lab6_Python\tic_tack_toe_fixed\main.py", line 38, in <module>     main()   File "C:\Users\Brett Bullman\Desktop\Programming\Lab 6\Lab6_Python\tic_tack_toe_fixed\main.py", line 17, in main     gboard.show_board_fixed() # show empty grid at the beginning of the game   File "C:\Users\Brett Bullman\Desktop\Programming\Lab 6\Lab6_Python\tic_tack_toe_fixed\gameboardfixed.py", line 63, in show_board_fixed     print(' ' + self.__board[5][0] + ' | ' + self.__board[5][1] + ' | ' + self.__board[5][2]) IndexError: list index out of range
This is the code:

>>> def show_board_fixed(self):
  print('   |   |   |   |   |   |   ')
  print(' ' + self.__board[0][0] + ' | ' + self.__board[0][1] + ' | ' + self.__board[0][2])
  print('   |   |   |   |   |   |   ')
  print('---------------------------')
  print('   |   |   |   |   |   |   ')
  print(' ' + self.__board[1][0] + ' | ' + self.__board[1][1] + ' | ' + self.__board[1][2])
  print('   |   |   |   |   |   |   ')
  print('---------------------------')
  print('   |   |   |   |   |   |   ')
  print(' ' + self.__board[2][0] + ' | ' + self.__board[2][1] + ' | ' + self.__board[2][2])
  print('   |   |   |   |   |   |   ')
  print('---------------------------')
  print('   |   |   |   |   |   |   ')
  print(' ' + self.__board[3][0] + ' | ' + self.__board[3][1] + ' | ' + self.__board[3][2])
  print('   |   |   |   |   |   |   ')
  print('---------------------------')
  print('   |   |   |   |   |   |   ')
  print(' ' + self.__board[4][0] + ' | ' + self.__board[4][1] + ' | ' + self.__board[4][2])
  print('   |   |   |   |   |   |   ')
  print('---------------------------')
  print('   |   |   |   |   |   |   ')
  print(' ' + self.__board[5][0] + ' | ' + self.__board[5][1] + ' | ' + self.__board[5][2])
  print('   |   |   |   |   |   |   ')
also would i have to adjust the self.board to suit all spaces? Thanks
Reply


Messages In This Thread
GameBoard coding - by Bullman - Dec-20-2016, 01:22 PM
RE: GameBoard coding - by ichabod801 - Dec-20-2016, 09:25 PM
RE: GameBoard coding - by Larz60+ - Dec-21-2016, 01:19 AM
RE: GameBoard coding - by nilamo - Dec-21-2016, 10:46 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020