コード例 #1
0
ファイル: Strategy.py プロジェクト: robbai/RLBotPack
def ChaseBallBias(s):

    s.tL, s.tV, s.taV, s.dT = s.ptL, s.ptV, s.ptaV, s.pdT

    dt = s.bfd / 5300
    tPath = PhysicsLib.predictPath(s.ptL, s.ptV, s.ptaV, dt + 1 / 60, 60)
    tState = tPath.ballstates[min(tPath.numstates - 1, 0)]
    s.tL = a3(tState.Location)
    s.tV = a3(tState.Velocity)
    s.pfL, s.pfV = PhysicsLib.CarStep(s.pfL, s.pfV, dt)
    s.dT += dt

    s.fx, s.fy, s.fz = local(s.tL, s.pfL, s.pR)
    s.fd, s.fa, s.fi = spherical(s.fx, s.fy, s.fz)
    s.fd2 = dist2d([s.fx, s.fy])
    s.fgd2 = dist2d(s.pfL, s.tL)

    s.tx, s.ty, s.tz = local(s.tL, s.pL, s.pR)
    s.td, s.ta, s.ti = spherical(s.tx, s.ty, s.tz)
    s.td2 = dist2d([s.tx, s.ty])
    s.r = s.pR[2] / U180
    s.tLb = s.tL

    Cl = Ph.Collision_Model(s.pfL)
    if s.aerialing and not Cl.hasCollided:
        n1 = normalize(s.tL - s.pL)
        v1 = s.pV
        b1 = v1 - np.dot(v1, n1) * n1
        d = s.bd
        v = max(s.pvd * .5 + .5 * dist3d(s.pfV), 200)
        t = d / v
        s.tLb = s.tL - b1 * t

    s.ax, s.ay, s.az = local(s.tLb, s.pL, s.pR)
    s.d, s.a, s.i = spherical(s.ax, s.ay, s.az)
    s.d2 = dist2d([s.ax, s.ay])

    s.tLs = s.tL

    if s.pL[2] > 20 and s.poG and (s.tL[2] < s.az or s.az > 450 + s.pB * 9):
        s.tLs[2] = 50

    s.sx, s.sy, s.sz = local(s.tLs, s.pL, s.pR)
    s.sd, s.sa, s.si = spherical(s.sx, s.sy + 50, s.sz)
    s.sd2 = dist2d([s.ax, s.ay])

    if not s.offense:
        s.goal = set_dist(s.tL, s.ogoal, -999)

    if max(abs(s.fz), abs(s.bz)
           ) > 130 or s.odT + dist3d(s.otL, s.ofL) / 5300 < s.pdT + 1 or 1:
        Bias(s, 93)
    else:
        aimBias(s, s.goal)

    s.txv, s.tyv, s.tzv = s.bxv, s.byv, s.bzv
    s.xv, s.yv, s.zv = s.pxv - s.txv, s.pyv - s.tyv, s.pzv - s.tzv
    s.vd, s.va, s.vi = spherical(s.xv, s.yv, s.zv)
    s.vd2 = dist2d([s.xv, s.yv])
コード例 #2
0
ファイル: PhysicsEnv.py プロジェクト: sabakipants/honte
 def build(self):
     # Build 'points' list.
     self.ob_x, self.ob_y = self.x, self.y
     self.ob_right, self.ob_top = self.right, self.top
     # Build 'normals' list.
     self.n1x, self.n1y = PhysicsLib.getPtNorm(self.p4, self.p1, self.p2)
     self.n2x, self.n2y = PhysicsLib.getPtNorm(self.p1, self.p2, self.p3)
     self.n3x, self.n3y = PhysicsLib.getPtNorm(self.p2, self.p3, self.p4)
     self.n4x, self.n4y = PhysicsLib.getPtNorm(self.p3, self.p4, self.p1)
