Пример #1
0
    def execute(self, state, pub):
        #bot_list = [self.bot_id, self.bot_id]
        print "BALL_POS : ", state.ballPos.x, ",", state.ballPos.y
        ballPos = Vector2D(int(state.ballPos.x), int(state.ballPos.y))
        botPos = Vector2D(int(state.homePos[self.bot_id].x),
                          int(state.homePos[self.bot_id].y))
        ballVel = Vector2D(int(state.ballVel.x), int(state.ballVel.y))
        distance = botPos.dist(ballPos)
        attacker_id = state.opp_bot_closest_to_ball
        attacker_pos = Vector2D(int(state.awayPos[attacker_id].x),
                                int(state.awayPos[attacker_id].y))
        gameState = self.getState(state)

        if gameState == TGoalie.State.block:
            print("ATTACKER_HAS_THE_BALL")
            self.sParams.GoToPointP.x = -HALF_FIELD_MAXX + 2 * BOT_RADIUS
            if (ballPos.x - attacker_pos.x) != 0:
                y = ballPos.y + (ballPos.y - attacker_pos.y) * abs(
                    (-HALF_FIELD_MAXX + 2 * BOT_RADIUS - ballPos.x) /
                    (ballPos.x - attacker_pos.x))
            else:
                y = ballPos.y
            y = min(y, OUR_GOAL_MAXY - BOT_RADIUS)
            y = max(y, OUR_GOAL_MINY + BOT_RADIUS)
            self.sParams.GoToPointP.y = y
            finalPos = Vector2D(self.sParams.GoToPointP.x,
                                self.sParams.GoToPointP.y)
            self.sParams.GoToPointP.finalSlope = ballPos.angle(finalPos)
            sGoalie.execute(self.sParams, state, self.bot_id, pub)
        elif gameState == TGoalie.State.intercept:
            print("___BALL_APPROACHING______")
            self.sParams.GoToPointP.x = -HALF_FIELD_MAXX + 2 * BOT_RADIUS
            y = ballPos.y + ballVel.y * abs(
                (-HALF_FIELD_MAXX + 2 * BOT_RADIUS - ballPos.x) / ballVel.x)
            y = min(y, OUR_GOAL_MAXY - BOT_RADIUS)
            y = max(y, OUR_GOAL_MINY + BOT_RADIUS)
            self.sParams.GoToPointP.y = y
            finalPos = Vector2D(self.sParams.GoToPointP.x,
                                self.sParams.GoToPointP.y)
            self.sParams.GoToPointP.finalSlope = ballPos.angle(finalPos)
            sGoalie.execute(self.sParams, state, self.bot_id, pub)
        elif gameState == TGoalie.State.chill:
            print("___BALL_NOT_APPROACHING______")
            self.sParams.GoToPointP.x = -HALF_FIELD_MAXX + 2 * BOT_RADIUS
            y = ballPos.y
            y = min(y, OUR_GOAL_MAXY - BOT_RADIUS)
            y = max(y, OUR_GOAL_MINY + BOT_RADIUS)
            self.sParams.GoToPointP.y = y
            self.sParams.GoToPointP.finalSlope = ballPos.angle(botPos) + pi
            sGoalie.execute(self.sParams, state, self.bot_id, pub)
        elif gameState == TGoalie.State.clear:
            print(" ___CLEAR_THE_BALL________")
            # TO DO decide the point where the ball is to be kicked
            self.sParams.KickToPointP.x = 0
            self.sParams.KickToPointP.y = 0
            self.sParams.KickToPointP.power = 7
            sKickToPoint.execute(self.sParams, state, self.bot_id, pub)
        else:
            print("___REFREE_PLAY__________")
