Python Colab Turtle Tic Tac Toe рисует круги не по центру без причиныPython

Программы на Python
Ответить
Anonymous
 Python Colab Turtle Tic Tac Toe рисует круги не по центру без причины

Сообщение Anonymous »

Код: Выделить всё

def square(x):
for i in range(4):
allmight.pendown()
allmight.forward(x)
allmight.right(90)
def nextshape(jump):
allmight.penup()
allmight.forward(jump)
allmight.pendown()
def nextrow():
allmight.penup()
allmight.setheading(180)
allmight.forward(300)
allmight.setheading(270)
allmight.forward(100)
def printboard():
print(board[0])
print(board[1])
print(board[2])
def go():
row = int(input("which row do you want to place in? (1 is top, 2 is middle, 3 is bottom)"))
collumn = int(input("which collumn do you want to place in? (1 is left, 2 is middle, 3 is right)"))
while board[row-1][collumn-1] != " ":
row = int(input("which row do you want to place in? (1 is top, 2 is middle, 3 is bottom)"))
collumn = int(input("which collumn do you want to place in? (1 is left, 2 is middle, 3 is right)"))
xvalue = boardx[row-1][collumn-1]
yvalue = boardy[row-1][collumn-1]
if piece == "o":
board[row-1][collumn-1] = "o"
circle(xvalue,yvalue)
if piece == "x":
board[row-1][collumn-1] = "x"
cross(xvalue,yvalue)
def check_won():
won = False
if board[0][0] == board[0][1] and board[0][1] == board[0][2]:
if board[0][0] != " ":
won = True
elif board[1][0] == board[1][1] and board[1][1] == board[1][2]:
if board[1][0] != " ":
won = True
elif board[2][0] == board[2][1] and board[2][1] == board[2][2]:
if board[2][0] != " ":
won = True
elif board[0][0] == board[1][0] and board[1][0] == board[2][0]:
if board[0][0] != " ":
won = True
elif board[0][1] == board[1][1] and board[1][1] == board[2][1]:
if board[0][1] != " ":
won = True
elif board[0][2] == board[1][2] and board[1][2] == board[2][2]:
if board[0][2] != " ":
won = True
elif board[0][0] == board[1][1] and board[1][1] == board[2][2]:
if board[0][0] != " ":
won = True
elif board[0][2] == board[1][1] and board[1][1] == board[2][0]:
if board[0][2] != " ":
won = True
return won
def opponentgo():
print('not yet')
def opponentgorandom():
opponentx = random.randint(0,2)
opponenty = random.randint(0,2)
opponentgo = board[opponentx][opponenty]
while opponentgo != " ":
opponentx = random.randint(0,2)
opponenty = random.randint(0,2)
opponentgo = board[opponentx][opponenty]
xvalue = boardx[opponentx][opponenty]
yvalue = boardy[opponentx][opponenty]
board[opponentx][opponenty] = opponentpiece
if opponentpiece == "o":
circle(xvalue,yvalue)
print(xvalue)
print(yvalue)
if opponentpiece == "x":
cross(xvalue,yvalue)
print(xvalue)
print(yvalue)
def circle(x,y):
allmight.goto(x-35,y)
print(allmight.pos())
allmight.pendown()
allmight.circle(35)
allmight.penup()
allmight.goto(x,y)
def cross(x,y):
for count in range(0,4):
allmight.goto(x,y)
allmight.down()
allmight.setheading(45+(90*count))
allmight.forward(55)
allmight.penup()
import ColabTurtlePlus.Turtle as allmight
import random
allmight.initializeTurtle((300,300), 'standard', 10)
allmight.clear()
allmight.speed(13)
allmight.bgcolor("rgb(240 248 255)")
allmight.pencolor("rgb(0 0 0)")
allmight.fillcolor("rgb(255 127 80)")
allmight.penup()
allmight.goto(-150,150)
allmight.pendown()
board = [[" ", " ", " "],
[" ", " ", " "],
[" ", " ", " "]]
boardx = [[-100,0,100],
[-100,0,100],
[-100,0,100]]
boardy = [[100,100,100],
[0,  0,  0],
[-100,-100,-100]]
for item in range(0,3):
for count in range(0,3):
allmight.setheading(0)
square(100)
nextshape(100)
nextrow()
piece = str(input("Do you want to be noughts(enter o) or crosses(enter x)"))
while piece != "o"  and piece != "x":
piece = str(input("Do you want to be noughts(enter o) or crosses(enter x)"))
if piece == "o":
opponentpiece = "x"
if piece == "x":
opponentpiece = "o"
if opponentpiece == "o":
board[0][0] = "o"
circle(-100,100)
if opponentpiece == "x":
board[0][0] = "x"
cross(-100,100)
printboard()
go()
haswon = check_won()
printboard()
while haswon == False:
opponentgorandom()
printboard()
go()
haswon = check_won()
print("")
printboard()
print("somebody won")

print(board[0])
print(board[1])
print(board[2])

если код начинается, первый круг не будет смещен от центра, а остальные будут смещены.
Я пробовал изменить некоторые значения, но это просто помогло первый круг находился в центре, а не в центре, поэтому я почти уверен, что проблема где-то в более поздних частях кода. Код создает версию двухмерного массива, которая работает нормально, единственная проблема — рисование круга. Кресты всегда находятся в центре, хотя они используют очень похожий код. Я не вижу какого-либо очевидного решения, поэтому, если бы кто-нибудь нашел его, было бы здорово.

Подробнее здесь: https://stackoverflow.com/questions/792 ... -no-reason
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Python»