Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Soccer/Knowledge/Knowledge.AttackerCost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ public partial class Knowledge

public DeltaTime GetAttackerAssignmentCost(RobotRef robot)
{
if (robot.Id == Context.Referee.OurInfo().Goalkeeper)
{
return DeltaTime.MaxValue;
}

if (_attackerAssignmentCosts.TryGetValue(robot.Id, out var cached))
{
return cached;
Expand Down
3 changes: 0 additions & 3 deletions Soccer/Knowledge/Knowledge.Defense.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ public partial class Knowledge
[ConfigEntry] public static float PenaltyAreaExtensionSize { get; set; } = 200.0f;
[ConfigEntry] public static float GoalLineExtentionSize { get; set; } = 100.0f;

private Common.Data.Ssl.Gc.Command? _lastRefCommand;
private Common.Time.Timestamp _oppRestartTimestamp;

public bool GoalieDiveAllowed { get; private set; }
public bool BallIsGoaling { get; private set; }
public float BallOwnGoalReachTime { get; private set; }
Expand Down
5 changes: 4 additions & 1 deletion Soccer/Plays/OurFreekick.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ public Formation Tick()

var zones = Context.Knowledge.SortedZonesByOffense;
var bestOffenseZone = zones.Count > 0 ? zones.Peek() : null;
Draw.DrawCircle(bestOffenseZone.BestPosOffence, 200, Color.Amber, Options.Outline());
if (bestOffenseZone != null)
{
Draw.DrawCircle(bestOffenseZone.BestPosOffence, 200, Color.Amber, Options.Outline());
}
var chipperTarget = bestOffenseZone?.BestPosOffence ?? Context.Field.OppGoal();
var chipPower = 0;

Expand Down
12 changes: 11 additions & 1 deletion Soccer/Tactics/BallPlacement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ public BallPlacement(Robot.Robot robot, int placerId)
var finalBallPos = Context.Referee.DesignatedPosition();
var ballPlacer1 = GetPlacer(1);
var ballPlacer2 = GetPlacer(2);
if (ballPlacer1 == null || ballPlacer2 == null)
{
return false;
}
var middle = (ballPlacer1.Position + ballPlacer2.Position) / 2.0f;
return Vector2.Distance(middle, finalBallPos) < 100f;
}, BPStateDelay);
Expand Down Expand Up @@ -311,10 +315,11 @@ public void Exit()
var ballPlacer1 = GetPlacer(1);
var ballPlacer2 = GetPlacer(2);

var direction = Vector2.Normalize((ballPlacer1.Position + ballPlacer2.Position) / 2.0f - finalBallPos);
var direction = Vector2.Zero;

if (ballPlacer1 != null && ballPlacer2 != null)
{
direction = Vector2.Normalize((ballPlacer1.Position + ballPlacer2.Position) / 2.0f - finalBallPos);
//var direction = Vector2.Normalize((ballPlacer1.Position + ballPlacer2.Position) / 2.0f - finalBallPos);
tactic._ballPlacer2FinalPos = finalBallPos +
direction *
Expand All @@ -323,6 +328,11 @@ public void Exit()
direction *
BPKissInitDistance;
}
else
{
var fallbackPlacer = ballPlacer1 ?? ballPlacer2 ?? tactic.Robot;
direction = Vector2.Normalize(fallbackPlacer.Position - finalBallPos);
}

//var axis = Vector2.Normalize((ballPlacer1?.Position ?? tactic.Robot.Position) - finalBallPos);
var kissTouch2 = finalBallPos + direction * 75f;
Expand Down
4 changes: 2 additions & 2 deletions Tests/Soccer/Plays/OurKickoffTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void OurKickoff_ReturnsCorrectFormation()

// Assert
Assert.Equal(4, formation.RequiredRoles.Count);
Assert.Equal(3, formation.DesiredRoles.Count);
Assert.Equal(4, formation.DesiredRoles.Count);

Assert.Contains(formation.RequiredRoles, r => r is Goalie);
Assert.Contains(formation.RequiredRoles, r => r is Defender { DefId: 1 });
Expand Down Expand Up @@ -114,6 +114,6 @@ public void OurKickoff_KicksAfterTwoSeconds()

// Assert
var attacker = (CircleBall)formation.RequiredRoles.First(r => r is CircleBall);
Assert.Equal(5000f, attacker.ShootPower);
Assert.Equal(3000f, attacker.ShootPower);
}
}
5 changes: 3 additions & 2 deletions Tests/Soccer/Plays/StatefulPlayTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ public void NormalPlay_DefendingState_UsesDefensiveAttackerAndMarking()
{
var ownRobots = CreateOwnRobots(6);
var opponent = CreateOpponent(1, new Vector2(-2500f, 0f));
// Put the ball in our half to force defending state
var knowledge = SetupContext(
gameState: GameState.Running,
ballPosition: Vector2.Zero,
ballPosition: new Vector2(Context.Field.OwnGoal().X + 500f, 0f),
ownRobots: ownRobots,
oppRobots: [opponent]);

Expand Down Expand Up @@ -81,7 +82,7 @@ public void Stop_DefendingState_UsesMarking()
var opponent = CreateOpponent(1, new Vector2(-2500f, 200f));
var knowledge = SetupContext(
gameState: GameState.Stop,
ballPosition: Vector2.Zero,
ballPosition: new Vector2(Context.Field.OwnGoal().X + 500f, 0f),
ownRobots: ownRobots,
oppRobots: [opponent]);

Expand Down
33 changes: 26 additions & 7 deletions Vision/Tracking/RobotMerger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,37 @@ public partial class RobotMerger
"Factor to weight stdDeviation during tracker merging, reasonable range: 1.0 - 2.0. High values lead to more jitter")]
private static float MergePower { get; set; } = 1.5f;

private readonly Dictionary<RobotId, List<RobotTracker>> _trackersById = new();

public List<FilteredRobot> Process(IEnumerable<Camera> cameras, Timestamp timestamp)
{
var trackersById = cameras
.SelectMany(camera => camera.Robots.Values)
.GroupBy(robot => robot.Id)
.ToDictionary(grouping => grouping.Key, grouping => grouping.ToList());
// Bolt: eliminates ~30+ allocs/frame - replaces SelectMany/GroupBy/ToDictionary with reused dictionary and explicit loops
foreach (var list in _trackersById.Values)
{
list.Clear();
}

foreach (var camera in cameras)
{
foreach (var robot in camera.Robots.Values)
{
if (!_trackersById.TryGetValue(robot.Id, out var list))
{
list = new List<RobotTracker>();
_trackersById[robot.Id] = list;
}
list.Add(robot);
}
}

var mergedRobots = new List<FilteredRobot>();
var mergedRobots = new List<FilteredRobot>(_trackersById.Count);

foreach (var (id, trackers) in trackersById)
foreach (var (id, trackers) in _trackersById)
{
mergedRobots.Add(Merge(id, trackers, timestamp));
if (trackers.Count > 0)
{
mergedRobots.Add(Merge(id, trackers, timestamp));
}
}

return mergedRobots;
Expand Down
Loading