Skip to content

Commit da06291

Browse files
committed
Implement team advantage response for not stopping game
1 parent b4cc64b commit da06291

17 files changed

+831
-242
lines changed

cmd/ssl-team-client/main.go

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"flag"
77
"github.com/RoboCup-SSL/ssl-game-controller/internal/app/rcon"
88
"github.com/RoboCup-SSL/ssl-game-controller/internal/app/sslconn"
9+
"github.com/RoboCup-SSL/ssl-game-controller/internal/app/state"
910
"github.com/RoboCup-SSL/ssl-game-controller/pkg/client"
1011
"log"
1112
"net"
@@ -17,6 +18,7 @@ var autoDetectAddress = flag.Bool("autoDetectHost", true, "Automatically detect
1718
var refBoxAddr = flag.String("address", "localhost:10008", "Address to connect to")
1819
var privateKeyLocation = flag.String("privateKey", "", "A private key to be used to sign messages")
1920
var teamName = flag.String("teamName", "Test Team", "The name of the team as it is sent by the referee")
21+
var teamColor = flag.String("teamColor", "", "The color of the team as it is sent by the referee")
2022

2123
var privateKey *rsa.PrivateKey
2224

@@ -37,6 +39,8 @@ func main() {
3739
if host != "" {
3840
log.Print("Detected game-controller host: ", host)
3941
*refBoxAddr = client.GetConnectionString(*refBoxAddr, host)
42+
} else {
43+
log.Println("No host detected")
4044
}
4145
}
4246

@@ -55,12 +59,15 @@ func main() {
5559
c.reader = bufio.NewReaderSize(conn, 1)
5660

5761
c.register()
58-
for !c.sendDesiredKeeper(3) {
59-
time.Sleep(time.Second)
60-
}
62+
c.sendDesiredKeeper(3)
6163

6264
for {
63-
c.ReplyToChoices()
65+
for i := 0; i < 30; i++ {
66+
c.ReplyToChoices()
67+
time.Sleep(time.Millisecond * 100)
68+
}
69+
log.Print("Waiting")
70+
time.Sleep(time.Millisecond * 2000)
6471
}
6572
}
6673

@@ -75,11 +82,16 @@ func (c *Client) register() {
7582

7683
registration := rcon.TeamRegistration{}
7784
registration.TeamName = teamName
85+
86+
if color, validColor := state.Team_value[*teamColor]; validColor {
87+
registration.Team = new(state.Team)
88+
*registration.Team = state.Team(color)
89+
}
7890
if privateKey != nil {
7991
registration.Signature = &rcon.Signature{Token: reply.GetControllerReply().NextToken, Pkcs1V15: []byte{}}
8092
registration.Signature.Pkcs1V15 = client.Sign(privateKey, &registration)
8193
}
82-
log.Print("Sending registration")
94+
log.Print("Sending registration: ", registration.String())
8395
if err := sslconn.SendMessage(c.conn, &registration); err != nil {
8496
log.Fatal("Failed sending registration: ", err)
8597
}
@@ -110,14 +122,7 @@ func (c *Client) sendDesiredKeeper(id int32) (accepted bool) {
110122
}
111123

112124
func (c *Client) ReplyToChoices() {
113-
request := rcon.ControllerToTeam{}
114-
if err := sslconn.ReceiveMessage(c.reader, &request); err != nil {
115-
log.Fatal("Failed receiving controller request: ", err)
116-
}
117-
if request.GetAdvantageChoice() != nil {
118-
log.Printf("Received choice for: %v", *request.GetAdvantageChoice().Foul)
119-
}
120-
reply := rcon.TeamToController_AdvantageResponse_{AdvantageResponse: rcon.TeamToController_CONTINUE}
125+
reply := rcon.TeamToController_AdvantageResponse{AdvantageResponse: rcon.AdvantageResponse_CONTINUE}
121126
response := rcon.TeamToController{Msg: &reply}
122127
c.sendRequest(&response)
123128
}

config/ssl-game-controller.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ game:
5050
continue-from-halt: false
5151
challenge-flags: 3
5252
emergency-stop-grace-period: 10s
53+
advantage-response-timeout: 1s
5354
normal:
5455
half-duration: 5m
5556
half-time-duration: 5m

internal/app/config/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ type Game struct {
6262
ContinueFromHalt bool `yaml:"continue-from-halt"`
6363
ChallengeFlags int32 `yaml:"challenge-flags"`
6464
EmergencyStopGracePeriod time.Duration `yaml:"emergency-stop-grace-period"`
65+
AdvantageResponseTimeout time.Duration `yaml:"advantage-response-timeout"`
6566
}
6667

6768
// Network holds configs for network communication
@@ -193,6 +194,7 @@ func DefaultControllerConfig() (c Controller) {
193194
c.Game.AutoApproveGoals = false
194195
c.Game.ChallengeFlags = 3
195196
c.Game.EmergencyStopGracePeriod = 10 * time.Second
197+
c.Game.AdvantageResponseTimeout = 500 * time.Millisecond
196198

197199
c.Game.Normal.HalfDuration = 5 * time.Minute
198200
c.Game.Normal.HalfTimeDuration = 5 * time.Minute

internal/app/config/testdata/config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ game:
4949
continue-from-halt: false
5050
challenge-flags: 3
5151
emergency-stop-grace-period: 10s
52+
advantage-response-timeout: 1s
5253
normal:
5354
half-duration: 5m
5455
half-time-duration: 5m

internal/app/engine/engine.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,11 @@ func (e *Engine) GetConfig() *Config {
369369
return &cfg
370370
}
371371

372+
// GetLastTimeUpdate returns the current time
373+
func (e *Engine) GetLastTimeUpdate() time.Time {
374+
return e.lastTimeUpdate
375+
}
376+
372377
// UpdateConfig updates the current engine config with the given delta
373378
func (e *Engine) UpdateConfig(delta *Config) {
374379
e.mutex.Lock()

internal/app/engine/process_botremoved.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ func (e *Engine) processBotNumberPerTeam(team state.Team) {
4646
numBots := numRobotsOfTeam(e.gcState.TrackerStateGc.Robots, team)
4747
numBotsAllowed := *teamInfo.MaxAllowedBots + newCards
4848
if numBots > numBotsAllowed {
49+
50+
advantageResponse := e.gcState.TeamState[team.Opposite().String()].LastAdvantageResponse
51+
if *advantageResponse.Response == TeamAdvantageResponse_CONTINUE {
52+
return
53+
}
54+
4955
var ballPos *geom.Vector2
5056
if e.gcState.TrackerStateGc.Ball != nil {
5157
ballPos = e.gcState.TrackerStateGc.Ball.Pos.ToVector2()
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package engine
2+
3+
import "github.com/RoboCup-SSL/ssl-game-controller/internal/app/state"
4+
5+
var defaultResponse = TeamAdvantageResponse_STOP
6+
7+
func (e *Engine) processTeamAdvantageResponse() {
8+
9+
for _, team := range state.BothTeams() {
10+
advantageResponse := e.gcState.TeamState[team.String()].LastAdvantageResponse
11+
if advantageResponse == nil {
12+
e.gcState.TeamState[team.String()].LastAdvantageResponse = &TeamAdvantageResponse{
13+
Response: &defaultResponse,
14+
}
15+
} else if advantageResponse.Timestamp != nil {
16+
age := e.lastTimeUpdate.Sub(advantageResponse.Timestamp.AsTime())
17+
if age > e.gameConfig.AdvantageResponseTimeout {
18+
// reset
19+
advantageResponse.Timestamp = nil
20+
advantageResponse.Response = &defaultResponse
21+
}
22+
}
23+
}
24+
}

internal/app/engine/process_tick.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ func (e *Engine) processTick() {
6060
e.noProgressDetector.process()
6161
e.ballPlacementCoordinator.process()
6262
e.processContinue()
63+
e.processTeamAdvantageResponse()
6364
e.botNumberProcessor.processBotNumber()
6465
e.processPenalty()
6566
e.processProposals()

0 commit comments

Comments
 (0)