틱택토 터틀 함수 같은 지역에 안들어가게 하는법

조회수 903회

from turtle import * 로 실행하고 9개 지역에서 x 랑 o 까지 넣는 것은 됐습니다. 근데 3줄 맞추고 게임을 끝내는 것하고 이미 문자가 입력된 곳에 중복으로 들어가는 오류가 발생합니다 어떻게 해결하면 좋을까요?


pieces = ["", "", "", "", "", "", "", "", ""]
nextTurn = "X"


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

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

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

def clicked(x, y):
    global nextTurn, pieces
    column = (x+300)//200
    row = -(y-300)//200
    square = column + row*3
    square = int(square)
    print("You clicked ",x,",",y," square", square)
    pieces[square] = nextTurn
    if nextTurn == "X":
        nextTurn = "O"
    else:
        nextTurn = "X"

    drawPieces(pieces)

onscreenclick(clicked)
mainloop()

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)