예제 #1
0
    def markShot(self, puck):
        puckPos = self.getRelativePos(puck.position)
        puckVel = self.getRelativeVector(puck.velocity)

        if puckVel.x < 0:
            return 0

        shotLine = Line(puckPos, puckPos + puckVel)
        goalLine = Line(Vector2(FIELD_WIDTH, 0), Vector2(FIELD_WIDTH, 1))
        intersection = shotLine.getIntersectPoint(goalLine)

        if intersection is None:
            return 0

        distFromCenter = abs(intersection.y)
        bounces = 0

        afterBounceDist = distFromCenter
        while afterBounceDist > FIELD_HEIGHT / 2:
            bounces += 1
            afterBounceDist -= FIELD_HEIGHT

        afterBounceDist = abs(afterBounceDist)

        if bounces > 3:
            return 0

        if afterBounceDist > GOAL_SPAN / 2:
            accuracy = min(1, ((GOAL_SPAN / 2) / afterBounceDist)**2)
        else:
            accuracy = 1

        return round(puck.velocity.magnitude_squared() / 100000 * accuracy)
예제 #2
0
    def defendGoalDefault(self):
        if self.willBounce and self.puck.state == ACURATE\
          and (self.puck.vector.x < -0.5 or (self.puck.vector.x < 0 and self.puck.trajectory[-1].end.x <= PUCK_RADIUS))\
          and not (self.puck.position.x > FIELD_WIDTH*.6 and self.puck.speedMagnitude < 500):
            if self.puck.trajectory[-1].end.x > XLIMIT + STRIKER_RADIUS:
                fromPoint = self.puck.trajectory[-1].end
            else:
                fromPoint = self.puck.trajectory[-1].start
        else:
            fromPoint = self.puck.position

        a = Line(fromPoint, Vector2(0, 0))
        b = Line(Vector2(DEFENSE_LINE, -FIELD_HEIGHT / 2),
                 Vector2(DEFENSE_LINE, FIELD_HEIGHT / 2))

        desiredPosition = a.getIntersectPoint(b)

        self.debugLines.append(a)
        self.debugLines.append(b)
        self.debugString = "basic.defendGoalDefault"

        if desiredPosition is not None:
            self.setDesiredPosition(Vector2(desiredPosition))
예제 #3
0
    def initialCheck(self, pos):

        currentStepVector = pos - self.puck.position
        stepDistance = currentStepVector.magnitude()

        if self.puck.timeSinceCaptured == 0:
            stepSpeed = 0
        else:
            stepSpeed = stepDistance / self.puck.timeSinceCaptured

        errorAngle = self.getAngleDifference(currentStepVector,
                                             self.puck.velocity)

        # Low angle condition
        if abs(errorAngle) > self.lowAngleTolerance and sign(
                errorAngle) == self.previousErrorSide:
            self.capturesWithBadLowAngle += 1
            if (self.capturesWithBadLowAngle > 4):
                # print("Low Angle error")

                for i in range(4):
                    self.puckHistory[self.firstUsefull].state = USELESS
                    if self.firstUsefull > 1: self.firstUsefull -= 1
        else:
            self.capturesWithBadLowAngle = 0

        self.previousErrorSide = sign(errorAngle)

        if stepSpeed > 200 and stepDistance > 4 and abs(errorAngle):
            # Medium angle condition
            if abs(errorAngle) > self.mediumAngleTolerance and sign(
                    errorAngle) == self.previousErrorSide:
                self.capturesWithBadMediumAngle += 1
                if (self.capturesWithBadMediumAngle > 3):
                    # print("Low angle condition.. 4 states -> useless")
                    self.capturesWithBadLowAngle = 0
                    self.capturesWithBadMediumAngle = 0
                    # print("Medium Angle error")
                    for i in range(3, len(self.puckHistory)):
                        self.puckHistory[i].state = USELESS

            else:
                self.capturesWithBadMediumAngle = 0

            # Debug
            # if len(self.puck.trajectory) > 0:
            # trajectoryLine = Line(self.puckHistory[self.firstUsefull].position, self.puck.position)
            # bounceLine = Line(Vector2(0, sign(pos.y) * (FIELD_HEIGHT/2 - PUCK_RADIUS)), Vector2(FIELD_WIDTH,  sign(pos.y) * (FIELD_HEIGHT/2 - PUCK_RADIUS)))
            # self.debugLines.append(trajectoryLine)
            # self.debugLines.append(bounceLine)
            # self.debugPoints.append(self.getIntersectPoint(trajectoryLine, bounceLine))

            # High angle condition
            if (abs(errorAngle) > self.highAngleTolerance) or (
                    stepSpeed > 700 and stepDistance > 25
                    and abs(errorAngle) > self.highAngleTolerance * .4):
                self.capturesWithBadLowAngle = 0
                self.capturesWithBadMediumAngle = 0

                # print("Angle condition: " + str(errorAngle))
                if abs(pos.y) > max(
                        200, FIELD_HEIGHT / 2 -
                    (stepDistance * abs(self.puck.vector.y) + PUCK_RADIUS)
                ) and sign(currentStepVector.x) == sign(
                        self.puck.velocity.x
                ) and sign(self.puck.velocity.y) == sign(
                        pos.y
                ) and self.puck.state == ACURATE:  # seems like bounce from sidewalls occured
                    trajectoryLine = Line(
                        self.puckHistory[self.firstUsefull].position,
                        self.puck.position)
                    bounceLine = Line(
                        Vector2(0,
                                sign(pos.y) *
                                (FIELD_HEIGHT / 2 - PUCK_RADIUS)),
                        Vector2(FIELD_WIDTH,
                                sign(pos.y) *
                                (FIELD_HEIGHT / 2 - PUCK_RADIUS)))

                    bouncePoint = trajectoryLine.getIntersectPoint(bounceLine)
                    self.debugLines.append(trajectoryLine)
                    self.debugLines.append(bounceLine)
                    bouncePoint = trajectoryLine.getIntersectPoint(bounceLine)
                    self.puck.position = bouncePoint
                    # print(bouncePoint)
                for i in range(len(self.puckHistory)):
                    self.puckHistory[i].state = USELESS