Skip to content

Commit 4c6e0d1

Browse files
committed
[feature] Add maxAllowedBots to state, UI and referee message
1 parent a1762cc commit 4c6e0d1

File tree

9 files changed

+115
-71
lines changed

9 files changed

+115
-71
lines changed

config/ssl-game-controller.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,7 @@ game:
4545
placement-offset-touch-line: 0.2
4646
placement-offset-goal-line: 0.2
4747
placement-offset-goal-line-goal-kick: 1.0
48-
placement-offset-defense-area: 1.0
48+
placement-offset-defense-area: 1.0
49+
max-bots:
50+
DivA: 8
51+
DivB: 6

internal/app/controller/config.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ type ConfigGame struct {
3838
MultipleCardStep int `yaml:"multiple-card-step"`
3939
MultipleFoulStep int `yaml:"multiple-foul-step"`
4040
MultiplePlacementFailures int `yaml:"multiple-placement-failures"`
41+
MaxBots map[Division]int `yaml:"max-bots"`
4142
}
4243

4344
// ConfigNetwork holds configs for network communication
@@ -144,6 +145,10 @@ func DefaultConfig() (c Config) {
144145
c.Game.DefaultGeometry[DivB].PlacementOffsetTouchLine = 0.2
145146
c.Game.DefaultGeometry[DivB].PlacementOffsetDefenseArea = 1.0
146147

148+
c.Game.MaxBots = map[Division]int{}
149+
c.Game.MaxBots[DivA] = 8
150+
c.Game.MaxBots[DivB] = 6
151+
147152
return
148153
}
149154

internal/app/controller/engine.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@ func NewEngine(config ConfigGame) (e Engine) {
3232

3333
func (e *Engine) ResetGame() {
3434
e.State = NewState()
35-
e.State.TeamState[TeamBlue].TimeoutTimeLeft = e.config.Normal.TimeoutDuration
36-
e.State.TeamState[TeamYellow].TimeoutTimeLeft = e.config.Normal.TimeoutDuration
37-
e.State.TeamState[TeamBlue].TimeoutsLeft = e.config.Normal.Timeouts
38-
e.State.TeamState[TeamYellow].TimeoutsLeft = e.config.Normal.Timeouts
35+
for _, team := range []Team{TeamBlue, TeamYellow} {
36+
e.State.TeamState[team].TimeoutTimeLeft = e.config.Normal.TimeoutDuration
37+
e.State.TeamState[team].TimeoutsLeft = e.config.Normal.Timeouts
38+
e.State.TeamState[team].MaxAllowedBots = e.config.MaxBots[e.State.Division]
39+
}
40+
3941
e.RefereeEvents = []RefereeEvent{}
4042
e.State.Division = e.config.DefaultDivision
4143
e.Geometry = *e.config.DefaultGeometry[e.State.Division]
@@ -177,10 +179,20 @@ func (e *Engine) Process(event Event) error {
177179
if err != nil {
178180
return err
179181
}
182+
e.updateMaxBots()
180183
e.appendHistory()
181184
return nil
182185
}
183186

187+
func (e *Engine) updateMaxBots() {
188+
for _, team := range []Team{TeamBlue, TeamYellow} {
189+
max := e.config.MaxBots[e.State.Division]
190+
yellowCards := len(e.State.TeamState[team].YellowCardTimes)
191+
redCards := e.State.TeamState[team].RedCards
192+
e.State.TeamState[team].MaxAllowedBots = max - yellowCards - redCards
193+
}
194+
}
195+
184196
func (e *Engine) appendHistory() {
185197
e.History = append(e.History, HistoryEntry{*e.State, e.RefereeEvents})
186198
if len(e.History) > maxHistorySize {
@@ -288,6 +300,7 @@ func (e *Engine) updateTimes(delta time.Duration) {
288300
for team, teamState := range e.State.TeamState {
289301
reduceYellowCardTimes(teamState, delta)
290302
e.removeElapsedYellowCards(team, teamState)
303+
e.updateMaxBots()
291304
}
292305
}
293306

internal/app/controller/publisher.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ func initTeamInfo(t *refproto.Referee_TeamInfo) {
7171
t.FoulCounter = new(uint32)
7272
t.BallPlacementFailures = new(uint32)
7373
t.CanPlaceBall = new(bool)
74+
t.MaxAllowedBots = new(uint32)
7475
}
7576

7677
// Publish the state and command
@@ -203,6 +204,7 @@ func updateTeam(team *refproto.Referee_TeamInfo, state *TeamInfo) {
203204
*team.FoulCounter = uint32(state.FoulCounter)
204205
*team.BallPlacementFailures = uint32(state.BallPlacementFailures)
205206
*team.CanPlaceBall = state.CanPlaceBall
207+
*team.MaxAllowedBots = uint32(state.MaxAllowedBots)
206208
}
207209

208210
func mapTimes(durations []time.Duration) []uint32 {

internal/app/controller/state.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ type TeamInfo struct {
241241
FoulCounter int `json:"foulCounter"`
242242
BallPlacementFailures int `json:"ballPlacementFailures"`
243243
CanPlaceBall bool `json:"canPlaceBall"`
244+
MaxAllowedBots int `json:"maxAllowedBots"`
244245
}
245246

246247
// State of the game
@@ -317,6 +318,7 @@ func newTeamInfo() (t TeamInfo) {
317318
t.FoulCounter = 0
318319
t.BallPlacementFailures = 0
319320
t.CanPlaceBall = true
321+
t.MaxAllowedBots = 0
320322
return
321323
}
322324

pkg/refproto/ssl_referee.pb.go

Lines changed: 75 additions & 65 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/refproto/ssl_referee.proto

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ message Referee {
145145
optional uint32 ball_placement_failures = 10;
146146
// Indicate if the team is able and allowed to place the ball
147147
optional bool can_place_ball = 12;
148+
// The maximum number of bots allowed on the field based on division and cards
149+
optional uint32 max_allowed_bots = 13;
148150
}
149151

150152
// Information about the two teams.

src/components/team/TeamOverview.vue

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@
4444
<TeamBallPlacement
4545
:team-color="teamColor"/>
4646
</div>
47+
<div>
48+
Max <b>{{maxAllowedBots}}</b> bots allowed on the field
49+
</div>
4750
</div>
4851
</div>
4952
</template>
@@ -78,9 +81,12 @@
7881
teamColor: String
7982
},
8083
computed: {
81-
team: function () {
84+
team() {
8285
return this.$store.state.refBoxState.teamState[this.teamColor]
8386
},
87+
maxAllowedBots() {
88+
return this.team.maxAllowedBots;
89+
}
8490
}
8591
}
8692
</script>

src/store.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export class TeamState {
1616
foulCounter = 0;
1717
ballPlacementFailures = 0;
1818
canPlaceBall = true;
19+
maxAllowedBots = 0;
1920
}
2021

2122
export class RefBoxState {

0 commit comments

Comments
 (0)