I was coding 0 - player game with random library, the error often accrues after thousands of iterations for no apparent reason, I am using only random.randint
so there is no need for rounding, I have seen similar question like this but with no answer because user didn't send enough error traceback, here is link:
'int' object is not callable only appears randomly
my code looks like that:
inventory = 0
sprint = 0
dirt = 0
stone = 0
wood = 0
plank = 0
stick = 0
craftingTable = 0
woodPick = 0
stonePick = 0
def randomMove():
global inventory
global sprint
if inventory == 0:
if sprint == 0:
randomed = random.randint(0, 10)
listOfActions = [rightH, rightC, leftH, leftC, W, A, S, D, angleRandomize, openInventory, startSprint]
listOfActions[randomed]()
else:
randomed = random.randint(0, 10)
listOfActions = [rightH, rightC, leftH, leftC, W, A, S, D, angleRandomize, openInventory, stopSprint]
listOfActions[randomed]()
else:
randomed = random.randint(0, 1)
listOfActions = [closeInventory, craft]
listOfActions[randomed]()
def rightH():
global dirt, stone, wood, woodPick
rand = random.randint(0, 1)
if rand == 0:
rand = random.randint(0, 99)
if rand < 74:
if woodPick == 0:
print("Broke stone, not dropped")
else:
print("Broke stone")
stone += 1
if 74 < rand < 99:
print("Broke dirt")
dirt += 1
if 98 < rand:
print("Broke wood")
wood += 1
else:
print("Holding Right Click")
def rightC():
print("Clicking Right Click")
def leftH():
print("Holding Left Click")
def leftC():
print("Clicking Left Click")
def W():
print("Going forward")
def A():
print("Going left")
def S():
print("Going backwards")
def D():
print("Going right")
def angleRandomize():
x = random.randint(-180, 180)
y = random.randint(-90, 90)
print("Randomized angle, looking " + str(x) + " " + str(y))
def openInventory():
global inventory, sprint
print("Opening inventory")
inventory = 1
sprint = 0
def closeInventory():
global inventory
print("Closing inventory")
inventory = 0
def startSprint():
global sprint
print("Sprinting")
sprint = 1
def stopSprint():
global sprint
print("Stopping Sprint")
sprint = 0
def craftPlanks():
global plank, wood
plank += 4
wood -= 1
def craftSticks():
global stick, plank
stick += 4
plank -= 2
def craftCraftingTable():
global craftingTable, plank
craftingTable += 1
plank -= 4
def craftWoodPick():
global woodPick, plank, stick
woodPick += 1
plank -= 3
stick -= 2
def craftStonePick():
global stonePick, stick, stone
stonePick += 1
stone -= 3
stick -= 2
def craft():
options = []
if wood >= 1:
options.append(craftPlanks)
if plank >= 2:
options.append(craftSticks)
if plank >= 4:
options.append(craftingTable)
if plank >= 3 and stick >= 2 and craftingTable >= 1:
options.append(craftWoodPick)
if stone >= 3 and stick >= 2 and craftingTable >= 1:
options.append(craftStonePick)
if len(options) == 0:
print("Can't craft")
else:
randomCraft = random.randint(0, len(options) - 1)
options[randomCraft]()
for i in range(100000):
inventoryStored = [dirt, stone, wood, plank, stick, craftingTable]
print("Inventory: " + str(inventoryStored))
randomMove()
if craftingTable == 1:
break
and error traceback is:
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\Program Files\JetBrains\PyCharm Community Edition 2020.3.3\plugins\python-ce\helpers\pydev\_pydev_bundle\pydev_umd.py", line 197, in runfile
pydev_imports.execfile(filename, global_vars, local_vars) # execute the script
File "C:\Program Files\JetBrains\PyCharm Community Edition 2020.3.3\plugins\python-ce\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "C:/Users/***/PycharmProjects/randomMinecraftAgent/RandomAgnetWithSimulatedMinecraft.py", line 147, in <module>
randomMove()
File "C:/Users/***/PycharmProjects/randomMinecraftAgent/RandomAgnetWithSimulatedMinecraft.py", line 29, in randomMove
listOfActions[randomed]()
File "C:/Users/***/PycharmProjects/randomMinecraftAgent/RandomAgnetWithSimulatedMinecraft.py", line 141, in craft
options[randomCraft]()
TypeError: 'int' object is not callable
this "simulation" is working for thousands of iterations and then it just breaks, how to fix that?
Aucun commentaire:
Enregistrer un commentaire