Пример #2
0
 def execute(self, state, pub, reciever_bot_id=[-1]):
     ballPos = Vector2D(state.ballPos.x, state.ballPos.y)
     botPos = Vector2D(state.homePos[self.bot_id].x,
                       state.homePos[self.bot_id].y)
     params = Vector2D(4500, 0)
     self.sParams.GoToPointP.x = params.x
     self.sParams.GoToPointP.y = params.y
     sKickToPoint.execute(self.sParams, state, self.bot_id, pub)
    def execute(self, state, pub):
        print "BALL_POS : ", state.ballPos.x, ",", state.ballPos.y
        ballPos = Vector2D(int(state.ballPos.x), int(state.ballPos.y))
        botPos = Vector2D(int(state.homePos[self.bot_id].x),
                          int(state.homePos[self.bot_id].y))
        ballVel = Vector2D(int(state.ballVel.x), int(state.ballVel.y))
        gameState = self.getState(state)
        global k1
        global k2

        if gameState == TDumbattacker.State.shoot:
            if not (state.ballPos.x < -HALF_FIELD_MAXX + DBOX_WIDTH):
                if fabs(
                        ballPos.dist(
                            Vector2D(int(state.homePos[self.bot_id].x),
                                     int(state.homePos[self.bot_id].y))) >
                        BOT_BALL_THRESH):
                    sGoToBall.execute(self.sParams, state, self.bot_id, pub)
            else:
                return

            if k1 and not k2:
                self.sParams.KickToPointP.x = HALF_FIELD_MAXX
                self.sParams.KickToPointP.y = 0.8 * OUR_GOAL_MINY
                self.sParams.KickToPointP.power = 10
                sKickToPoint.execute(self.sParams, state, self.bot_id, pub)
            else:
                self.sParams.KickToPointP.x = HALF_FIELD_MAXX
                self.sParams.KickToPointP.y = 0.8 * OUR_GOAL_MAXY
                self.sParams.KickToPointP.power = 10
                sKickToPoint.execute(self.sParams, state, self.bot_id, pub)

        if gameState == TDumbattacker.State.cross_pass:
            self.sParams.KickToPointP.x = state.homePos[self.receive_bot_id].x
            self.sParams.KickToPointP.y = state.homePos[self.receive_bot_id].y
            self.sParams.KickToPointP.power = 7
            sKickToPoint.execute(self.sParams, state, self.bot_id, pub)

        if gameState == TDumbattacker.State.cross_receive:
            self.SParams.sTurnToPoint.x = state.homePos[self.passer_bot_id].x
            self.SParams.sTurnToPoint.y = state.homePos[self.passer_bot_id].y
            self.SParams.sTurnToPoint.max_omega = MAX_BOT_OMEGA
            sTurnToPoint.execute(self.sParams, state, self.bot_id, pub)

        if gameState == TDumbattacker.State.optimum_pos:
            if state.homePos[self.passer_bot_id].y > 0:
                if state.homePos[self.bot_id].x < state.homePos[
                        self.passer_bot_id].x:
                    self.SParams.sGoToPoint.y = OUR_GOAL_MAXY * 1.5
                    self.SParams.sGoToPoint.x = state.homePos[
                        self.passer_bot_id].x + 100
                    self.SParams.sGoToPoint.finalSlope = -State.homePos[
                        self.bot_id].angle(State.homePos[self.passer_bot_id])
                    self.SParams.sGoToPoint.align = False
                    self.SParams.sGoToPoint.finalVelocity = 0
                    sGoToPoint.execute(self.sParams, state, self.bot_id, pub)
                else:
                    self.SParams.sGoToPoint.y = OUR_GOAL_MAXY * 1.5
                    self.SParams.sGoToPoint.x = self.SParams.sGoToPoint.x + 75
                    self.SParams.sGoToPoint.finalSlope = -State.homePos[
                        self.bot_id].angle(State.homePos[self.passer_bot_id])
                    self.SParams.sGoToPoint.align = False
                    self.SParams.sGoToPoint.finalVelocity = 0
            else:
                if state.homePos[self.bot_id].x < state.homePos[
                        self.passer_bot_id].x:
                    self.SParams.sGoToPoint.y = OUR_GOAL_MINY * 1.5
                    self.SParams.sGoToPoint.x = state.homePos[
                        self.passer_bot_id].x + 100
                    self.SParams.sGoToPoint.finalSlope = -State.homePos[
                        self.bot_id].angle(State.homePos[self.passer_bot_id])
                    self.SParams.sGoToPoint.align = False
                    self.SParams.sGoToPoint.finalVelocity = 0
                    sGoToPoint.execute(self.sParams, state, self.bot_id, pub)
                else:
                    self.SParams.sGoToPoint.y = OUR_GOAL_MINY * 1.5
                    self.SParams.sGoToPoint.x = self.SParams.sGoToPoint.x + 75
                    self.SParams.sGoToPoint.finalSlope = -State.homePos[
                        self.bot_id].angle(State.homePos[self.passer_bot_id])
                    self.SParams.sGoToPoint.align = False
                    self.SParams.sGoToPoint.finalVelocity = 0
