Python Forum
help needed for a friend! :)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
help needed for a friend! :)
#11
:::Welcome to O'Neillo Game:::
==============================
		1. New Game
		2. Restore a Game
		3. Quit

Select a number from the menu : 1
Please enter player 1's name?S
Please enter player 2's name?A

Hi S you are '   '
Hi A you are @@

Let's play!
Number of tokens for    : 2
Number of tokens for @@ : 2
 ---- ---- ---- ---- ---- ---- ---- ----
| 01 | 02 | 03 | 04 | 05 | 06 | 07 | 08 | 
 ---- ---- ---- ---- ---- ---- ---- ----
| 09 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 
 ---- ---- ---- ---- ---- ---- ---- ----
| 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 
 ---- ---- ---- ---- ---- ---- ---- ----
| 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 
 ---- ---- ---- ---- ---- ---- ---- ----
| 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 
 ---- ---- ---- ---- ---- ---- ---- ----
| 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 
 ---- ---- ---- ---- ---- ---- ---- ----
| 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 
 ---- ---- ---- ---- ---- ---- ---- ----
| 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 
 ---- ---- ---- ---- ---- ---- ---- ----
Select your choice between 1 and 64:
4
Player pattern :  @@
this
player opposite pattern :    
1 -1
2 -2
3 -3
4 -4
5 -5
6 -6
7 -7
8 -8
Traceback (most recent call last):
  File "/Users/samhessell/PycharmProjects/Assignment_2/venv/Youtube.py", line 359, in <module>
    mainmenu()
  File "/Users/samhessell/PycharmProjects/Assignment_2/venv/Youtube.py", line 25, in mainmenu
    if userInput in ['1', '2'] : funcNames[int(userInput) -1]()
  File "/Users/samhessell/PycharmProjects/Assignment_2/venv/Youtube.py", line 14, in newGame
    game_in_play()
  File "/Users/samhessell/PycharmProjects/Assignment_2/venv/Youtube.py", line 103, in game_in_play
    flip(board, row, col, player, playerOpposite)
  File "/Users/samhessell/PycharmProjects/Assignment_2/venv/Youtube.py", line 297, in flip
    if (board[row][col]==playerOpposite):
IndexError: list index out of range
Reply
#12
What does that tell you about 8 and -8 and your index?
Reply
#13
Hi, i sent your reply to him as you have gathered he has only started to learn this stuff 3 weeks ago, and is asking for help! so when i posted your reply to him all i got was ???? he still has not gotten any further...

i asked him what he does not understand about this.. his reply!

How to play a move on the board. e.g. enter 23 and for whoevers turn it is, if the move is valid, flip the number

(May-09-2021, 11:36 AM)jefsummers Wrote: What does that tell you about 8 and -8 and your index?
Reply
#14
Look at your current code for flip
def flip(board, row, col, player, playerOpposite):
   while(row<len(board)-2 or col!=0):
      row+=1
      col-=1
      print(row,col)
      if (board[row][col]==playerOpposite):
        board[row][col]=player
Your while loop will continue as long as col is not zero. Given that col starts negative and you continue to subtract one from it, it will always be non-zero and it is an infinite loop.
Reply


Forum Jump:

User Panel Messages

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