From f98a29176369ebd19078d93ff44e6ae95f6da82e Mon Sep 17 00:00:00 2001 From: BorisKolganov Date: Tue, 4 Sep 2018 23:50:11 +0300 Subject: [PATCH] add groove joint and py3.6 --- .../Runners/mechanic/game_objects/base_car.py | 16 ++++++---------- madcars/Runners/mechanic/game_objects/cars.py | 19 ++++++------------- madcars/Runners/mechanic/game_objects/maps.py | 11 +++++++---- madcars/dockers/python3/Dockerfile | 6 ++++-- 4 files changed, 23 insertions(+), 29 deletions(-) diff --git a/madcars/Runners/mechanic/game_objects/base_car.py b/madcars/Runners/mechanic/game_objects/base_car.py index a7b0b2d..c0df20c 100644 --- a/madcars/Runners/mechanic/game_objects/base_car.py +++ b/madcars/Runners/mechanic/game_objects/base_car.py @@ -84,7 +84,6 @@ def create_wheel(self, wheel_side): wheel_position = getattr(self, wheel_side + '_wheel_position') wheel_friction = getattr(self, wheel_side + '_wheel_friction') wheel_elasticity = getattr(self, wheel_side + '_wheel_elasticity') - wheel_joint = getattr(self, wheel_side + '_wheel_joint') wheel_damp_position = getattr(self, wheel_side + '_wheel_damp_position') wheel_damp_length = getattr(self, wheel_side + '_wheel_damp_length') wheel_damp_stiffness = getattr(self, wheel_side + '_wheel_damp_stiffness') @@ -100,8 +99,12 @@ def create_wheel(self, wheel_side): wheel_shape.elasticity = wheel_elasticity wheel_objects.append(wheel_shape) - wheel_joint = pymunk.PinJoint(wheel_body, self.car_body, anchor_b=(wheel_joint[0] * self.x_modification, wheel_joint[1])) - wheel_objects.append(wheel_joint) + wheel_grove = pymunk.GrooveJoint(self.car_body, wheel_body, + (wheel_damp_position[0] * self.x_modification, wheel_damp_position[1]), + (wheel_damp_position[0] * self.x_modification, + wheel_damp_position[1] - wheel_damp_length * 1.5), + (0, 0)) + wheel_objects.append(wheel_grove) wheel_damp = pymunk.DampedSpring(wheel_body, self.car_body, anchor_a=(0, 0), anchor_b=(wheel_damp_position[0] * self.x_modification, wheel_damp_position[1]), @@ -110,16 +113,9 @@ def create_wheel(self, wheel_side): damping=wheel_damp_damping) wheel_objects.append(wheel_damp) - wheel_stop = pymunk.Poly(self.car_body, [(0, 0), (0, 1), (wheel_radius * 2 * self.x_modification, 1), (wheel_radius * 2 * self.x_modification, 0)], - transform=pymunk.Transform(tx=wheel_damp_position[0] * self.x_modification - wheel_radius * self.x_modification, ty=wheel_damp_position[1])) - wheel_objects.append(wheel_stop) - - wheel_stop.color = 0, 255, 0 - wheel_motor = None if (wheel_side == 'rear' and self.drive in [self.AWD, self.FR]) or (wheel_side == 'front' and self.drive in [self.AWD, self.FF]): wheel_motor = pymunk.SimpleMotor(wheel_body, self.car_body, 0) - # wheel_objects.append(motor) return wheel_body, wheel_motor, wheel_objects diff --git a/madcars/Runners/mechanic/game_objects/cars.py b/madcars/Runners/mechanic/game_objects/cars.py index 5fd068e..59eb29d 100644 --- a/madcars/Runners/mechanic/game_objects/cars.py +++ b/madcars/Runners/mechanic/game_objects/cars.py @@ -28,7 +28,6 @@ class Buggy(Car): rear_wheel_mass = 50 rear_wheel_position = (29, -5) - rear_wheel_joint = (150, 0) rear_wheel_damp_position = (29, 20) rear_wheel_damp_stiffness = 5e4 rear_wheel_damp_damping = 3e3 @@ -37,7 +36,6 @@ class Buggy(Car): front_wheel_mass = 5 front_wheel_position = (122, -5) - front_wheel_joint = (0, 6) front_wheel_damp_position = (122, 20) front_wheel_damp_length = 25 front_wheel_radius = 12 @@ -69,7 +67,6 @@ class Bus(Car): rear_wheel_radius = 13 rear_wheel_position = (38, -5) rear_wheel_friction = 0.9 - rear_wheel_joint = (153, 5) rear_wheel_damp_position = (38, 30) rear_wheel_damp_length = 35 rear_wheel_damp_stiffness = 10e4 @@ -77,7 +74,6 @@ class Bus(Car): front_wheel_radius = 13 front_wheel_position = (125, -5) - front_wheel_joint = (0, 6) front_wheel_damp_position = (125, 30) front_wheel_damp_length = 35 front_wheel_damp_stiffness = 10e4 @@ -108,7 +104,6 @@ def create_wheel(self, wheel_side): wheel_position = getattr(self, wheel_side + '_wheel_position') wheel_friction = getattr(self, wheel_side + '_wheel_friction') wheel_elasticity = getattr(self, wheel_side + '_wheel_elasticity') - wheel_joint = getattr(self, wheel_side + '_wheel_joint') wheel_damp_position = getattr(self, wheel_side + '_wheel_damp_position') wheel_damp_length = getattr(self, wheel_side + '_wheel_damp_length') wheel_damp_stiffness = getattr(self, wheel_side + '_wheel_damp_stiffness') @@ -124,8 +119,12 @@ def create_wheel(self, wheel_side): wheel_shape.elasticity = wheel_elasticity wheel_objects.append(wheel_shape) - wheel_joint = pymunk.PinJoint(wheel_body, self.car_body, anchor_b=(wheel_joint[0] * self.x_modification, wheel_joint[1])) - wheel_objects.append(wheel_joint) + wheel_grove = pymunk.GrooveJoint(self.car_body, wheel_body, + (wheel_damp_position[0] * self.x_modification, wheel_damp_position[1]), + (wheel_damp_position[0] * self.x_modification, + wheel_damp_position[1] - wheel_damp_length * 1.5), + (0, 0)) + wheel_objects.append(wheel_grove) wheel_damp = pymunk.DampedSpring(wheel_body, self.car_body, anchor_a=(0, 0), anchor_b=(wheel_damp_position[0] * self.x_modification, wheel_damp_position[1]), @@ -134,12 +133,6 @@ def create_wheel(self, wheel_side): damping=wheel_damp_damping) wheel_objects.append(wheel_damp) - wheel_stop = pymunk.Poly(self.car_body, [(0, 0), (0, 1),(wheel_radius * 2 * self.x_modification, 1), (wheel_radius * 2 * self.x_modification, 0)], - transform=pymunk.Transform(tx=wheel_damp_position[0] * self.x_modification - wheel_radius * self.x_modification, ty=wheel_damp_position[1])) - wheel_objects.append(wheel_stop) - - wheel_stop.color = 0, 255, 0 - wheel_motor = None if (wheel_side == 'rear' and self.drive in [self.AWD, self.FR]) or (wheel_side == 'front' and self.drive in [self.AWD, self.FF]): wheel_motor = pymunk.SimpleMotor(wheel_body, self.car_body, 0) diff --git a/madcars/Runners/mechanic/game_objects/maps.py b/madcars/Runners/mechanic/game_objects/maps.py index 979bb0d..c23966e 100644 --- a/madcars/Runners/mechanic/game_objects/maps.py +++ b/madcars/Runners/mechanic/game_objects/maps.py @@ -32,16 +32,19 @@ def __init__(self, space): self.objects.append(segment) def create_box(self, space): - left = pymunk.Segment(space.static_body, (0, 0), (0, self.max_height), 1) + bo = self.segment_height - 1 # box offset + left = pymunk.Segment(space.static_body, (-bo, -bo), (-bo, self.max_height + bo), self.segment_height) left.sensor = True - top = pymunk.Segment(space.static_body, (0, self.max_height), (self.max_width, self.max_height), 1) + top = pymunk.Segment(space.static_body, (-bo, self.max_height + bo), + (self.max_width + bo, self.max_height + bo), 10) top.sensor = True - right = pymunk.Segment(space.static_body, (self.max_width, self.max_height), (self.max_width, 0), 1) + right = pymunk.Segment(space.static_body, (self.max_width + bo, self.max_height + bo), + (self.max_width + bo, -bo), 10) right.sensor = True - bottom = pymunk.Segment(space.static_body, (self.max_width, 0), (0, 0), 1) + bottom = pymunk.Segment(space.static_body, (self.max_width + bo, -bo), (-bo, -bo), 10) bottom.sensor = True self.objects.extend([left, top, right, bottom]) diff --git a/madcars/dockers/python3/Dockerfile b/madcars/dockers/python3/Dockerfile index 87c2d4b..70c69fa 100644 --- a/madcars/dockers/python3/Dockerfile +++ b/madcars/dockers/python3/Dockerfile @@ -1,8 +1,10 @@ FROM ubuntu:16.04 MAINTAINER Boris Kolganov -RUN apt-get update && apt-get install -y python3 python3-pip && pip3 install -U numpy scipy cython scikit-learn keras pandas tensorflow==1.5.0 pymunk==5.3.2 +RUN add-apt-repository ppa:jonathonf/python-3.6 && \ + apt-get update && apt-get install -y python3.6 python3-pip && \ + python3.6 -m pip install -U numpy scipy cython scikit-learn keras pandas tensorflow==1.5.0 pymunk==5.3.2 ENV SOLUTION_CODE_ENTRYPOINT=main.py ENV SOLUTION_CODE_PATH=/opt/client/solution -ENV RUN_COMMAND='python3 -u $SOLUTION_CODE_PATH/$SOLUTION_CODE_ENTRYPOINT' +ENV RUN_COMMAND='python3.6 -u $SOLUTION_CODE_PATH/$SOLUTION_CODE_ENTRYPOINT'