1

I made a tic/tac/toe game and I keep getting an indentation error about how there is too many mixes of tabs and spaces but I tried re-indenting line by line and it did not work. I even put it in "Sublime Text" that automatically re-indents lines or turns the spaces into tabs. It still did not work. Does anyone have any suggestions, maybe there is some obvious error I am missing that is messing up the whole thing?

Angel Baby
  • 137
  • 1
  • 9
  • Have you tried the solution listed here: https://stackoverflow.com/questions/44803547/autoindent-on-sublime-text? – zedfoxus Apr 24 '19 at 22:33
  • Yes. It did not work. I am not sure what is the issue or maybe I did it wrong. Because since I have a lot of functions, it would just indent inside each function and that’s of course not what I want. I had to go to each function to reinvent everything and it still didn’t work – Angel Baby Apr 25 '19 at 02:15

1 Answers1

2

There were some indentation errors in your code, but I didn't notice any problems with mixed tabs and spaces. Instead, the indentation depth was inconsistent and, in some places, incorrect. Below is a cleanup of your code that you should be able to copy and paste into a file and run:

from turtle import *

# draw board
pieces = ["", "", "", "", "", "", "", "", ""]
turn = "X"

setup(600, 600)
bgcolor("black")

pencolor("white")
hideturtle()
speed('fastest')
pensize(10)
penup()

# Horizontal bars
goto(-300, 100)
pendown()
forward(600)
penup()
goto(-300, -100)
pendown()
forward(600)
penup()

# Vertical bars
goto(-100, 300)
setheading(-90)
pendown()
forward(600)
penup()
goto(100, 300)
pendown()
forward(600)
penup()

pencolor("green")

# Draw noughts and crosses
def cross(x, y):
    penup()
    goto(x + 20, y - 20)
    setheading(-45)
    pendown()
    forward(226)
    penup()
    goto(x + 180, y - 20)
    setheading(-135)
    pendown()
    forward(226)
    penup()

def nought(x, y):
    penup()
    goto(x + 100, y - 180)
    setheading(0)
    pendown()
    circle(80)
    penup()

def drawPieces(pieces):
    x, y = -300, 300

    for piece in pieces:
        if piece == "X":
            cross(x, y)
        elif piece == "O":
            nought(x, y)

        x += 200
        if x > 100:
            x = -300
            y -= 200

def clicked(x, y):
    global turn, pieces

    onscreenclick(None)  # disable handler when inside handler!

    column = (x + 300) // 200
    row = (y - 300) // -200
    square = int(row * 3 + column)

    print("You clicked ", x, ",", y, " which is square ", square)

    if pieces[square] == "":
        pieces[square] = turn

        if turn == "X":
            turn = "O"
        else:
            turn = "X"

        drawPieces(pieces)
    else:
        print("That square is already taken")

    onscreenclick(clicked)

# Start the game
onscreenclick(clicked)

mainloop()

enter image description here

cdlane
  • 40,441
  • 5
  • 32
  • 81