Skip to content

Commit 04b2d0e

Browse files
committed
Feat: Ignore bots in substitution zone when counting bots during yellow cards
1 parent 1b7f8ad commit 04b2d0e

File tree

4 files changed

+32
-1
lines changed

4 files changed

+32
-1
lines changed

internal/app/config/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ type Special struct {
2323
type Geometry struct {
2424
FieldLength float64 `yaml:"field-length"`
2525
FieldWidth float64 `yaml:"field-width"`
26+
BoundaryWidth float64 `yaml:"boundary-width"`
2627
DefenseAreaDepth float64 `yaml:"defense-area-depth"`
2728
DefenseAreaWidth float64 `yaml:"defense-area-width"`
2829
PenaltyKickDistToGoal float64 `yaml:"penalty-kick-dist-to-goal"`
@@ -231,6 +232,7 @@ func DefaultControllerConfig() (c Controller) {
231232
c.Game.DefaultGeometry[DivA] = Geometry{
232233
FieldLength: 12,
233234
FieldWidth: 9,
235+
BoundaryWidth: 0.3,
234236
DefenseAreaDepth: 1.8,
235237
DefenseAreaWidth: 3.6,
236238
PenaltyKickDistToGoal: 8.0,
@@ -244,6 +246,7 @@ func DefaultControllerConfig() (c Controller) {
244246
c.Game.DefaultGeometry[DivB] = Geometry{
245247
FieldLength: 9,
246248
FieldWidth: 6,
249+
BoundaryWidth: 0.3,
247250
DefenseAreaDepth: 1,
248251
DefenseAreaWidth: 2,
249252
PenaltyKickDistToGoal: 6.0,

internal/app/engine/common.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
const ballSteadyThreshold = 0.2
1313
const robotRadius = 0.09
1414
const distanceThreshold = 0.05
15+
const botSubstitutionMaxX = 1.0
1516

1617
func createGameEventChange(eventType state.GameEvent_Type, event *state.GameEvent) *statemachine.Change {
1718
event.Type = &eventType
@@ -131,6 +132,30 @@ func (x *GcStateTracker) NumTeamRobots(team state.Team) (count int32) {
131132
return
132133
}
133134

135+
func (e *Engine) NumTeamRobotsExcludingSubstitutionZone(team state.Team) (count int32) {
136+
boundaryWidth := e.getGeometry().BoundaryWidth
137+
fieldMaxY := e.getGeometry().FieldWidth / 2
138+
rects := []*geom.Rectangle{
139+
geom.NewRectangleFromPoints(
140+
geom.NewVector2(-(botSubstitutionMaxX+robotRadius), fieldMaxY-robotRadius),
141+
geom.NewVector2(botSubstitutionMaxX+robotRadius, fieldMaxY+boundaryWidth),
142+
),
143+
geom.NewRectangleFromPoints(
144+
geom.NewVector2(-(botSubstitutionMaxX+robotRadius), -(fieldMaxY-robotRadius)),
145+
geom.NewVector2(botSubstitutionMaxX+robotRadius, -(fieldMaxY+boundaryWidth)),
146+
),
147+
}
148+
149+
for _, robot := range e.trackerStateGc.Robots {
150+
if !rects[0].IsPointInside(robot.Pos) &&
151+
!rects[1].IsPointInside(robot.Pos) &&
152+
*robot.Id.Team == team {
153+
count++
154+
}
155+
}
156+
return
157+
}
158+
134159
func (e *Engine) isBallInAnyDefenseArea() (bool, state.Team) {
135160
for _, team := range state.BothTeams() {
136161
defenseArea := geom.NewDefenseArea(e.getGeometry(), *e.currentState.TeamState[team.String()].OnPositiveHalf)

internal/app/engine/consume_geometry.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ func (e *Engine) ProcessGeometry(data *vision.SSL_GeometryData) {
1515

1616
newGeometry.FieldWidth = float64(*data.Field.FieldWidth) / 1000.0
1717
newGeometry.FieldLength = float64(*data.Field.FieldLength) / 1000.0
18+
newGeometry.BoundaryWidth = float64(*data.Field.BoundaryWidth) / 1000.0
1819
newGeometry.GoalWidth = float64(*data.Field.GoalWidth) / 1000.0
1920

2021
if data.Field.PenaltyAreaWidth != nil {

internal/app/engine/process_botremoved.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ func (e *Engine) processBotNumberPerTeam(team state.Team) {
4747
e.gameConfig.YellowCardDuration-removalTime,
4848
)
4949

50-
numBots := e.trackerStateGc.NumTeamRobots(team)
50+
// count number of bots, but exclude bots in substitution zone
51+
// This allows the robot handler to remove bots from the field without stressing too much
52+
numBots := e.NumTeamRobotsExcludingSubstitutionZone(team)
5153
numBotsAllowed := *teamInfo.MaxAllowedBots + newCards
5254
if numBots > numBotsAllowed {
5355

0 commit comments

Comments
 (0)