0

Hi i have been having trouble figuring out what is wrong with this code. I am attempting to make a Tic-Tac-Toe game where you can choose the size of the square but each time i try it the game puts an x down the column i chose. Some parts of the code have been cut out because I've checked if they are the problem already, so there may be some useless variables at the beginning of the code.

edit: The variables aren't actually useless in the full code but they are in the chunk that has the problem

x=int(input('How big would you like the square to be (eg if you put 4 the board will be 4X4)? '))-1
fboard=[]
for counter in range(x+1):
    fboard.append('-')
board=[]
for counter in range(x+1):
    board.append(fboard)
print('Welcome to Gay Als SUPER noughts and crosses adventure!')
gameOver=False
Player=1
gameOverValidation=0
while gameOver==False:
    Row=False
    Column=False
    valid=False
    if Player%2!=0:
        currentPlayer='x'
    else:
        currentPlayer='o'
    print('Player',currentPlayer,'Is up next')
    for row in range(x+1):
        for column in range(x+1):
            print(board[row][column],end=' ')
        print()
    while valid==False:
        Row=False
        while Row==False:
            newRow=int(input('Which row would YOU like to put your piece in ,darling? '))
            if newRow>(x+1) or newRow<1:
                print ("Invalid value. mmmmaybe come to GAY AL's cove of WONDERS!")
            else:
                Row=True
        Column=False
        while Column==False:
            newColumn=int(input('Mmmkay, interesting. The column por favor? '))
            if newColumn>(x+1) or newColumn<1:
                print('GOD DAMN STUPID **** **** ***** **** **** THAT IS NOT VALID!')
            else:
                Column=True
        if board[newRow-1][newColumn-1]!='-':
            print('Umm, that space is taken already, babe.')
        else:
            valid=True
    board[newRow-1][newColumn-1]=currentPlayer

(then there are loops to figure out if the game has been won yet)

Player+=1
  • 1
    Could you reiterate what the problem is? What is the exact behavior that you are getting that you don't expect? – Jenner Felton Nov 27 '16 at 19:00
  • 1
    `board.append(fboard)` makes each row an alias of `fboard`. You have 1 row echoed various times, not independent rows. In various guises, this is a heavily-duplicated question and I am voting to close it as such. – John Coleman Nov 27 '16 at 19:05
  • Also this `while something == False` should be replaced with `while not something` or `while something is False` -> [here](http://docs.python-guide.org/en/latest/writing/style/?highlight=is%20False#check-if-variable-equals-a-constant) and @JohnColeman have just explained to you where the problem lies. – mutantkeyboard Nov 27 '16 at 19:07

0 Answers0