Skip to content

Commit c1e1f89

Browse files
committed
Count proposal timeout from first proposal, not last
1 parent db5e917 commit c1e1f89

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

internal/app/engine/process_proposals.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,15 @@ import (
55
"github.com/RoboCup-SSL/ssl-game-controller/internal/app/statemachine"
66
"log"
77
"math"
8-
"time"
98
)
109

1110
const maxProposals = 5
1211

1312
func (e *Engine) processProposals() {
14-
15-
now := e.timeProvider()
16-
proposalTimeout := e.gameConfig.AutoRefProposalTimeout
17-
minTime := now.Add(-proposalTimeout)
18-
1913
for i, group := range e.currentState.ProposalGroups {
2014
latestGameEvent := group.Proposals[len(group.Proposals)-1].GameEvent
21-
if *group.Accepted || groupHasRecentProposal(group, minTime) ||
15+
if *group.Accepted ||
16+
e.groupIsStillAcceptingProposals(group) ||
2217
e.config.GameEventBehavior[latestGameEvent.Type.String()] == Config_BEHAVIOR_PROPOSE_ONLY {
2318
continue
2419
}
@@ -58,9 +53,13 @@ func uniqueOrigins(group *state.ProposalGroup) int {
5853
return len(origins)
5954
}
6055

61-
func groupHasRecentProposal(group *state.ProposalGroup, minTime time.Time) bool {
62-
latestProposal := group.Proposals[len(group.Proposals)-1]
63-
return goTime(latestProposal.Timestamp).Before(minTime)
56+
func (e *Engine) groupIsStillAcceptingProposals(group *state.ProposalGroup) bool {
57+
firstProposal := group.Proposals[0]
58+
59+
now := e.timeProvider()
60+
proposalTimeout := e.gameConfig.AutoRefProposalTimeout
61+
62+
return now.Sub(firstProposal.Timestamp.AsTime()) < proposalTimeout
6463
}
6564

6665
func (e *Engine) numAutoRefs(gameEvent *state.GameEvent) (n int) {

0 commit comments

Comments
 (0)