コード例 #3
0
ファイル: Strategy.py プロジェクト: robbai/RLBotPack
def GatherInfo(s):
    """Gather necessary info"""

    min_speed = 1400 if s.pB > 30 else 999
    min_speed = ((2300 - s.pvd) + dist3d(s.pV, s.bV)) * abs(s.ba) * 2 + 100

    # Opponent info

    s.obd = dist3d(s.oL, s.bL)

    iState = PhysicsLib.intercept2(s.bL, s.bV, s.baV, s.oL, s.oV,
                                   s.obd / min_speed, 30)

    s.otL = a3(iState.Ball.Location)
    s.otV = a3(iState.Ball.Velocity)
    s.ofL = a3(iState.Car.Location)
    s.odT = iState.dt

    s.ofd = dist3d(s.otL, s.ofL)

    s.ooglinex = line_intersect(
        ([0, -Ph.wy * s.color], [1, -Ph.wy * s.color]),
        (s.ofL * .8 + .2 * s.oL, s.otL * .8 + .2 * s.bL))[0]

    # s.ooglinez = line_intersect(([0, -Ph.wy * s.color], [1, -Ph.wy * s.color]),
    #                             ([s.ofL[2], s.ofL[1]], [s.otL[2], s.otL[1]]))[0]

    # s.obd = dist3d(s.oL, s.bL)
    s.obfd = dist3d(s.ofL, s.otL)

    # player info

    s.prd = turning_radius(s.pvd)

    iState = PhysicsLib.intercept2(s.bL, s.bV, s.baV, s.pL, s.pV,
                                   s.bd / min_speed, 60)

    s.ptL = a3(iState.Ball.Location)
    s.ptV = a3(iState.Ball.Velocity)
    s.ptaV = a3(iState.Ball.AngularVelocity)
    s.pfL = a3(iState.Car.Location)
    s.pfV = a3(iState.Car.Velocity)
    s.pdT = iState.dt

    s.glinex = line_intersect(
        ([0, Ph.wy * s.color], [1, Ph.wy * s.color]),
        (s.pfL * .5 + .5 * s.pL, s.ptL * .8 + .2 * s.bL))[0]

    # s.glinez = line_intersect(([0, Ph.wy * s.color], [1, Ph.wy * s.color]),
    #                           ([s.pL[2], s.pL[1]], [s.ptL[2], s.ptL[1]]))[0]

    s.oglinex = line_intersect(
        ([0, -Ph.wy * s.color], [1, -Ph.wy * s.color]),
        (s.pfL * .8 + .2 * s.pL, s.ptL * .8 + .2 * s.bL))[0]

    # s.oglinez = line_intersect(([0, -Ph.wy * s.color], [1, -Ph.wy * s.color]),
    #                            ([s.pfL[2], s.pL[1]], [s.pftL[2], s.ptL[1]]))[0]

    s.bfd = dist3d(s.pfL, s.ptL)

    # goal location related

    s.goal = a3([
        -Range(s.glinex, 600) / 2,
        max(Ph.wy,
            abs(s.ptL[1]) + 1) * s.color, 300
    ])

    s.ogoal = a3([
        Range(s.ooglinex * .8, 900), -max(Ph.wy,
                                          abs(s.ptL[1]) + 1) * s.color, 300
    ])

    s.gaimdx = abs(s.goal[0] - s.glinex)
    # s.gaimdz = abs(s.goal[2] - s.glinez)

    # s.gx, s.gy, s.gz = local(s.goal, s.pL, s.pR)
    # s.gd, s.ga, s.gi = spherical(s.gx, s.gy, s.gz)

    # s.ogx, s.ogy, s.ogz = local(s.ogoal, s.pL, s.pR)
    # s.ogd, s.oga, s.ogi = spherical(s.ogx, s.ogy, s.ogz)

    s.gtL = s.ptL - s.goal
    s.gpL = s.pL - s.goal

    s.gtd, s.gta, s.gti = spherical(*s.gtL, 0)
    s.gpd, s.gpa, s.gpi = spherical(*s.gpL, 0)

    s.gtd = dist3d(s.goal, s.ptL)
    s.gpd = dist3d(s.goal, s.pL)
    s.ogtd = dist3d(s.ogoal, s.ptL)
    s.ogpd = dist3d(s.ogoal, s.pL)

    # near_post = (gx / 2 * sign(s.bL[0]), s.goal[1])
    # tangent = tangent_point(near_post, R, s.bL, s.color * sign(s.bL[0]))

    # s.x_point = line_intersect([(1, near_post[1]), (-1, near_post[1])], [s.bL, tangent])[0]

    # States

    s.aerialing = not s.poG and s.pL[2] > 150 and s.airtime > .25
    s.kickoff = not s.bH and dist3d(s.bL) < 99
    s.behind = s.gpd < s.gtd or s.ogpd > s.ogtd
    s.offense = s.ogtd + 70 > s.ogpd

    # Other
    s.tLb = set_dist(s.ptL, s.goal, -92)
