我正在尝试实现一个机器人环境,这是英特尔提供的免费课程的一部分。课程作业中有多个文件,MakeItLearn.py
是我们应该编辑的文件,并在其中添加我们自己的网络,用于机器人的培训
但是,当我尝试使用ExploreAndCollect.py
文件收集数据时(Intel也提供了该文件,我们没有被告知更改该文件中的任何内容),它会抛出以下错误:
Traceback (most recent call last): File "ExploreAndCollect.py", line 268, in <module> env = BotEnv() File "ExploreAndCollect.py", line 35, in __init__ self.BuildBot(50.01, 450.01, 20) File "ExploreAndCollect.py", line 69, in BuildBot BoxPoints = list(map(Vec2d, [(-size, -size), (-size, size), (size,size), (size, -size)])) TypeError: __new__() missing 1 required positional argument: 'y'
下面是定义类和函数的代码:
class BotEnv:
def __init__(self):
## Initialize Required Variables
self.crashed = False
self.DetectCrash = 0
self.space = pymunk.Space()
self.BuildBot(50.01, 450.01, 20) <---------------------------------------------
self.walls = []
self.WallShapes = []
self.WallRects = []
## Add Walls To The Map ###
WallBody, WallShape, WallRect = self.BuildWall(200, 50, 50)
self.WallRects.append(WallRect)
WallBody, WallShape, WallRect = self.BuildWall(200, 125, 50)
self.WallRects.append(WallRect)
WallBody, WallShape, WallRect = self.BuildWall(200, 550, 50)
self.WallRects.append(WallRect)
WallBody, WallShape, WallRect = self.BuildWall(200, 450, 50)
self.WallRects.append(WallRect)
WallBody, WallShape, WallRect = self.BuildWall(400, 350, 50)
self.WallRects.append(WallRect)
WallBody, WallShape, WallRect = self.BuildWall(400, 250, 50)
self.WallRects.append(WallRect)
WallBody, WallShape, WallRect = self.BuildWall(500, 250, 50)
self.WallRects.append(WallRect)
WallBody, WallShape, WallRect = self.BuildWall(600, 250, 50)
self.WallRects.append(WallRect)
WallBody, WallShape, WallRect = self.BuildWall(115, 1050, 500)
self.WallRects.append(WallRect)
self.PreviousAction = 0
def BuildBot(self, x, y, r):
### Build The Bot Object ###
size = r
BoxPoints = list(map(Vec2d, [(-size, -size), (-size, size), (size,size), (size, -size)])) <----------------
mass = 0.5
moment = pymunk.moment_for_poly(mass,BoxPoints, Vec2d(0,0))
self.Bot = pymunk.Body(mass, moment)
self.Bot.position = (x,y) # Declare Bot Position
self.Bot.angle = 1.54 # Set the Bot Angle
BotDirection = Vec2d(PointsFromAngle(self.Bot.angle)) # Get The Direction Vector From Angle
self.space.add(self.Bot)
self.BotRect = pygame.Rect(x-r,600-y-r, 2*r, 2*r)
return self.Bot
我查看了上面提到的函数调用,其中包含y
组件,因此我似乎无法找到导致错误的原因。python环境要求是Python2.7和Python3的所有版本
出什么问题了?
您正在学习的课程附带的代码使用pymunk.vec2d.Vec2d。最近对
Vec2d
进行了更新,使其成为NamedTuple。在此更改之前,可以使用元组创建Vec2d
:这已经不可能了}和{}的命名元组,可以使用以下方法创建:{}单独的参数、
Vec2d
是一个带有字段{*
元组解包语法或Vec2d._make:这些都在the Changelog for Pymunk(版本6.0.0)中描述:
那你能做什么呢
您可能应该让英特尔的员工知道,他们的代码已被Pymunk 6.0.0及更高版本破坏。目前,您可以尝试使用Pymunk 6.0.0之前的版本(这可能是最好的解决方案),也可以更改课程附带的代码,并使用上述选项之一
相关问题 更多 >
编程相关推荐