def execute(self, state, pub): point = Vector2D(int(self.param.DribbleTurnP.x), int(self.param.DribbleTurnP.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)) dist = botPos.dist(ballPos) angleToTurn = point.normalizeAngle(state.homePos[self.bot_id].theta - point.angle(ballPos)) pointDis = botPos.dist(point) goalBotAngle = point.angle(botPos) ballBotAngle = ballPos.angle(botPos) angle = point.angle(ballPos) delta = 0.085 if pointDis != 0 else 3.0 / 4 angleUp = angle + delta angleDown = angle - delta if dist >= 2.0: # DRIBBLER_BALL_THRESH: sParams = skills_union.SParam() sParams.GoToPointP.x = state.ballPos.x sParams.GoToPointP.y = state.ballPos.y sParams.GoToPointP.finalslope = ballPos.angle(botPos) sParams.GoToPointP.finalVelocity = 0 sGoToPoint.execute(sParams, state, self.bot_id, pub) else: pass
def execute(self, state, pub): print("int TestTac execute") 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) self.sParams.GoToPointP.x = 1000 self.sParams.GoToPointP.y = 200 sGoToPoint.execute(self.sParams, state, self.bot_id, pub)
def skills_GoToPoint(state, bot_id, point): sParams = skills_union.SParam() ballPos = Vector2D(int(state.ballPos.x), int(state.ballPos.y)) botPos = Vector2D(int(state.homePos[bot_id].x), int(state.homePos[bot_id].y)) ballVel = Vector2D(int(state.ballVel.x), int(state.ballVel.y)) distance = botPos.dist(ballPos) sParams.GoToPointP.x = point.x sParams.GoToPointP.y = point.y sGoToPoint.execute(sParams, state, bot_id, pub)
def execute(self, state, pub): # print("int TestTac execute") 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) self.sParams.GoToPointP.x = ballPos.x self.sParams.GoToPointP.y = ballPos.y # self.sParams.GoToBallP.finalslope = 3*pi/4.0 # self.sParams.GoToBallP.align = 3*pi/4.0 sGoToPoint.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
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__________")
def execute(self, state, pub): self.sParam.GoToPointP.x = self.param.PositionP.x self.sParam.GoToPointP.y = self.param.PositionP.y self.sParam.GoToPointP.finalSlope = self.param.PositionP.finalSlope self.sParam.GoToPointP.finalVelocity = self.param.PositionP.finalVelocity sGoToPoint.execute(self.sParam, state, self.bot_id, pub)
def execute(self, state, pub): #bot_list = [self.bot_id, self.bot_id] #self.wall_bots = wall print("Defender : ", self.bot_id) upper_limit = Vector2D(int(-HALF_FIELD_MAXX), int(OUR_GOAL_MAXY)) lower_limit = Vector2D(int(HALF_FIELD_MAXX), int(OUR_GOAL_MINY)) # p_def = Vector2D(int(state.homePos[self.bot_id].x), int(state.homePos[self.bot_id].y)) # 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)) goalieBot = Vector2D(int(state.our_goalie), int(state.our_goalie)) upper_dist = goalieBot.dist(upper_limit) lower_dist = goalieBot.dist(lower_limit) sol = Vector2D(int(-HALF_FIELD_MAXX + DBOX_WIDTH * 1.1), 0) ball_bool, angle = self.ball_velocity_direction(state) print state.ballPos.x < HALF_FIELD_MAXX, fabs( state.ballPos.y) < HALF_FIELD_MAXY if state.ballPos.x < HALF_FIELD_MAXX and fabs( state.ballPos.y) < HALF_FIELD_MAXY: print "_______________________1________________________" threat_bot, min_dist = self.threat_with_ball(state) ball_bool, angle = self.ball_velocity_direction(state) #print("min dist ,bot ",min_dist,threat_bot) threat_pointing_goal = False if min_dist < BOT_BALL_THRESH: threat_bot_pos = Vector2D(int(state.awayPos[threat_bot].x), int(state.awayPos[threat_bot].y)) threat_bot_theta = state.awayPos[threat_bot].theta bool_sol, sol = self.inter_circle_and_line( threat_bot_pos, tan(threat_bot_theta)) #print("threat1",sol.x, sol.y,bool_sol) if not bool_sol: threat_bot_theta = threat_bot_pos.angle(C) bool_sol, sol = self.inter_circle_and_line( threat_bot_pos, tan(threat_bot_theta)) else: threat_pointing_goal = True else: p_threat_id = self.primary_threat(state, threat_bot) threat_bot_pos = Vector2D(int(state.awayPos[p_threat_id].x), int(state.awayPos[p_threat_id].y)) threat_bot_theta = state.awayPos[p_threat_id].theta bool_sol, sol = self.inter_circle_and_line( threat_bot_pos, tan(threat_bot_theta)) #print("pthreat1",p_threat_id,bool_sol) if not bool_sol: threat_bot_theta = threat_bot_pos.angle(C) bool_sol, sol = self.inter_circle_and_line( threat_bot_pos, tan(threat_bot_theta)) else: threat_pointing_goal = True #print(threat_pointing_goal,threat_bot_theta) self.sParams.GoToPointP.x = sol.x self.sParams.GoToPointP.y = -1 * sol.y * 0.7 if threat_pointing_goal: if not (threat_bot_theta > pi / 2 or threat_bot_theta < -pi / 2): threat_pointing_goal = False #print(threat_pointing_goal) if threat_pointing_goal: self.sParams.GoToPointP.finalSlope = threat_bot_pos.normalizeAngle( threat_bot_theta + pi) else: self.sParams.GoToPointP.finalSlope = threat_bot_pos.normalizeAngle( threat_bot_theta) #print("bot theta ",180*threat_bot_theta/pi, 180*threat_bot_pos.normalizeAngle(threat_bot_theta)/ pi) print self.sParams.GoToPointP.x, ",", self.sParams.GoToPointP.y sGoToPoint.execute(self.sParams, state, self.bot_id, pub) return if state.ball_in_our_possession: return else: if ballPos.dist(botPos) < DBOX_WIDTH: if state.ballPos.x < -HALF_FIELD_MAXX * 0.5 and state.ballPos.x > -HALF_FIELD_MAXX + DBOX_WIDTH * 1.1: #botPos_y = tan(angle) * (-HALF_FIELD_MAXX + DBOX_WIDTH*0.8 - state.ballPos.x) +state.ballPos.y #print("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&") #print ("Bot placed at ......................................",-HALF_FIELD_MAXX*19.5/20, botPos_y) self.sParams.GoToPointP.x = state.ballPos.x self.sParams.GoToPointP.y = state.ballPos.y self.sParams.GoToPointP.finalVelocity = 0 self.sParams.GoToPointP.finalSlope = ballPos.normalizeAngle( angle + pi) sGoToPoint.execute(self.sParams, state, self.bot_id, pub)