コード例 #4
0
ファイル: Strategy.py プロジェクト: robbai/RLBotPack
def ChaseBallBias(s):

    s.tL, s.tV, s.taV, s.dT = s.ptL, s.ptV, s.ptaV, s.pdT

    dt = s.bfd / 8300
    tPath = PhysicsLib.predictPath(s.ptL, s.ptV, s.ptaV, dt + 1 / 60, 60)
    tState = tPath.ballstates[min(tPath.numstates - 1, 0)]
    s.tL = a3(tState.Location)
    s.tV = a3(tState.Velocity)
    s.pfL, s.pfV = PhysicsLib.CarStep(s.pfL, s.pfV, dt)
    s.dT += dt

    if s.tL[1] * s.color < -Ph.wy - 80:
        s.tL[1] = -Ph.wy * s.color - 80

    s.fx, s.fy, s.fz = local(s.tL, s.pfL, s.pR)
    s.fd, s.fa, s.fi = spherical(s.fx, s.fy, s.fz)
    s.fd2 = dist2d([s.fx, s.fy])
    s.fgd2 = dist2d(s.pfL, s.tL)

    s.tLb2 = s.tLb
    s.r = s.pR[2] / U180

    s.Cl = Ph.Collision_Model(s.pfL)
    if s.Cl.hasCollided:
        # landing on any surface
        # lt = Ph.local_space(s.tLb2, s.Cl.Location, s.Cl.Rotation)
        # lp = Ph.local_space(s.pL, s.Cl.Location, s.Cl.Rotation)
        # lt[2] = (93 + lp[2]) / 2
        # s.tLb2 = Ph.global_space(lt, s.Cl.Location, s.Cl.Rotation)
        # sUP = Ph.global_space(UP, 0, s.Cl.Rotation)
        # sRI = Ph.global_space(RI, 0, s.Cl.Rotation)
        # pUP = world(UP, 0, s.pR)
        # s.r = math.atan2(np.dot(sRI, pUP), np.dot(sUP, pUP)) / PI
        pass
    elif s.aerialing:
        n1 = normalize(s.tL - s.pL)
        v1 = s.pV
        b1 = v1 - np.dot(v1, n1) * n1
        d = (s.bd * 5 + .5 * dist3d(s.pL, s.tL))
        v = max(s.pvd * .5 + .5 * dist3d(s.pfV), 200)
        t = d / v
        s.tLb2 = s.tLb - b1 * t
    else:
        s.tLb2 = (s.pV + s.tLb2) / 2

    s.x, s.y, s.z = local(s.tLb2, s.pL, s.pR)
    s.d, s.a, s.i = spherical(s.x, s.y, s.z)
    s.d2 = dist2d([s.x, s.y])

    s.dspeed = 2310
    s.forwards = 1

    goal = s.goal if not s.behind else set_dist(s.tL, s.ogoal, -999)

    s.tLs = aimBias(s, goal) if s.pL[2] < 50 or not s.poG else s.tLb

    if s.pL[2] > 20 and s.poG and (s.tL[2] < s.z or s.z > 450 + s.pB * 9):
        s.tLs[2] = 50

    s.sx, s.sy, s.sz = local(s.tLs, s.pL, s.pR)
    s.sd, s.sa, s.si = spherical(s.sx, s.sy + 50, s.sz)

    s.txv, s.tyv, s.tzv = s.bxv, s.byv, s.bzv
    s.xv, s.yv, s.zv = s.pxv - s.txv, s.pyv - s.tyv, s.pzv - s.tzv
    s.vd, s.va, s.vi = spherical(s.xv, s.yv, s.zv)
    s.vd2 = dist2d([s.xv, s.yv])

    s.shoot = True