Пример #4
0
    def execute(self, state , pub):
        #bot_list = [self.bot_id, self.bot_id]
        print "BALL_POS : ",state.ballPos.x,",",state.ballPos.y
        ballPos = Vector2D(int(state.ballPos.x), int(state.ballPos.y))
        botPos = Vector2D(int(state.homePos[self.bot_id].x), int(state.homePos[self.bot_id].y))
        ballVel = Vector2D(int(state.ballVel.x) , int(state.ballVel.y))
        distance = botPos.dist(ballPos)
        attacker_id = state.opp_bot_closest_to_ball
        attacker_pos = Vector2D (int(state.awayPos[attacker_id].x),int(state.awayPos[attacker_id].y))
        gameState = self.getState(state)

        # self.sParams.GoToPointP.x = ballPos.x
        # self.sParams.GoToPointP.y = ballPos.y
        # sGoToPoint.execute(self.sParams, state, self.bot_id, pub)
        # return

        if gameState == TLDefender.State.block:
            print ("ATTACKER_HAS_THE_BALL")
            self.sParams.GoToPointP.x = -HALF_FIELD_MAXX+DBOX_WIDTH+BOT_RADIUS
            if (ballPos.x-attacker_pos.x) != 0 :
                y = ballPos.y + (ballPos.y-attacker_pos.y)*abs((-HALF_FIELD_MAXX+2*BOT_RADIUS-ballPos.x)/(ballPos.x-attacker_pos.x))
            else :
                y = ballPos.y
            y = min(y,OUR_GOAL_MAXY - BOT_RADIUS)
            y = max(y,OUR_GOAL_MINY + BOT_RADIUS)
            if y - OUR_GOAL_MINY <= 2*BOT_RADIUS :
                y = y + 4.4*BOT_RADIUS
            elif OUR_GOAL_MAXY - y <= 2*BOT_RADIUS :
                y = y - 1.7*BOT_RADIUS
            else :
                y = y + 2.4*BOT_RADIUS
            self.sParams.GoToPointP.y = y
            finalPos = Vector2D(self.sParams.GoToPointP.x,self.sParams.GoToPointP.y)
            self.sParams.GoToPointP.finalSlope = ballPos.angle(finalPos)
            if finalPos.dist(state.homePos[self.bot_id]) <= BOT_BALL_THRESH :
                print (" TURN TOWARDS BALL")
                self.sParams.TurnToPointP.x = ballPos.x
                self.sParams.TurnToPointP.y = ballPos.y
                self.sParams.TurnToPointP.max_omega = MAX_BOT_OMEGA
                sTurnToPoint.execute(self.sParams,state,self.bot_id,pub)
            else :
                print (" GET POSITIONED ")
                sGoToPoint.execute(self.sParams, state, self.bot_id, pub)
        elif gameState == TLDefender.State.intercept:
            print ("___BALL_APPROACHING______")
            self.sParams.GoToPointP.x = -HALF_FIELD_MAXX+DBOX_WIDTH+BOT_RADIUS
            y = ballPos.y + ballVel.y*abs((-HALF_FIELD_MAXX+2*BOT_RADIUS-ballPos.x)/ballVel.x)
            y = min(y,OUR_GOAL_MAXY - BOT_RADIUS)
            y = max(y,OUR_GOAL_MINY + BOT_RADIUS)
            if y - OUR_GOAL_MINY <= 2*BOT_RADIUS :
                y = y + 4.4*BOT_RADIUS
            elif OUR_GOAL_MAXY - y <= 2*BOT_RADIUS :
                y = y - 1.7*BOT_RADIUS
            else :
                y = y + 2.4*BOT_RADIUS
            self.sParams.GoToPointP.y = y
            finalPos = Vector2D(self.sParams.GoToPointP.x,self.sParams.GoToPointP.y)
            self.sParams.GoToPointP.finalSlope = ballPos.angle(finalPos)
            if distance <= DRIBBLER_BALL_THRESH and ballPos.y < 0:
                self.sParams.KickToPointP.x = 0  # TO DO decide the point to clear the ball
                self.sParams.KickToPointP.y = 0
                self.sParams.KickToPointP.power = 7
                sKickToPoint.execute(self.sParams,state,self.bot_id,pub, True)
            else :
                sGoToPoint.execute(self.sParams, state, self.bot_id, pub)
        elif gameState == TLDefender.State.chill :
            print ("___BALL_NOT_APPROACHING______")
            pointL,pointR = self.getPoints(state)
            self.sParams.GoToPointP.x = pointL.x
            self.sParams.GoToPointP.y = pointL.y
            finalPos = pointL
            self.sParams.GoToPointP.finalSlope = ballPos.angle(finalPos)
            print(finalPos.x,finalPos.y)
            if distance <= DRIBBLER_BALL_THRESH and ballPos.y > 0:
                print ("KICK TO POINT")
                self.sParams.KickToPointP.x = 0  # TO DO decide the point to clear the ball
                self.sParams.KickToPointP.y = 0
                self.sParams.KickToPointP.power = 7
                sKickToPoint.execute(self.sParams,state,self.bot_id,pub)
            else :
                if finalPos.dist(state.homePos[self.bot_id]) <= BOT_BALL_THRESH :
                    print (" TURN TOWARDS BALL")
                    self.sParams.TurnToPointP.x = ballPos.x
                    self.sParams.TurnToPointP.y = ballPos.y
                    self.sParams.TurnToPointP.max_omega = MAX_BOT_OMEGA
                    sTurnToPoint.execute(self.sParams,state,self.bot_id,pub)
                else :
                    print (" GET POSITIONED ")
                    sGoToPoint.execute(self.sParams, state, self.bot_id, pub)
        elif gameState == TLDefender.State.clear_block:
            print (" ___CLEAR_THE_BALL________")
            sStop.execute(self.sParams,state,self.bot_id,pub)
            # TO DO decide the opponent to block
        else :
            print ("___REFREE_PLAY__________")
