What’s wrong here ? I can’t understand

Asked

Viewed 72 times

0

from tkinter import *
import random
import time
import math
'''

                  Isso foi uma tentativa de criar
                  uma inteligencia artificial.
                  Não consegui encontrar os erros :(

'''
#Variaveis:

velx=1
vely=0
Height = 280
Width  = 470
Acao=0
Mortes=0
Random=0
Survivals=0
SuccessT=0
jumpsuccescount=1
jumpweight=0
problem=0
shortjumpsuccescount=1
shortjumpweight=0
totalSuccess=0
turnSuccescount=1
turnweight=0
walkSuccescount=1
walkwight=0

#Configurações da janela:
janela= Tk()
janela.title('I.A')
janela.geometry('470x280+200+300')
canvas= Canvas(janela, width = Width, height = Height)
canvas.pack()

#Fundo:

fundo = PhotoImage(file='D:\\Patrick\\PYTHON\\Inteligencia artificial\\Fundo.png')
canvas.create_image(0,0,anchor=NW,image=fundo)

#Personagem:

Per = PhotoImage(file='D:\\Patrick\\PYTHON\\Inteligencia artificial\\P.png')
Personagem = canvas.create_image(0,79,anchor=NW,image=Per)

# Inteligencia :

while True:
    canvas.move(Personagem,velx,vely) 
    pos = canvas.coords(Personagem) #pegar a pos do personagem

    if pos[1]<79:
        canvas.move(Personagem,velx,0.5)
    else:
        vely=0
    if pos[0]>=Width or pos[0]<0: #Se tocar na borda, volte
        velx= -velx

    SuccessT=1
    while SuccessT!=0 or not pos[0]>=Width or pos[0]<0:
        canvas.move(Personagem,velx,vely)
        if pos[1]<79:
            canvas.move(Personagem,velx,0.5)
        else:
            vely=0
        if pos[0]>=198 and pos[1]==79 and pos[0]<=270:
            mortes+=1
            canvas.move(Personagem,0,79)
            vely=0
            Success=0
        if pos[0]>=180 and pos[0]<=198 or pos[0]>=270 and pos[0]<=262:

            problem=0
            totalSuccess=walkSuccesscount+turnSuccescount+shortjumpsuccescount+jumpsuccescount
            walkweight=walkSuccescount/totalSuccess
            turnweight=turnSuccescount/totalSuccess
            jumpweight=jumpsuccescount/totalSuccess
            shortjumpweight=shortjumpsuccescount/totalSuccess
            Random=(random.randrange(1,1000))/1000
        if Random<turnweight:
           velx= -velx
           Acao=1
        else:
            Random+= -1*turnweight
            if Random<jumpweight:
                vely=12
                Acao=2
                canvas.move(Personagem,velx,10)
            else:
                Random+= -1*jumpweight
                if Random<shortjumpweight:
                    vely=5
                    Acao=3
                    canvas.move(Personagem,velx,10)
                else:
                    Acao=0
    Survivals+=SuccessT
    if Acão==0:
        walkSuccesscount+=SuccessT
    elif Acao==1:
        turnSuccesscount+=SuccessT
    elif Acao==2:
        jumpsuccesscount+=SuccessT
    else:
        shortjumpsuccesscount+=SuccessT
    janela.update()
    time.sleep(0.1)
    janela.mainloop()

1 answer

1

Possibly coding, before any code adds

# -*- coding: utf-8 -*-

You have the variable Action that on the line 103 is Action

Browser other questions tagged

You are not signed in. Login or sign up in order to post.