コード例 #5
0
ファイル: PhysicsEnv.py プロジェクト: sabakipants/honte
    def move(self, obstacle):

        self.windowCol()

        # Perform 'pointCol()' on each point from 'obstacle'.
        for i, p in enumerate(obstacle.points):
            cx, cy, cr = self.center[0], self.center[1], self.size[0] / 2
            if PhysicsLib.pointCol(cx, cy, cr, p[0], p[1]):
                # If collision is detected...

                for l in obstacle.legs[i]:
                    lp1, lp2 = l
                    lp1x, lp1y = lp1
                    lp2x, lp2y = lp2
                    if PhysicsLib.edgeProj(cx, cy, lp1x, lp1y, lp2x, lp2y):
                        """ perform 'edgeCol()' on 'l' """
                        vel_ang = (Vector(1, 0).angle(Vector(self.velocity)))                       # NEED TO WRITE PHYSICS FUNCTION FOR BLOCK...
                        # if vel_ang < 0:  vel_ang = abs(vel_ang) + 180                             #
                        print("vel_ang", vel_ang)                                                   #
                        edge_ang = (Vector(1, 0).angle(Vector(lp2) - Vector(lp1)))                  #
                        print("edge_ang", edge_ang)                                                 #
                        # dif = (Vector(p2) - Vector(p)).angle(Vector(self.velocity))               #
                        dif = (edge_ang - vel_ang)                                                  #
                        print("dif", dif)                                                           #
                        # dif = edge_ang - vel_ang                                                  #
                        refl = dif * 2                                                              #
                        if dif < 0:  self.velocity = Vector(self.velocity).rotate(-refl)            #
                        else:  self.velocity = Vector(self.velocity).rotate(refl)                   # ...

                        return

                # Get angle from origin 'ball.center' and points 'ball.velocity' and point          # NEED TO WRITE PHYSICS FUNCTION FOR BLOCK...
                # collided with.                                                                    #
                dif = (Vector(p) - Vector(self.center)).angle(Vector(self.velocity))                #
                # Get angle of reflection point.  It is the angle to be added to current velocity   #
                # angle to get new trajectory.                                                      #
                refl = (90 - abs(dif)) * 2                                                          #
                # Handle two possible scenarios differently:  If angle from collision point to      #
                # velocity is negative, then reflection is positive.  If angle from collision point #
                # to velocity is positive, then reflection is negative.                             #
                if dif < 0:  self.velocity = Vector(self.velocity).rotate(refl)                     #
                else:  self.velocity = Vector(self.velocity).rotate(-refl)                          # ...

                return  # New velocity determined.  Proceed to next frame.

        for i, e in enumerate(obstacle.edges):
            cx, cy, cr = self.center[0], self.center[1], self.size[0] / 2
            p1, p2 = e
            p1x, p1y = p1
            p2x, p2y = p2

            if PhysicsLib.edgeCol(cx, cy, cr, p1x, p1y, p2x, p2y):
                vel_ang = (Vector(1, 0).angle(Vector(self.velocity)))                               # NEED TO WRITE PHYSICS FUNCTION FOR BLOCK...
                # if vel_ang < 0:  vel_ang = abs(vel_ang) + 180                                     #
                print("vel_ang", vel_ang)                                                           #
                edge_ang = (Vector(1, 0).angle(Vector(p2) - Vector(p1)))                            #
                print("edge_ang", edge_ang)                                                         #
                # dif = (Vector(p2) - Vector(p)).angle(Vector(self.velocity))                       #
                dif = (edge_ang - vel_ang)                                                          #
                print("dif", dif)                                                                   #
                # dif = edge_ang - vel_ang                                                          #
                refl = dif * 2                                                                      #
                if dif < 0:  self.velocity = Vector(self.velocity).rotate(-refl)                    #
                else:  self.velocity = Vector(self.velocity).rotate(refl)                           # ...

                return
