//public void ActionAssignments(SSL_WrapperPacket packet) //{ // if (repo.Configuration.IsBlueTeam) // { // if (Closest_Blue_Distance < Closest_Yellow_Distance) // { // MakeFreeSpace(packet, repo.Configuration.IsBlueTeam); // Block_Line_of_Sight(packet, repo.Configuration.IsBlueTeam); // if (false)//GoalInSight(packet, repo.Configuration.IsBlueTeam)) // { // GoNearandRotate(packet, true, 300, new IRobotInfo(3025, 0, 0)); // } // else // { // CheckandPass(packet, repo.Configuration.IsBlueTeam); // } // } // else // { // Block_Attacker(packet, repo.Configuration.IsBlueTeam); // //if (Goal_in_Sight(ref packet, 2)) // //{ // // Shoot_at_Goal(2); // //} // //else // //{ // // Pass(2); // //} // Mark_Opp_Attack_Support(packet, repo.Configuration.IsBlueTeam); // Block_Line_of_Sight(packet, repo.Configuration.IsBlueTeam); // } // } // else // { // if (Closest_Blue_Distance < Closest_Yellow_Distance) // { // Block_Attacker(packet, repo.Configuration.IsBlueTeam); // GoalInSight(packet, repo.Configuration.IsBlueTeam); // //{ // // temp(packet, Attacker_Blue); // //} // //else // //{ // // Pass(1); // //} // Mark_Opp_Attack_Support(packet, repo.Configuration.IsBlueTeam); // Block_Line_of_Sight(packet, repo.Configuration.IsBlueTeam); // } // else // { // MakeFreeSpace(packet, repo.Configuration.IsBlueTeam); // Block_Line_of_Sight(packet, repo.Configuration.IsBlueTeam); // if (true) // { // GoNearandRotate(packet, true, 300, new IRobotInfo(-3025, 0, 0)); // } // //else // //{ // // Pass(2); // //} // } // } //} public bool GoalInSight(SSL_WrapperPacket packet, bool IsBlue) { float slope1, slope2, tmp_slope, width = 350; PointF tmp_Point = new PointF(0, 0); List<float> slopes = new List<float>(); List<float> slopes2 = new List<float>(); List<int> IDs = new List<int>(); List<PointF> Points = new List<PointF>(); List<PointF> Final_Points = new List<PointF>(); if (IsBlue) { slope1 = (OppGoal.Y + width - packet.detection.robots_blue[OwnAttackerId].y) / (OppGoal.X - packet.detection.robots_blue[OwnAttackerId].x); slope2 = (OppGoal.Y - width - packet.detection.robots_blue[OwnAttackerId].y) / (OppGoal.X - packet.detection.robots_blue[OwnAttackerId].x); for (int i = 0; i < 6; i++) { if (packet.detection.robots_blue[OwnAttackerId].x - packet.detection.robots_yellow[i].x > 0) { tmp_slope = (packet.detection.robots_blue[OwnAttackerId].y - packet.detection.robots_yellow[i].y) / (packet.detection.robots_blue[OwnAttackerId].x - packet.detection.robots_yellow[i].x); slopes.Add(tmp_slope); IDs.Add(i); } } slopes.Sort(); //MessageBox.Show("**"); for (int i = 0; i < slopes.Count; i++) { //MessageBox.Show(i.ToString()); //MessageBox.Show(slopes.Count.ToString()); if (slopes.Count == 0) break; tmp_slope = -1 / slopes[i]; if (float.IsInfinity(tmp_slope)) tmp_slope = 71; double ratio = 0.1666666; float x = 0, y = 0; while (Math.Sqrt(Math.Pow(x, 2) + Math.Pow(y, 2)) < 70) { if (Math.Abs(tmp_slope) > 8) { x = (float)(x + ratio); y = (float)(y + ratio * tmp_slope); } else { x += 1; y = y + tmp_slope; } } tmp_Point.X = packet.detection.robots_yellow[IDs[i]].x + x; tmp_Point.Y = packet.detection.robots_yellow[IDs[i]].y + y; Points.Add(tmp_Point); x = 0; y = 0; while (Math.Sqrt(Math.Pow(x, 2) + Math.Pow(y, 2)) < 70) { if (Math.Abs(tmp_slope) > 8) { x = (float)(x - ratio); y = (float)(y - ratio * tmp_slope); } else { x -= 1; y = y - tmp_slope; } } tmp_Point.X = packet.detection.robots_yellow[IDs[i]].x + x; tmp_Point.Y = packet.detection.robots_yellow[IDs[i]].y + y; Points.Add(tmp_Point); } for (int i = 0; i < Points.Count; i += 2) { if (Points.Count == 0) break; if (Points[i].Y < Points[i + 1].Y) { tmp_Point = Points[i + 1]; Points[i + 1] = Points[i]; Points[i] = tmp_Point; } } slopes.Clear(); for (int i = 0; i < Points.Count; i++) { if (Points.Count == 0) break; tmp_slope = (packet.detection.robots_blue[OwnAttackerId].y - Points[i].Y) / (packet.detection.robots_blue[OwnAttackerId].x - Points[i].X); slopes.Add(tmp_slope); } Points.Clear(); for (int i = 0; i < slopes.Count; i += 2) { tmp_Point.X = OppGoal.X; tmp_Point.Y = slopes[i] * (OppGoal.X - packet.detection.robots_blue[OwnAttackerId].x) + packet.detection.robots_blue[OwnAttackerId].y; Points.Add(tmp_Point); tmp_Point.X = OppGoal.X; tmp_Point.Y = slopes[i + 1] * (OppGoal.X - packet.detection.robots_blue[OwnAttackerId].x) + packet.detection.robots_blue[OwnAttackerId].y; Points.Add(tmp_Point); } //MessageBox.Show("**"); for (int i = 0; i < Points.Count; i++) { //MessageBox.Show(Points[i].X.ToString() + " " + Points[i].Y.ToString() + " " + i.ToString()); tmp_Point.X = 3025; if (Points[i].Y < (OppGoal.Y - 350)) { tmp_Point.Y = -350; Points[i] = tmp_Point; } if (Points[i].Y > (OppGoal.Y + 350)) { tmp_Point.Y = 350; Points[i] = tmp_Point; } } for (int i = 0; i < Points.Count; i += 2) { if ((Points[i].Y > 350 && Points[i + 1].Y > 350) || (Points[i].Y < -350 && Points[i + 1].Y < -350)) { Points.RemoveAt(i); Points.RemoveAt(i + 1); } } for (int i = 0; i < Points.Count; i++) { for (int j = 0; j < Points.Count; j += 2) { if (Points[i].Y < Points[j].Y && Points[i].Y > Points[j + 1].Y) { if (i % 2 == 0) { tmp_Point.Y = Points[j].Y; Points[i] = tmp_Point; if (Points[i + 1].Y > Points[j + 1].Y) { tmp_Point.Y = Points[j + 1].Y; Points[i + 1] = tmp_Point; } else { tmp_Point.Y = Points[i + 1].Y; Points[j + 1] = tmp_Point; } } else { tmp_Point.Y = Points[j + 1].Y; Points[i] = tmp_Point; if (Points[i - 1].Y < Points[j].Y) { tmp_Point.Y = Points[j].Y; Points[i - 1] = tmp_Point; } else { tmp_Point.Y = Points[i - 1].Y; Points[j] = tmp_Point; } } } } } for (int i = 0; i < Points.Count; i++) { tmp_Point.Y = 0; if (i == 0) { Final_Points.Add(Points[i]); } for (int j = 0; j < Final_Points.Count; j++) { if (Points[i] == Final_Points[j]) { tmp_Point.Y = 1; } } if (tmp_Point.Y == 0) { Final_Points.Add(Points[i]); } } float max_dist = 0; float tmp_dist = 0; for (int i = 0; i < Final_Points.Count; i++) { if (i == 0) { tmp_dist = OppGoal.Y + 350 - Final_Points[i].Y; max_dist = tmp_dist; tmp_Point.Y = (OppGoal.Y + 350 + Final_Points[i].Y) / 2; } else { if (i == Final_Points.Count - 1) { tmp_dist = Math.Abs(OppGoal.Y - 350 - Final_Points[i].Y); if (tmp_dist > max_dist) { max_dist = tmp_dist; tmp_Point.Y = (OppGoal.Y - 350 + Final_Points[i].Y) / 2; } } else { if (i % 2 == 0) { continue; } else { tmp_dist = Math.Abs(Final_Points[i].Y - Final_Points[i + 1].Y); if (tmp_dist > max_dist) { max_dist = tmp_dist; tmp_Point.Y = (Final_Points[i].Y + Final_Points[i + 1].Y) / 2; } } } } } //MessageBox.Show(tmp_Point.X.ToString() + " " + tmp_Point.Y.ToString()); if (max_dist >= 50) { ShootingAngle = (float)Math.Atan2(packet.detection.robots_blue[OwnAttackerId].y - tmp_Point.Y, packet.detection.robots_blue[OwnAttackerId].x - 0); return true; } else return false; } else { return true; } }
public void Block_Line_of_Sight(SSL_WrapperPacket packet, bool IsBlue) { if (IsBlue) { if (packet.detection.balls[0].x > -3025) { List<float> slopes = new List<float>(); IRobotInfo[] final_points = new IRobotInfo[3]; List<IRobotInfo> points_goal = new List<IRobotInfo>(); List<float> final_angles = new List<float>(); int point_with_small_y = 0, point_with_big_y = 2; IRobotInfo tmp_point = new RobotParameters(-3025, 0, 0); tmp_point.Y = -232; points_goal.Add(Statics.DeepClone<IRobotInfo>(tmp_point)); tmp_point.Y = 0; points_goal.Add(Statics.DeepClone<IRobotInfo>(tmp_point)); tmp_point.Y = 232; points_goal.Add(Statics.DeepClone<IRobotInfo>(tmp_point)); slopes.Add((OwnGoal.Y - 232 - packet.detection.balls[0].y) / (OwnGoal.X - packet.detection.balls[0].x)); slopes.Add((OwnGoal.Y + 0 - packet.detection.balls[0].y) / (OwnGoal.X - packet.detection.balls[0].x)); slopes.Add((OwnGoal.Y + 232 - packet.detection.balls[0].y) / (OwnGoal.X - packet.detection.balls[0].x)); float x = 0, y = 0; double ratio = 0.1666666666; for (int i = 0; i < 3; i++) { if (float.IsInfinity(slopes[i])) slopes[i] = 300; if (i == 1) { while (Math.Sqrt(Math.Pow(x, 2) + Math.Pow(y, 2)) < 375) { if (slopes[i] > 9) { x = (float)(x + ratio); y = (float)(y + ratio * slopes[i]); } else { x = x + 1; y = y + slopes[i]; } } } else { while (Math.Sqrt(Math.Pow(x, 2) + Math.Pow(y, 2)) < 800) { if (slopes[i] > 9) { x = (float)(x + ratio); y = (float)(y + ratio * slopes[i]); } else { x = x + 1; y = y + slopes[i]; } } } tmp_point.X = points_goal[i].X + x; tmp_point.Y = points_goal[i].Y + y; final_points[i] = Common.Statics.DeepClone<IRobotInfo>(tmp_point); x = 0; y = 0; } final_angles.Add((float)Math.Atan2(OwnGoal.Y - 232 - packet.detection.balls[0].y, OwnGoal.X - packet.detection.balls[0].x)); final_angles.Add((float)Math.Atan2(OwnGoal.Y - 0 - packet.detection.balls[0].y, OwnGoal.X - packet.detection.balls[0].x)); final_angles.Add((float)Math.Atan2(OwnGoal.Y + 232 - packet.detection.balls[0].y, OwnGoal.X - packet.detection.balls[0].x)); for (int i = 0; i < 3; i++) { final_angles[i] += (float)Math.PI; final_points[i].W = final_angles[i]; } if (final_points[2].Y < final_points[0].Y) { point_with_small_y = 2; point_with_big_y = 0; } if (packet.detection.robots_blue[OwnDefender1Id].y < packet.detection.robots_blue[OwnDefender2Id].y) { repo.OutData[OwnDefender1Id].X = final_points[point_with_small_y].X; repo.OutData[OwnDefender1Id].Y = final_points[point_with_small_y].Y; repo.OutData[OwnDefender1Id].W = final_points[point_with_small_y].W; //DataHandler.WriteReference(final_points[point_with_small_y], Defender1_Blue); repo.OutData[OwnGoalkeeperId].X = final_points[1].X; repo.OutData[OwnGoalkeeperId].Y = final_points[1].Y; repo.OutData[OwnGoalkeeperId].W = final_points[1].W; //DataHandler.WriteReference(final_points[1], GoalKeeper_Blue_id); repo.OutData[OwnDefender2Id].X = final_points[point_with_big_y].X; repo.OutData[OwnDefender2Id].Y = final_points[point_with_big_y].Y; repo.OutData[OwnDefender2Id].W = final_points[point_with_big_y].W; //DataHandler.WriteReference(final_points[point_with_big_y], Defender2_Blue); } else { repo.OutData[OwnDefender1Id].X = final_points[point_with_big_y].X; repo.OutData[OwnDefender1Id].Y = final_points[point_with_big_y].Y; repo.OutData[OwnDefender1Id].W = final_points[point_with_big_y].W; //DataHandler.WriteReference(final_points[point_with_big_y], Defender1_Blue); repo.OutData[OwnGoalkeeperId].X = final_points[1].X; repo.OutData[OwnGoalkeeperId].Y = final_points[1].Y; repo.OutData[OwnGoalkeeperId].W = final_points[1].W; //DataHandler.WriteReference(final_points[1], GoalKeeper_Blue_id); repo.OutData[OwnDefender2Id].X = final_points[point_with_small_y].X; repo.OutData[OwnDefender2Id].Y = final_points[point_with_small_y].Y; repo.OutData[OwnDefender2Id].W = final_points[point_with_small_y].W; //DataHandler.WriteReference(final_points[point_with_small_y], Defender2_Blue); } //if(Distance(packet.detection.robots_blue[Defender1_Blue].x,final_points[0].x,packet.detection.robots_blue[Defender1_Blue].y,final_points[0].y) < Distance(packet.detection.robots_blue[Defender2_Blue].x,final_points[0].x, //rebuff = Defender1_Blue.ToString() + Environment.NewLine + final_points[0].x.ToString() + " " + final_points[0].y.ToString() + " " + final_points[0].w.ToString() + // Environment.NewLine + GoalKeeper_Blue_id.ToString() + Environment.NewLine + final_points[1].x.ToString() + " " + final_points[1].y.ToString() + " " + final_points[1].w.ToString() + // Environment.NewLine + Defender2_Blue.ToString() + Environment.NewLine + final_points[2].x.ToString() + " " + final_points[2].y.ToString() + " " + final_points[2].w.ToString(); } } else { if (packet.detection.balls[0].x < 3025) { List<float> slopes = new List<float>(); IRobotInfo[] final_points = new IRobotInfo[3]; List<IRobotInfo> points_goal = new List<IRobotInfo>(); List<float> final_angles = new List<float>(); int point_with_small_y = 0, point_with_big_y = 2; IRobotInfo tmp_point = new RobotParameters(3025, 0, 0); tmp_point.Y = -232; points_goal.Add(Statics.DeepClone<IRobotInfo>(tmp_point)); tmp_point.Y = 0; points_goal.Add(Statics.DeepClone<IRobotInfo>(tmp_point)); tmp_point.Y = 232; points_goal.Add(Statics.DeepClone<IRobotInfo>(tmp_point)); slopes.Add((OppGoal.Y - 232 - packet.detection.balls[0].y) / (OppGoal.X - packet.detection.balls[0].x)); slopes.Add((OppGoal.Y + 0 - packet.detection.balls[0].y) / (OppGoal.X - packet.detection.balls[0].x)); slopes.Add((OppGoal.Y + 232 - packet.detection.balls[0].y) / (OppGoal.X - packet.detection.balls[0].x)); float x = 0, y = 0; double ratio = 0.1666666666; for (int i = 0; i < 3; i++) { if (float.IsInfinity(slopes[i])) slopes[i] = 300; if (i == 1) { while (Math.Sqrt(Math.Pow(x, 2) + Math.Pow(y, 2)) < 375) { if (slopes[i] > 9) { x = (float)(x - ratio); y = (float)(y - ratio * slopes[i]); } else { x = x - 1; y = y - slopes[i]; } } } else { while (Math.Sqrt(Math.Pow(x, 2) + Math.Pow(y, 2)) < 800) { if (slopes[i] > 9) { x = (float)(x - ratio); y = (float)(y - ratio * slopes[i]); } else { x = x - 1; y = y - slopes[i]; } } } tmp_point.X = points_goal[i].X + x; tmp_point.Y = points_goal[i].Y + y; final_points[i] = Statics.DeepClone<IRobotInfo>(tmp_point); x = 0; y = 0; } final_angles.Add((float)Math.Atan2(OppGoal.Y - 232 - packet.detection.balls[0].y, OppGoal.X - packet.detection.balls[0].x)); final_angles.Add((float)Math.Atan2(OppGoal.Y - 0 - packet.detection.balls[0].y, OppGoal.X - packet.detection.balls[0].x)); final_angles.Add((float)Math.Atan2(OppGoal.Y + 232 - packet.detection.balls[0].y, OppGoal.X - packet.detection.balls[0].x)); for (int i = 0; i < 3; i++) { final_angles[i] += (float)Math.PI; final_points[i].W = final_angles[i]; } if (final_points[2].Y < final_points[0].Y) { point_with_small_y = 2; point_with_big_y = 0; } if (packet.detection.robots_yellow[OppDefender1Id].y < packet.detection.robots_yellow[OppDefender2Id].y) { repo.OutData[OppDefender1Id].X = final_points[point_with_small_y].X; repo.OutData[OppDefender1Id].Y = final_points[point_with_small_y].Y; repo.OutData[OppDefender1Id].W = final_points[point_with_small_y].W; //DataHandler.WriteReference(final_points[point_with_small_y], Defender1_Yellow); repo.OutData[OppGoalkeeperId].X = final_points[1].X; repo.OutData[OppGoalkeeperId].Y = final_points[1].Y; repo.OutData[OppGoalkeeperId].W = final_points[1].W; //DataHandler.WriteReference(final_points[1], GoalKeeper_Yellow_id); repo.OutData[OppDefender2Id].X = final_points[point_with_big_y].X; repo.OutData[OppDefender2Id].Y = final_points[point_with_big_y].Y; repo.OutData[OppDefender2Id].W = final_points[point_with_big_y].W; //DataHandler.WriteReference(final_points[point_with_big_y], Defender2_Yellow); } else { repo.OutData[OppDefender1Id].X = final_points[point_with_big_y].X; repo.OutData[OppDefender1Id].Y = final_points[point_with_big_y].Y; repo.OutData[OppDefender1Id].W = final_points[point_with_big_y].W; //DataHandler.WriteReference(final_points[point_with_big_y], Defender1_Yellow); repo.OutData[OppGoalkeeperId].X = final_points[1].X; repo.OutData[OppGoalkeeperId].Y = final_points[1].Y; repo.OutData[OppGoalkeeperId].W = final_points[1].W; //DataHandler.WriteReference(final_points[1], GoalKeeper_Yellow_id); repo.OutData[OppDefender2Id].X = final_points[point_with_small_y].X; repo.OutData[OppDefender2Id].Y = final_points[point_with_small_y].Y; repo.OutData[OppDefender2Id].W = final_points[point_with_small_y].W; //DataHandler.WriteReference(final_points[point_with_small_y], Defender2_Yellow); } } //tb_private.Text += "Yellow Defender1 ID " + Defender1_Yellow + " and " + "Yellow Defender2 ID " + Defender2_Yellow + " blocking the goal " + "\r\n"; } //Use Defender1_Yellow and Defender2_Support_Yellow for team 2 and Defender1_Blue and Defender2_Support_Blue for team 1. }
public void CheckandPass(SSL_WrapperPacket packet, bool IsBlue) { IRobotInfo roboinfo = RobotToIRobotInfo(repo.InData.Own(OwnAttackerId)); IRobotInfo roboinfo2 = RobotToIRobotInfo(repo.InData.Own(OwnAttackSupportId)); if (roboinfo.XVelocity <= 0.005 && roboinfo.YVelocity <= 0.005 && roboinfo.WVelocity <= 0.005 && roboinfo2.XVelocity <= 0.005 && roboinfo2.YVelocity <= 0.005 && roboinfo2.WVelocity < 0.005) { bool go_support = true; if (IsBlue) { IRobotInfo[] pts = TrianglePoints(packet, PassCalculation(RobotToIRobotInfo(packet.detection.robots_blue[OwnAttackSupportId]), new RobotParameters(packet.detection.balls[0].x, packet.detection.balls[0].y, 0), 50), OwnAttackSupportId, repo.Configuration.IsBlueTeam); foreach (SSL_DetectionRobot robot in packet.detection.robots_yellow) if (TriangleTest(pts[0], pts[1], RobotToIRobotInfo(packet.detection.robots_blue[OwnAttackSupportId]), RobotToIRobotInfo(robot))) { go_support = false; break; } if (go_support) { GoNearandRotate(packet, repo.Configuration.IsBlueTeam, 300, RobotToIRobotInfo(packet.detection.robots_blue[OwnAttackSupportId])); } else { go_support = true; pts = TrianglePoints(packet, PassCalculation(RobotToIRobotInfo(packet.detection.robots_blue[OwnFreeRoleId]), new RobotParameters(packet.detection.balls[0].x, packet.detection.balls[0].y, 0), 50), OwnFreeRoleId, repo.Configuration.IsBlueTeam); foreach (SSL_DetectionRobot robot in packet.detection.robots_yellow) { if (TriangleTest(pts[0], pts[1], RobotToIRobotInfo(packet.detection.robots_blue[OwnFreeRoleId]), RobotToIRobotInfo(robot))) { go_support = false; break; } } if (go_support) { GoNearandRotate(packet, repo.Configuration.IsBlueTeam, 300, RobotToIRobotInfo(packet.detection.robots_blue[OwnFreeRoleId])); } } } } }
public IRobotInfo[] TrianglePoints(SSL_WrapperPacket packet, IRobotInfo source, int TargetID, bool IsBlue) { IRobotInfo[] t = new IRobotInfo[2]; float angle = (float)Math.Atan2(source.Y - packet.detection.robots_blue[TargetID].y, source.X - packet.detection.robots_blue[TargetID].x); t[0] = new RobotParameters((float)(-100 * Math.Sin(angle)) + source.X, (float)(100 * Math.Cos(angle)) + source.Y, 0); t[1] = new RobotParameters((float)(100 * Math.Sin(angle)) + source.X, (float)(-100 * Math.Cos(angle)) + source.Y, 0); return t; }
public void Block_Attacker(SSL_WrapperPacket packet, bool IsBlue) { IRobotInfo Final_Point_Marker = new RobotParameters(0, 0, 0); float Final_Angle = 0; float tmp_slope = 0; if (IsBlue) { tmp_slope = (OwnGoal.Y - packet.detection.balls[0].y) / (OwnGoal.X - packet.detection.balls[0].x); if (float.IsInfinity(tmp_slope)) tmp_slope = 300; float x = 0; float y = 0; double ratio = 0.1666666666; while (Math.Sqrt(Math.Pow(x, 2) + Math.Pow(y, 2)) < 300) { if (tmp_slope > 9) { x = (float)(x - ratio); y = (float)(y - ratio * tmp_slope); } else { x = x - 1; y = y - tmp_slope; } } Final_Point_Marker.X = packet.detection.balls[0].x + x; Final_Point_Marker.Y = packet.detection.balls[0].y + y; Final_Angle = (float)Math.Atan2(OwnGoal.Y - packet.detection.balls[0].y, OwnGoal.X - packet.detection.balls[0].x); Final_Angle = (float)(Final_Angle + Math.PI); Final_Point_Marker.W = Final_Angle; repo.OutData[OwnAttackerId].X = Final_Point_Marker.X; repo.OutData[OwnAttackerId].Y = Final_Point_Marker.Y; repo.OutData[OwnAttackerId].W = Final_Point_Marker.W; //DataHandler.WriteReference(Final_Point_Marker, Attacker_Blue); } else { tmp_slope = (OppGoal.Y - packet.detection.balls[0].y) / (OppGoal.X - packet.detection.balls[0].x); if (float.IsInfinity(tmp_slope)) tmp_slope = 300; float x = 0; float y = 0; double ratio = 0.16666666666; while (Math.Sqrt(Math.Pow(x, 2) + Math.Pow(y, 2)) < 300) { if (tmp_slope > 9) { x = (float)(x + ratio); y = (float)(y + ratio * tmp_slope); } else { x = x + 1; y = y + tmp_slope; } } Final_Point_Marker.X = packet.detection.balls[0].x + x; Final_Point_Marker.Y = packet.detection.balls[0].y + y; Final_Angle = (float)Math.Atan2(OppGoal.Y - packet.detection.balls[0].y, OppGoal.X - packet.detection.balls[0].x); Final_Angle = (float)(Final_Angle + Math.PI); Final_Point_Marker.W = Final_Angle; repo.OutData[OppAttackerId].X = Final_Point_Marker.X; repo.OutData[OppAttackerId].Y = Final_Point_Marker.Y; repo.OutData[OppAttackerId].W = Final_Point_Marker.W; //DataHandler.WriteReference(Final_Point_Marker, Attacker_Yellow); //Yellow Function Goes Here } //Use Marker_Yellow for team 2 and Marker_Blue for team 1. }
public IRobotInfo[] PlanExclusive(SSL_WrapperPacket mainPacket) { Plan(); return null; }
public void rotateabout(SSL_WrapperPacket packet, IRobotInfo target, float conf) { //packet.detection.robots_blue[Attacker_Blue] //PointF[] paray=new PointF[360]; //for (int i=0;i<360;i++) float finalangle = (float)Math.Atan2(packet.detection.balls[0].y - target.Y, packet.detection.balls[0].x - target.X); IRobotInfo rb1 = new RobotParameters(); float i = (float)Math.Atan2(packet.detection.robots_blue[OwnAttackerId].y - packet.detection.balls[0].y, packet.detection.robots_blue[OwnAttackerId].x - packet.detection.balls[0].x); float Offset = 1.30f;//0.69808027923211169284467713787086f; if (Math.Abs(finalangle - i) > Math.PI) Offset = -Offset; if (finalangle - i > Offset)//0.69808027923211169284467713787086f) { //rebuff = (finalangle * 57.3).ToString() + " x " + (i * 57.3).ToString(); i += Offset; rb1.X = packet.detection.balls[0].x + conf * (float)Math.Cos(i); rb1.Y = packet.detection.balls[0].y + conf * (float)Math.Sin(i); //rb1.w = (float)Math.Atan2(packet.detection.balls[0].y - packet.detection.robots_blue[Attacker_Blue].y, packet.detection.balls[0].x - packet.detection.robots_blue[Attacker_Blue].x); //rb1.w += (float)Offset; repo.OutData[OwnAttackerId].X = rb1.X; repo.OutData[OwnAttackerId].Y = rb1.Y; repo.OutData[OwnAttackerId].W = (float)Math.Atan2(0 - repo.InData.GetBalls(0)[0].y, 3025 - repo.InData.GetBalls(0)[0].x); //DataHandler.WriteReference(new RobotParameters(rb1.X, rb1.Y, (float)Math.Atan2(0 - packet.detection.balls[0].y, 3025 - packet.detection.balls[0].x)), Attacker_Blue); } else if (finalangle - i > 0.05f) { //rebuff = (finalangle * 57.3).ToString() + Environment.NewLine; rb1.X = packet.detection.balls[0].x + conf * (float)Math.Cos(finalangle); rb1.Y = packet.detection.balls[0].y + conf * (float)Math.Sin(finalangle); //rb1.w = (float)Math.Atan2(packet.detection.balls[0].y - packet.detection.robots_blue[Attacker_Blue].y, packet.detection.balls[0].x - packet.detection.robots_blue[Attacker_Blue].x); //rb1.w += (float)(40 / 57.3); repo.OutData[OwnAttackerId].X = rb1.X; repo.OutData[OwnAttackerId].Y = rb1.Y; repo.OutData[OwnAttackerId].X = (float)Math.Atan2(0 - packet.detection.balls[0].y, 3025 - packet.detection.balls[0].x); //DataHandler.WriteReference(new IRobotInfo(rb1.X, rb1.Y, (float)Math.Atan2(0 - packet.detection.balls[0].y, 3025 - packet.detection.balls[0].x)), Attacker_Blue); } else GrabOrKick(packet, OwnAttackerId); }
public void MakeFreeSpace(SSL_WrapperPacket packet, bool IsBlue) { IRobotInfo Final_Point_Support = new RobotParameters(); IRobotInfo Final_Point_Mid = new RobotParameters(); if (IsBlue) { //tb_private.Text += "Blue team's Attack Support ID " + Attack_Supporter_Blue + " and Midfielder ID " + Free_Role_Blue + " move into the free space" + "\r\n"; if (OppRobotsMean.Y > 0) { if (Distance(packet.detection.robots_blue[OwnAttackSupportId].x, OppRobotsMean.X, packet.detection.robots_blue[OwnAttackSupportId].y, OppRobotsMean.Y) < Distance(packet.detection.robots_blue[OwnFreeRoleId].x, OppRobotsMean.X, packet.detection.robots_blue[OwnFreeRoleId].y, OppRobotsMean.Y)) { Final_Point_Support.X = OppRobotsMean.X; Final_Point_Support.Y = OppRobotsMean.Y; Final_Point_Mid.X = OppRobotsMean.X; Final_Point_Mid.Y = -9 * OppRobotsStandardDeviation.Y / 5; } else { Final_Point_Support.X = OppRobotsMean.X; Final_Point_Support.Y = -9 * OppRobotsStandardDeviation.Y / 5; Final_Point_Mid.X = OppRobotsMean.X; Final_Point_Mid.Y = OppRobotsMean.Y; } } else { if (Distance(packet.detection.robots_blue[OwnAttackSupportId].x, OppRobotsMean.X, packet.detection.robots_blue[OwnAttackSupportId].y, -OppRobotsMean.Y) < Distance(packet.detection.robots_blue[OwnFreeRoleId].x, OppRobotsMean.X, packet.detection.robots_blue[OwnFreeRoleId].y, -OppRobotsMean.Y)) { Final_Point_Support.X = OppRobotsMean.X; Final_Point_Support.Y = -OppRobotsMean.Y; Final_Point_Mid.X = OppRobotsMean.X; Final_Point_Mid.Y = 9 * OppRobotsStandardDeviation.Y / 5; } else { Final_Point_Support.X = OppRobotsMean.X; Final_Point_Support.Y = 9 * OppRobotsStandardDeviation.Y / 5; Final_Point_Mid.X = OppRobotsMean.X; Final_Point_Mid.Y = -OppRobotsMean.Y; } } Final_Point_Support.W = (float)Math.Atan2(packet.detection.balls[0].y - Final_Point_Support.Y, packet.detection.balls[0].x - Final_Point_Support.X); Final_Point_Mid.W = (float)Math.Atan2(packet.detection.balls[0].y - Final_Point_Mid.Y, packet.detection.balls[0].x - Final_Point_Mid.X); repo.OutData[OwnAttackSupportId].X = Final_Point_Support.X; repo.OutData[OwnAttackSupportId].Y = Final_Point_Support.Y; repo.OutData[OwnAttackSupportId].W = Final_Point_Support.W; //DataHandler.WriteReference(Final_Point_Support, Attack_Supporter_Blue); repo.OutData[OwnFreeRoleId].X = Final_Point_Mid.X; repo.OutData[OwnFreeRoleId].Y = Final_Point_Mid.Y; repo.OutData[OwnFreeRoleId].W = Final_Point_Mid.W; //DataHandler.WriteReference(Final_Point_Mid, Free_Role_Blue); //tb_private.Text += "Blue team's Attack Support ID " + Attack_Supporter_Blue + " moves to (" + Final_Point_Support.X + ", " + Final_Point_Support.Y + ") and Midfielder ID " + Free_Role_Blue + " moves to (" + Final_Point_Mid.X + ", " + Final_Point_Mid.Y + ")" + "\r\n"; } else { if (OwnRobotsMean.Y > 0) { if (Distance(packet.detection.robots_yellow[OppAttackSupportId].x, OwnRobotsMean.X, packet.detection.robots_yellow[OppAttackSupportId].y, OwnRobotsMean.Y) < Distance(packet.detection.robots_yellow[OppFreeRoleId].x, OwnRobotsMean.X, packet.detection.robots_yellow[OppFreeRoleId].y, OwnRobotsMean.Y)) { Final_Point_Support.X = OwnRobotsMean.X; Final_Point_Support.Y = OwnRobotsMean.Y; Final_Point_Mid.X = OwnRobotsMean.X; Final_Point_Mid.Y = -9 * OwnRobotsStandardDeviation.Y / 5; } else { Final_Point_Support.X = OwnRobotsMean.X; Final_Point_Support.Y = -9 * OwnRobotsStandardDeviation.Y / 5; Final_Point_Mid.X = OwnRobotsMean.X; Final_Point_Mid.Y = OwnRobotsMean.Y; } } else { if (Distance(packet.detection.robots_yellow[OppAttackSupportId].x, OwnRobotsMean.X, packet.detection.robots_yellow[OppAttackSupportId].y, -OwnRobotsMean.Y) < Distance(packet.detection.robots_yellow[OppFreeRoleId].x, OwnRobotsMean.X, packet.detection.robots_yellow[OppFreeRoleId].y, -OwnRobotsMean.Y)) { Final_Point_Support.X = OwnRobotsMean.X; Final_Point_Support.Y = -OwnRobotsMean.Y; Final_Point_Mid.X = OwnRobotsMean.X; Final_Point_Mid.Y = 9 * OwnRobotsStandardDeviation.Y / 5; } else { Final_Point_Support.X = OwnRobotsMean.X; Final_Point_Support.Y = 9 * OwnRobotsStandardDeviation.Y / 5; Final_Point_Mid.X = OwnRobotsMean.X; Final_Point_Mid.Y = -OwnRobotsMean.Y; } } Final_Point_Mid.W = (float)Math.Atan2(packet.detection.balls[0].y - Final_Point_Mid.Y, packet.detection.balls[0].x - Final_Point_Mid.X); Final_Point_Support.W = (float)Math.Atan2(packet.detection.balls[0].y - Final_Point_Support.Y, packet.detection.balls[0].x - Final_Point_Support.X); repo.OutData[OppAttackSupportId].X = Final_Point_Support.X; repo.OutData[OppAttackSupportId].Y = Final_Point_Support.Y; repo.OutData[OppAttackSupportId].W = Final_Point_Support.W; //DataHandler.WriteReference(Final_Point_Support, Attack_Supporter_Yellow); repo.OutData[OppFreeRoleId].X = Final_Point_Mid.X; repo.OutData[OppFreeRoleId].Y = Final_Point_Mid.Y; repo.OutData[OppFreeRoleId].W = Final_Point_Mid.W; //DataHandler.WriteReference(Final_Point_Mid, Free_Role_Yellow); //MessageBox.Show(Final_Point_Support.x.ToString() + ", " + Final_Point_Support.y.ToString() + " " + Final_Point_Mid.x.ToString() + ", " + Final_Point_Mid.y.ToString()); //tb_private.Text += "Yellow team's Attack Support ID " + Attack_Supporter_Yellow + " and Midfielder ID " + Free_Role_Yellow + " move into the free space" + "\r\n"; } }
public void Mark_Opp_Attack_Support(SSL_WrapperPacket packet, bool IsBlue) { IRobotInfo Final_Point_Marker = new RobotParameters(0, 0, 0); float Final_Angle = 0; float tmp_slope = 0; if (IsBlue) { tmp_slope = (packet.detection.robots_yellow[OppAttackSupportId].y - packet.detection.robots_yellow[OppAttackerId].y) / (packet.detection.robots_yellow[OppAttackSupportId].x - packet.detection.robots_yellow[OppAttackerId].x); if (float.IsInfinity(tmp_slope)) tmp_slope = 300; float x = 0; float y = 0; double ratio = 0.1666666; while (Math.Sqrt(Math.Pow(x, 2) + Math.Pow(y, 2)) < 300) { if (packet.detection.robots_yellow[OppAttackSupportId].x <= packet.detection.robots_yellow[OppAttackerId].x) { if (tmp_slope > 9) { x = (float)(x + ratio); y = (float)(y + ratio * tmp_slope); } else { x = x + 1; y = y + tmp_slope; } } else { if (tmp_slope > 9) { x = (float)(x - ratio); y = (float)(y - ratio * tmp_slope); } else { x = x - 1; y = y - tmp_slope; } } } Final_Point_Marker.X = packet.detection.robots_yellow[OppAttackSupportId].x + x; Final_Point_Marker.Y = packet.detection.robots_yellow[OppAttackSupportId].y + y; Final_Angle = (float)Math.Atan2(packet.detection.robots_yellow[OppAttackSupportId].y - packet.detection.robots_yellow[OppAttackerId].y, packet.detection.robots_yellow[OppAttackSupportId].x - packet.detection.robots_yellow[OppAttackerId].x); Final_Angle = (float)(Final_Angle + Math.PI); Final_Point_Marker.W = Final_Angle; //MessageBox.Show(Final_Angle.ToString()); repo.OutData[OwnAttackSupportId].X = Final_Point_Marker.X; repo.OutData[OwnAttackSupportId].Y = Final_Point_Marker.Y; repo.OutData[OwnAttackSupportId].W = Final_Point_Marker.W; //DataHandler.WriteReference(Final_Point_Marker, Attack_Supporter_Blue); //tb_private.Text += "Blue Marker ID " + Marker_Blue + " blocking goal " + "\r\n"; //tb_private.Text += "Blue Midfielder ID " + Free_Role_Blue + " moves to (" + Final_Point_Marker.X + ", " + Final_Point_Marker.Y + ")" + "\r\n"; } else { tmp_slope = (packet.detection.robots_blue[OwnAttackSupportId].y - packet.detection.robots_blue[OwnAttackerId].y) / (packet.detection.robots_blue[OwnAttackSupportId].x - packet.detection.robots_blue[OwnAttackerId].x); //.Show(tmp_slope.ToString()); if (float.IsInfinity(tmp_slope)) tmp_slope = 300; //MessageBox.Show(tmp_slope.ToString()); float x = 0; float y = 0; double ratio = 0.1666666666666; while (Math.Sqrt(Math.Pow(x, 2) + Math.Pow(y, 2)) < 300) { if (packet.detection.robots_blue[OwnAttackSupportId].x <= packet.detection.robots_blue[OwnAttackerId].x) { if (tmp_slope > 9) { x = (float)(x + ratio); y = (float)(y + ratio * tmp_slope); } else { x = x + 1; y = y + tmp_slope; } } else { if (tmp_slope > 9) { x = (float)(x - ratio); y = (float)(y - ratio * tmp_slope); } else { x = x - 1; y = y - tmp_slope; } //MessageBox.Show(x.ToString() + ", " + y.ToString()); } } Final_Point_Marker.X = packet.detection.robots_blue[OwnAttackSupportId].x + x; Final_Point_Marker.Y = packet.detection.robots_blue[OwnAttackSupportId].y + y; Final_Angle = (float)Math.Atan2(packet.detection.robots_blue[OwnAttackSupportId].y - packet.detection.robots_blue[OwnAttackerId].y, packet.detection.robots_blue[OwnAttackSupportId].x - packet.detection.robots_blue[OwnAttackerId].x); Final_Angle = (float)(Final_Angle + Math.PI); Final_Point_Marker.W = Final_Angle; //MessageBox.Show(Final_Angle.ToString()); repo.OutData[OppAttackSupportId].X = Final_Point_Marker.X; repo.OutData[OppAttackSupportId].Y = Final_Point_Marker.Y; repo.OutData[OppAttackSupportId].W = Final_Point_Marker.W; //DataHandler.WriteReference(Final_Point_Marker, Attack_Supporter_Yellow); //tb_private.Text += "Yellow team's Midfielder ID " + Free_Role_Blue + " marking Blue's Attack Supporter ID " + Attack_Supporter_Blue + "\r\n"; } }
public void GrabOrKick(SSL_WrapperPacket packet, int id) { if (repo.Configuration.IsBlueTeam) { if (Distance(packet.detection.robots_blue[id].x, packet.detection.balls[0].x, packet.detection.robots_blue[id].y, packet.detection.balls[0].y) > 105) GrabBall(packet, repo.Configuration.IsBlueTeam); else Kickball(packet, id, 5, repo.Configuration.IsBlueTeam); } else { if (Distance(packet.detection.robots_yellow[id].x, packet.detection.balls[0].x, packet.detection.robots_yellow[id].y, packet.detection.balls[0].y) > 105) GrabBall(packet, repo.Configuration.IsBlueTeam); else Kickball(packet, id, 5, repo.Configuration.IsBlueTeam); } }
public void Kickball(SSL_WrapperPacket packet, int id, float speed, bool IsBlue) { if (IsBlue) { repo.OutData[id].KickSpeed = speed; //DataHandler.WriteKickSpeed(speed, id); System.Threading.Thread.Sleep(100); repo.OutData[id].KickSpeed = 0; //DataHandler.WriteKickSpeed(0, id); repo.OutData[id].Grab = false; //DataHandler.Dribble[id] = false; } else { repo.OutData[id].KickSpeed = speed; //DataHandler.WriteKickSpeed(speed, id); System.Threading.Thread.Sleep(100); repo.OutData[id].KickSpeed = 0; //DataHandler.WriteKickSpeed(0, id); repo.OutData[id].Grab = false; //DataHandler.Dribble[id] = false; } }
public void GrabBall(SSL_WrapperPacket packet, bool IsBlue) { if (IsBlue) { IRobotInfo final = new RobotParameters(packet.detection.balls[0].x, packet.detection.balls[0].y, (float)Math.Atan2(packet.detection.balls[0].y - packet.detection.robots_blue[OwnAttackerId].y, packet.detection.balls[0].x - packet.detection.robots_blue[OwnAttackerId].x)); repo.OutData[OwnAttackerId].X = final.X; repo.OutData[OwnAttackerId].X = final.Y; repo.OutData[OwnAttackerId].X = final.W; //DataHandler.WriteReference(final, Attacker_Blue); repo.OutData[OwnAttackerId].Grab = true; //DataHandler.Dribble[Attacker_Blue] = true; } else { IRobotInfo final = new RobotParameters(packet.detection.balls[0].x, packet.detection.balls[0].y, (float)Math.Atan2(packet.detection.balls[0].y - packet.detection.robots_yellow[OppAttackerId].y, packet.detection.balls[0].x - packet.detection.robots_yellow[OppAttackerId].x)); repo.OutData[OppAttackerId].X = final.X; repo.OutData[OppAttackerId].X = final.Y; repo.OutData[OppAttackerId].X = final.W; //DataHandler.WriteReference(final, Attacker_Yellow); repo.OutData[OppAttackerId].Grab = true; //DataHandler.Dribble[Attacker_Yellow] = true; } }
public void GoNearBall(SSL_WrapperPacket packet, bool IsBlue, float conf) { if (IsBlue) { float dis = Distance(packet.detection.robots_blue[OwnAttackerId].x, packet.detection.balls[0].x, packet.detection.robots_blue[OwnAttackerId].y, packet.detection.balls[0].y); float angle = (float)Math.Atan2(packet.detection.balls[0].y - packet.detection.robots_blue[OwnAttackerId].y, packet.detection.balls[0].x - packet.detection.robots_blue[OwnAttackerId].x); dis -= conf; IRobotInfo Target = new RobotParameters(packet.detection.robots_blue[OwnAttackerId].x + (float)(dis * Math.Cos(angle)), packet.detection.robots_blue[OwnAttackerId].y + (float)(dis * Math.Sin(angle)), (float)Math.Atan2(0 - packet.detection.balls[0].y, 3025 - packet.detection.balls[0].x)); repo.OutData[OwnAttackerId].X = Target.X; repo.OutData[OwnAttackerId].Y = Target.Y; repo.OutData[OwnAttackerId].W = Target.W; //DataHandler.WriteReference(Target, Attacker_Blue); } }
public void GoNearandRotate(SSL_WrapperPacket packet, bool IsBlue, float conf, IRobotInfo target) { if (Distance(packet.detection.robots_blue[OwnAttackerId].x, packet.detection.balls[0].x, packet.detection.robots_blue[OwnAttackerId].y, packet.detection.balls[0].y) > conf) GoNearBall(packet, true, conf - 200); else { rotateabout(packet, target, 350); } }
/// <summary> /// Parse the input packet so it is available on the parser's call /// </summary> /// <param name="packet">Input packet</param> public void ParsePacket(SSL_WrapperPacket packet) { if (packet != null) { if (_isBlue) { foreach (SSL_DetectionRobot ownRobot in packet.detection.robots_blue) _ownRobots[ownRobot.robot_id].Insert(ownRobot); foreach (SSL_DetectionRobot opponentRobot in packet.detection.robots_yellow) _opponentRobots[opponentRobot.robot_id].Insert(opponentRobot); } else { foreach (SSL_DetectionRobot ownRobot in packet.detection.robots_yellow) _ownRobots[ownRobot.robot_id].Insert(ownRobot); foreach (SSL_DetectionRobot opponentRobot in packet.detection.robots_blue) _opponentRobots[opponentRobot.robot_id].Insert(opponentRobot); } _balls.Insert(packet.detection.balls); if (packet.geometry != null) lock (_geoLock) { _geoData = packet.geometry; } } }
public IRobotInfo[] PlanExclusive(SSL_WrapperPacket mainPacket) { for (int i = 0; i < _gamePads.Length; i++) { if (_gamePads[i].Acquire().IsFailure) continue; if (_gamePads[i].Poll().IsFailure) continue; _states[i] = _gamePads[i].GetCurrentState(); if (Result.Last.IsFailure) continue; else { IRobotInfo robotInfo = new RobotParameters(); robotInfo.Id = 1; //Get Current Robot Position //Set Next Robot Position By adding the GamePad Values in Current Positon // example //currVAlX += _states[i].X; //currVALY += _states[i].Y; //currVALZ += _states[i].Z; //Call GrabBall Function from AI AIPlanner if you want (To Rotate and Go to that point) //Call GotoBall Function from AI AIPlanner if you want (TO Goto that point with Same direction) //Send Value to PID; //Write values to _repReference.OutData return new[] {robotInfo}; } } return null; }