Reputation: 445
I am trying to implement a robot environment which is a part of a free course provided by Intel. There are multiple files in the course assignment, MakeItLearn.py
is the one we were supposed to edit and add a network of our own there for the training of the bot.
But when I try to collect data using the ExploreAndCollect.py
file, which Intel also provides and we're not told to change anything in that file, it throws the following error :
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'
Here's the code where the class and the function is defined:
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
I looked at the function call, which is also mentioned above, and it has the y
component in it so I can't seem to find what seems to be causing the error. The python environment requirements were Python 2.7 and all versions of Python 3
Upvotes: 0
Views: 1396
Reputation: 11808
The code that comes with the course you are doing uses pymunk.vec2d.Vec2d. There recently has been an update to Vec2d
making it a NamedTuple. Before that change, Vec2d
could be created using a tuple:
vec2d = Vec2d((x, y))
That is no longer possible. Vec2d
being a named tuple with fields x
and y
can be created using: separate arguments, *
syntax for tuple unpacking or Vec2d._make:
v1 = Vec2d(3, 4)
v2 = Vec2d(*(3, 4))
v3 = Vec2d._make((3, 4))
This is all described in the Changelog for Pymunk (version 6.0.0):
- Made Vec2d a subclass of NamedTuple.
- Vec2ds has to be constructed with separate x and a y values.
- Vec2d((1,2)) can be changed to Vec2d(*(1,2)).
- Vec2d(Vec2d(1,2)) can be changed to Vec2d(*Vec2d(1,2)).
- Vec2d() can be changed to Vec2d(0,0) or Vec2d.zero().
- Vec2d(1,2) is no longer equal to [1,2] since they are of different types. (but Vec2d(1,2) == (1,2) is still true)
You probably should let the people at Intel know that their code is broken with Pymunk 6.0.0 and higher. For the time being you could try to use a version of Pymunk prior to 6.0.0 (that is probably the best solution) or you could change the code that comes with the course and use one of the options above.
Upvotes: 1