コード例 #6
0
def GatherInfo(s):
    """Gather necessary info"""

    min_speed = 1400 if s.pB > 30 else 999
    min_speed = ((2300 - s.pvd) + dist3d(s.pV, s.bV)) * abs(s.ba) * 2 + 100

    # Opponent info

    iState = PhysicsLib.intercept2(s.bL, s.bV, s.baV, s.oL, s.oV, s.obd / min_speed, 30, g=s.G)

    s.otL = a3(iState.Ball.Location)
    s.otV = a3(iState.Ball.Velocity)
    s.ofL = a3(iState.Car.Location)
    s.odT = iState.dt

    s.ofd = dist3d(s.otL, s.ofL)
    s.odT += s.ofd / (dist3d(s.oV) * 0.5 + 0.5 * 2300)
    s.otL[1] = Range(s.otL[1], abs(s.ogoal[1]))

    s.ooglinex = line_intersect(([0, s.ogoal[1]], [1, s.ogoal[1]]), (s.ofL * .5 + .5 * s.oL, s.otL))[0]

    # s.obd = dist3d(s.oL, s.bL)
    s.obfd = dist3d(s.ofL, s.otL)

    # player info

    s.prd = turning_radius(s.pvd)

    iState = PhysicsLib.intercept2(s.bL, s.bV, s.baV, s.pL, s.pV, s.bd / min_speed, 60, g=s.G)

    s.ptL = a3(iState.Ball.Location)
    s.ptV = a3(iState.Ball.Velocity)
    s.ptaV = a3(iState.Ball.AngularVelocity)
    s.pfL = a3(iState.Car.Location)
    s.pfV = a3(iState.Car.Velocity)
    s.pdT = iState.dt

    s.pfd = dist3d(s.pfL, s.ptL)
    s.pdT += s.pfd / (s.pvd * 0.5 + 0.5 * 2300)
    s.otL[1] = Range(s.ptL[1], abs(s.ogoal[1]))

    s.glinex = line_intersect(([0, s.goal[1]], [1, s.goal[1]]), (s.pL, s.ptL))[0]

    s.oglinex = line_intersect(([0, s.ogoal[1]], [1, s.ogoal[1]]), (s.pL, s.ptL))[0]

    s.obglinex = line_intersect(([0, s.ogoal[1]], [1, s.ogoal[1]]),
                                ([s.bL[0], s.bL[1]], [s.bL[0] + s.bV[0], s.bL[1] + s.bV[1]]))[0]

    # goal location related

    s.gaimdx = abs(s.goal[0] - s.glinex)

    s.gtL = s.ptL - s.goal
    s.gpL = s.pL - s.goal

    s.gtd, s.gta, s.gti = spherical(*s.gtL, 0)
    s.gpd, s.gpa, s.gpi = spherical(*s.gpL, 0)

    s.gtd = dist3d(s.goal, s.ptL)
    s.gpd = dist3d(s.goal, s.pL)
    s.ogtd = dist3d(s.ogoal, s.ptL)
    s.ogpd = dist3d(s.ogoal, s.pL)

    s.o_gtd = dist3d(s.ogoal, s.otL)
    s.o_gpd = dist3d(s.ogoal, s.oL)
    s.o_ogtd = dist3d(s.goal, s.otL)
    s.o_ogpd = dist3d(s.goal, s.oL)

    # TODO: shot angle possible

    # game state info

    s.aerialing = not s.poG and (s.airtime > .2 and s.pL[2] + s.pV[2] / 2 > 150 or s.jumper)
    s.behind = s.gpd < s.gtd or s.ogpd > s.ogtd
    s.offense = s.gpd > s.gtd or dist3d(s.ptL, s.goal) < 3500
    s.infront = s.ptL[1] * s.color + 90 > s.pL[1] * s.color

    s.obehind = s.o_gpd < s.o_gtd or s.o_ogpd > s.o_ogtd

    s.kickoff = not s.bH and dist3d(s.bL) < 99