Пример #5
0
    def execute(self, state, pub):
        ballPos = Vector2D(int(state.ballPos.x), int(state.ballPos.y))
        botPos = Vector2D(int(state.homePos[self.bot_id].x),
                          int(state.homePos[self.bot_id].y))
        ballVel = Vector2D(int(state.ballVel.x), int(state.ballVel.y))
        gameState = self.getState(state)
        global k1, k2

        if gameState == TAttacker.State.shoot:
            # if fabs(ballPos.dist(botPos)>BOT_BALL_THRESH/400):
            #     sGoToBall.execute(self.sParams, state, self.bot_id, pub)
            # #fuzzy logic to find best angle
            # #print "shoot_State"
            if k1 and not k2:
                self.sParams.KickToPointP.x = HALF_FIELD_MAXX
                self.sParams.KickToPointP.y = 0.8 * OUR_GOAL_MINY
                self.sParams.KickToPointP.power = 7
                sKickToPoint.execute(self.sParams, state, self.bot_id, pub)
                #print "shot"
            elif k2 and not k1:
                self.sParams.KickToPointP.x = HALF_FIELD_MAXX
                self.sParams.KickToPointP.y = 0.8 * OUR_GOAL_MAXY
                self.sParams.KickToPointP.power = 7
                sKickToPoint.execute(self.sParams, state, self.bot_id, pub)
                #print "shot"
            else:
                if state.awayPos[4].y < 0:
                    self.sParams.KickToPointP.x = HALF_FIELD_MAXX
                    self.sParams.KickToPointP.y = 0.8 * OUR_GOAL_MAXY
                    self.sParams.KickToPointP.power = 7
                    sKickToPoint.execute(self.sParams, state, self.bot_id, pub)
                    #print "shot"
                if state.awayPos[4].y > 0:
                    self.sParams.KickToPointP.x = HALF_FIELD_MAXX
                    self.sParams.KickToPointP.y = 0.8 * OUR_GOAL_MINY
                    self.sParams.KickToPointP.power = 7
                    sKickToPoint.execute(self.sParams, state, self.bot_id, pub)
                    #print "shot"

        if gameState == TAttacker.State.cross_pass:
            # if fabs(ballPos.dist(botPos)>BOT_BALL_THRESH/4):
            # 	sGoToBall.execute(self.sParams, state, self.bot_id, pub)
            print "pass_state"
            p = get_all(state, self.bot_id)
            self.receive_bot_id = p[0]
            print "receiver =", p[0]
            self.sParams.KickToPointP.x = state.homePos[self.receive_bot_id].x
            self.sParams.KickToPointP.y = state.homePos[self.receive_bot_id].y
            self.sParams.KickToPointP.power = 7
            sKickToPoint.execute(self.sParams, state, self.bot_id, pub)

        if gameState == TAttacker.State.cross_receive:
            mindist = 9999999
            print "recieve_state"
            for our_bot in xrange(len(state.homePos)):
                if state.homePos[our_bot].x > state.homePos[bots].x:
                    curr_home_bot = Vector2D(int(state.homePos[our_bot].x),
                                             int(state.homePos[our_bot].y))
                    # #print'Bot id: {}, Pos {},{}'.format(our_bot,curr_opp_bot.x, curr_opp_bot.y)
                    dist_bot = ballPos.dist(curr_home_bot)
                    # #print our_bot , " " ,mindist , " " , dist_bot
                    # #print int(state.homePos[our_bot].x)," " ,int(state.homePos[our_bot].y)
                    if dist_bot < mindist:

                        mindist = dist_bot
                        closest_home_bot = our_bot
            passer_bot_id = closest_home_bot
            self.SParams.sTurnToPoint.x = state.homePos[self.passer_bot_id].x
            self.SParams.sTurnToPoint.y = state.homePos[self.passer_bot_id].y
            self.SParams.sTurnToPoint.max_omega = MAX_BOT_OMEGA