コード例 #7
0
ファイル: Strategy.py プロジェクト: robbai/RLBotPack
def GatherInfo(s):
    """Gather necessary info"""

    min_speed = 800

    # player info

    s.prd = turning_radius(s.pvd)

    iState = PhysicsLib.intercept2(s.bL, s.bV, s.baV, s.pL, s.pV,
                                   s.bd / min_speed, 60)

    s.ptL = a3(iState.Ball.Location)
    s.ptV = a3(iState.Ball.Velocity)
    s.ptaV = a3(iState.Ball.AngularVelocity)
    s.pfL = a3(iState.Car.Location)
    s.pfV = a3(iState.Car.Velocity)
    s.pdT = iState.dt

    s.bfd = dist3d(s.pfL, s.ptL)

    s.glinex = line_intersect(([0, Ph.wy * s.color], [1, Ph.wy * s.color]),
                              ([s.pL[0], s.pL[1]], [s.ptL[0], s.ptL[1]]))[0]

    s.glinez = line_intersect(([0, Ph.wy * s.color], [1, Ph.wy * s.color]),
                              ([s.pL[2], s.pL[1]], [s.ptL[2], s.ptL[1]]))[0]

    s.oglinex = line_intersect(([0, -Ph.wy * s.color], [1, -Ph.wy * s.color]),
                               ([s.pL[0], s.pL[1]], [s.ptL[0], s.ptL[1]]))[0]

    # s.oglinez = line_intersect(([0, -Ph.wy * s.color], [1, -Ph.wy * s.color]),
    #                            ([s.pL[2], s.pL[1]], [s.ptL[2], s.ptL[1]]))[0]

    # Opponent info

    s.obd = dist3d(s.oL, s.bL)

    iState = PhysicsLib.intercept2(s.bL, s.bV, s.baV, s.oL, s.oV,
                                   s.obd / min_speed, 30)

    s.otL = a3(iState.Ball.Location)
    s.otV = a3(iState.Ball.Velocity)
    s.ofL = a3(iState.Car.Location)
    s.odT = iState.dt

    s.ofd = dist3d(s.otL, s.ofL)

    # s.obd = dist3d(s.oL, s.bL)
    s.obfd = dist3d(s.ofL, s.otL)

    s.ooglinex = line_intersect(([0, -Ph.wy * s.color], [1, -Ph.wy * s.color]),
                                ([s.oL[0], s.oL[1]], [s.otL[0], s.otL[1]]))[0]

    s.ooglinez = line_intersect(([0, -Ph.wy * s.color], [1, -Ph.wy * s.color]),
                                ([s.oL[2], s.oL[1]], [s.otL[2], s.otL[1]]))[0]

    # other

    s.goal = a3([
        -Range(s.glinex, 600) / 2,
        max(Ph.wy,
            abs(s.ptL[1]) + 1) * s.color, 300
    ])

    s.ogoal = a3([
        Range(s.ooglinex * .8, 900), -max(Ph.wy,
                                          abs(s.ptL[1]) + 1) * s.color, 300
    ])

    s.gaimdx = abs(s.goal[0] - s.glinex)
    s.gaimdz = abs(s.goal[2] - s.glinez)

    s.gx, s.gy, s.gz = local(s.goal, s.pL, s.pR)
    s.gd, s.ga, s.gi = spherical(s.gx, s.gy, s.gz)

    s.ogx, s.ogy, s.ogz = local(s.ogoal, s.pL, s.pR)
    s.ogd, s.oga, s.ogi = spherical(s.ogx, s.ogy, s.ogz)

    s.gtL = s.ptL - s.goal
    s.gpL = s.pL - s.goal

    s.gtd, s.gta, s.gti = spherical(*s.gtL, 0)
    s.gpd, s.gpa, s.gpi = spherical(*s.gpL, 0)

    s.gtd = dist3d(s.goal, s.ptL)
    s.gpd = dist3d(s.goal, s.pL)
    s.ogtd = dist3d(s.ogoal, s.ptL)
    s.ogpd = dist3d(s.ogoal, s.pL)

    # States

    s.aerialing = not s.poG and s.pL[2] > 150 and s.airtime > .25
    s.kickoff = not s.bH and dist3d(s.bL) < 99
    s.offense = s.ogtd + 70 > s.ogpd
    s.behind = s.gpd < s.gtd or s.ogpd > s.ogtd