Пример #6
0
    def execute(self, state, pub, receiver_bot_id=[-1]):
        ballPos = Vector2D(int(state.ballPos.x), int(state.ballPos.y))
        DistancesFromBot = inf

        if not (state.ballPos.x < -HALF_FIELD_MAXX + DBOX_WIDTH
                and fabs(state.ballPos.y) < OUR_GOAL_MAXY * 0.8):
            # print(ballPos.x,ballPos.y)
            if fabs(
                    ballPos.dist(
                        Vector2D(int(state.homePos[self.bot_id].x),
                                 int(state.homePos[self.bot_id].y))) >
                    BOT_BALL_THRESH):
                sGoToBall.execute(self.sParams, state, self.bot_id, pub)
        else:
            return
        flaggu = 0
        possibility = isPossible(self.bot_id, state)
        bool_goal = possibility.isGoalPossible(state)
        goal_chck = self.goal_possible(state)

        scores_of_bot = self.calculate_score(state, self.bot_id)
        AttackBot_ID = self.bot_id

        self.oh_my_bot = scores_of_bot[0][0]
        self.oh_my_bot = 1
        #print("\n\n\n\n\n\n\n\n\n\nScore: "+str(scores_of_bot))
        # print("kickinf to",self.oh_my_bot)
        passprobable = possibility.isPassPossible(state, self.oh_my_bot)
        geom = Vector2D()
        angle2 = -geom.normalizeAngle(passprobable[1])
        receiveprobable = possibility.isReceivePossible(
            state, self.oh_my_bot, angle2)
        # print (passprobable[0])
        if not flaggu:
            if passprobable[0]:
                print("Passing", self.bot_id, self.oh_my_bot)
                if receiveprobable:
                    print("Receiving", self.bot_id, self.oh_my_bot)
                    receiverbot = Vector2D(
                        int(state.homePos[self.oh_my_bot].x),
                        int(state.homePos[self.oh_my_bot].y))
                    receiver_bot_id[0] = self.oh_my_bot

                    distance = ballPos.dist(receiverbot)

                    point = Vector2D(int(ballPos.x - distance * cos(angle2)),
                                     int(ballPos.y - distance * sin(angle2)))

                    # print(self.oh_my_bot)
                    # ob =Vector2D()
                    # finalSlope = ballPos.angle(Vector2D(int(state.homePos[self.oh_my_bot].x),int(state.homePos[self.oh_my_bot].y)))
                    # turnAngleLeft = ob.normalizeAngle(finalSlope - state.homePos[self.bot_id].theta)
                    botPos = Vector2D(int(state.homePos[self.bot_id].x),
                                      int(state.homePos[self.bot_id].y))
                    # ballPos=Vector2D(int(state.ballPos.x), int(state.ballPos.y))
                    dist = ballPos.dist(botPos)
                    # finalSlope1 = ballPos.angle(botPosition)
                    # anglediff = state.homePos[self.bot_id].theta - ballPos.angle(Vector2D(botPosition))
                    # turnAngleLeft1 = ob.normalizeAngle(finalSlope1 - state.homePos[self.bot_id].theta)
                    if dist > BOT_BALL_THRESH + 10:

                        print('sGoToBall', dist, BOT_BALL_THRESH)
                        sGoToBall.execute(self.sParams, state, self.bot_id,
                                          pub)
                        return
                    # elif math.fabs(turnAngleLeft1) > SATISFIABLE_THETA/2 : # SATISFIABLE_THETA in config file
                    #     sParam = skills_union.SParam()
                    #     import sTurnToPoint
                    #     sParam.TurnToPointP.x = botPosition.x
                    #     sParam.TurnToPointP.y = botPosition.y
                    #     sParam.TurnToPointP.max_omega = MAX_BOT_OMEGA
                    #     print("before turn")
                    #     sTurnToPoint.execute(self.sParams, state,self.bot_id, pub)
                    #     print("after turn")
                    #     return
                    # elif fabs(anglediff)>SATISFIABLE_THETA:
                    #     argument = "align_properly"
                    #     print(argument)
                    #     return
                    else:
                        self.sParams.KickToPointP.x = 3000
                        self.sParams.KickToPointP.y = 0
                        # self.sParams.KickToPointP.x = point.x
                        # self.sParams.KickToPointP.y = point.y
                        # for i in xrange(10):
                        #     print("cordadfsd $$$$$$$$$$$$$$$$$$$$$$$$ ",point.x," , ",point.y)
                        self.sParams.KickToPointP.power = 7
                        sKickToPoint.execute(self.sParams, state, self.bot_id,
                                             pub)
                        # argument = "kicking"
                        # print(argument)
                        return