Skip to content

Commit 4b64278

Browse files
committed
Always add all non-GC game events to proposal groups
1 parent 24781a4 commit 4b64278

18 files changed

+259
-241
lines changed

frontend/src/components/match/GameEventProposalGroupItem.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type {GameEvent} from "@/proto/ssl_gc_game_event";
88
99
const props = defineProps<{
1010
proposalGroup: ProposalGroup,
11-
groupId: number,
11+
groupId: string,
1212
}>()
1313
1414
const control = inject<ControlApi>('control-api')

frontend/src/components/match/GameEventProposalGroupItemList.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ const proposalGroups = computed(() => {
1414
<q-list bordered class="rounded-borders" v-if="proposalGroups.length > 0">
1515
<GameEventProposalGroupItem
1616
:proposal-group="group"
17-
:group-id="groupId"
18-
v-for="(group, groupId) in proposalGroups"
19-
:key="groupId"
17+
:group-id="group.id || ''"
18+
v-for="(group) in proposalGroups"
19+
:key="group.id"
2020
/>
2121
</q-list>
2222
<div v-else>

frontend/src/proto/ssl_gc_change.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export interface Change_AddProposal {
112112
/** Accept a proposal group (that contain one or more proposals of the same type) */
113113
export interface Change_AcceptProposalGroup {
114114
/** The id of the group */
115-
groupId?: number;
115+
groupId?: string;
116116
/** An identifier of the acceptor */
117117
acceptedBy?: string;
118118
}
@@ -449,14 +449,14 @@ export const Change_AddProposal = {
449449
export const Change_AcceptProposalGroup = {
450450
fromJSON(object: any): Change_AcceptProposalGroup {
451451
return {
452-
groupId: isSet(object.groupId) ? Number(object.groupId) : 0,
452+
groupId: isSet(object.groupId) ? String(object.groupId) : "",
453453
acceptedBy: isSet(object.acceptedBy) ? String(object.acceptedBy) : "",
454454
};
455455
},
456456

457457
toJSON(message: Change_AcceptProposalGroup): unknown {
458458
const obj: any = {};
459-
message.groupId !== undefined && (obj.groupId = Math.round(message.groupId));
459+
message.groupId !== undefined && (obj.groupId = message.groupId);
460460
message.acceptedBy !== undefined && (obj.acceptedBy = message.acceptedBy);
461461
return obj;
462462
},

frontend/src/proto/ssl_gc_referee_message.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -478,8 +478,10 @@ export interface Referee_Point {
478478

479479
/** List of matching proposals */
480480
export interface GameEventProposalGroup {
481-
/** The proposed game event. */
482-
gameEvent?: GameEvent[];
481+
/** Unique ID of this group */
482+
id?: string;
483+
/** The proposed game events */
484+
gameEvents?: GameEvent[];
483485
/** Whether the proposal group was accepted */
484486
accepted?: boolean;
485487
}
@@ -613,17 +615,19 @@ export const Referee_Point = {
613615
export const GameEventProposalGroup = {
614616
fromJSON(object: any): GameEventProposalGroup {
615617
return {
616-
gameEvent: Array.isArray(object?.gameEvent) ? object.gameEvent.map((e: any) => GameEvent.fromJSON(e)) : [],
618+
id: isSet(object.id) ? String(object.id) : "",
619+
gameEvents: Array.isArray(object?.gameEvents) ? object.gameEvents.map((e: any) => GameEvent.fromJSON(e)) : [],
617620
accepted: isSet(object.accepted) ? Boolean(object.accepted) : false,
618621
};
619622
},
620623

621624
toJSON(message: GameEventProposalGroup): unknown {
622625
const obj: any = {};
623-
if (message.gameEvent) {
624-
obj.gameEvent = message.gameEvent.map((e) => e ? GameEvent.toJSON(e) : undefined);
626+
message.id !== undefined && (obj.id = message.id);
627+
if (message.gameEvents) {
628+
obj.gameEvents = message.gameEvents.map((e) => e ? GameEvent.toJSON(e) : undefined);
625629
} else {
626-
obj.gameEvent = [];
630+
obj.gameEvents = [];
627631
}
628632
message.accepted !== undefined && (obj.accepted = message.accepted);
629633
return obj;

frontend/src/proto/ssl_gc_state.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,12 @@ export interface Proposal {
204204
}
205205

206206
export interface ProposalGroup {
207-
/** List of proposals in this group */
207+
/** Unique ID of this group */
208+
id?: string;
209+
/** The proposals in this group */
208210
proposals?: Proposal[];
209211
/** Whether the proposal group was accepted */
210212
accepted?: boolean;
211-
/** unique id of the proposal group */
212-
id?: number;
213213
}
214214

215215
export interface TeamInfo {
@@ -376,21 +376,21 @@ export const Proposal = {
376376
export const ProposalGroup = {
377377
fromJSON(object: any): ProposalGroup {
378378
return {
379+
id: isSet(object.id) ? String(object.id) : "",
379380
proposals: Array.isArray(object?.proposals) ? object.proposals.map((e: any) => Proposal.fromJSON(e)) : [],
380381
accepted: isSet(object.accepted) ? Boolean(object.accepted) : false,
381-
id: isSet(object.id) ? Number(object.id) : 0,
382382
};
383383
},
384384

385385
toJSON(message: ProposalGroup): unknown {
386386
const obj: any = {};
387+
message.id !== undefined && (obj.id = message.id);
387388
if (message.proposals) {
388389
obj.proposals = message.proposals.map((e) => e ? Proposal.toJSON(e) : undefined);
389390
} else {
390391
obj.proposals = [];
391392
}
392393
message.accepted !== undefined && (obj.accepted = message.accepted);
393-
message.id !== undefined && (obj.id = Math.round(message.id));
394394
return obj;
395395
},
396396
};

frontend/src/providers/controlApi/ControlApi.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export class ControlApi {
8282
})
8383
}
8484

85-
public AcceptProposalGroup(groupId: number) {
85+
public AcceptProposalGroup(groupId: string) {
8686
this.SubmitChange({
8787
change: {
8888
$case: 'acceptProposalGroupChange',

internal/app/engine/engine.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -179,13 +179,12 @@ func convertAimlessKick(gameEvent *state.GameEvent) *state.GameEvent {
179179
func (e *Engine) handleGameEventBehavior(change *statemachine.Change) *statemachine.Change {
180180
gameEvent := change.GetAddGameEventChange().GameEvent
181181
behavior := e.config.GameEventBehavior[gameEvent.Type.String()]
182-
if isNonMajorityOrigin(gameEvent.Origin) && behavior == Config_BEHAVIOR_ACCEPT_MAJORITY {
183-
behavior = Config_BEHAVIOR_ACCEPT
184-
}
182+
185183
switch behavior {
186-
case Config_BEHAVIOR_ACCEPT, Config_BEHAVIOR_UNKNOWN:
187-
return change
188-
case Config_BEHAVIOR_ACCEPT_MAJORITY, Config_BEHAVIOR_PROPOSE_ONLY:
184+
case Config_BEHAVIOR_ACCEPT, Config_BEHAVIOR_ACCEPT_MAJORITY, Config_BEHAVIOR_PROPOSE_ONLY:
185+
if isNonMajorityOrigin(gameEvent.Origin) {
186+
return change
187+
}
189188
log.Println("Convert game event to proposal: ", gameEvent.String())
190189
timestamp := timestamppb.New(e.timeProvider())
191190
return &statemachine.Change{
@@ -209,10 +208,10 @@ func (e *Engine) handleGameEventBehavior(change *statemachine.Change) *statemach
209208
},
210209
},
211210
}
212-
case Config_BEHAVIOR_IGNORE:
213-
log.Printf("Ignoring game event: %v", gameEvent)
211+
default:
212+
log.Printf("Ignoring game event: %v (behavior: %v)", gameEvent, behavior)
213+
return nil
214214
}
215-
return nil
216215
}
217216

218217
// getGeometry returns the current geometry

internal/app/engine/process_proposals.go

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,46 +7,48 @@ import (
77
"math"
88
)
99

10-
const maxProposals = 5
11-
1210
func (e *Engine) processProposals() {
1311
for _, group := range e.currentState.ProposalGroups {
1412
latestGameEvent := group.Proposals[len(group.Proposals)-1].GameEvent
13+
behavior := e.config.GameEventBehavior[latestGameEvent.Type.String()]
1514
if *group.Accepted ||
1615
e.groupIsStillAcceptingProposals(group) ||
17-
e.config.GameEventBehavior[latestGameEvent.Type.String()] == Config_BEHAVIOR_PROPOSE_ONLY {
16+
behavior == Config_BEHAVIOR_PROPOSE_ONLY {
1817
continue
1918
}
20-
numProposals := uniqueOrigins(group)
19+
numProposals := e.uniqueAcceptingOrigins(group)
2120
numAutoRefs := e.numAutoRefs(latestGameEvent)
2221
majority := int(math.Floor(float64(numAutoRefs) / 2.0))
2322

24-
if numProposals > majority {
23+
var acceptedBy string
24+
if behavior == Config_BEHAVIOR_ACCEPT {
25+
acceptedBy = "Engine"
26+
} else if behavior == Config_BEHAVIOR_ACCEPT_MAJORITY && numProposals > majority {
2527
log.Printf("Majority of %v reached with %v out of %v for %v.", majority, numProposals, numAutoRefs, latestGameEvent.Type)
26-
acceptedBy := "Majority"
27-
e.Enqueue(&statemachine.Change{
28-
Origin: &changeOriginEngine,
29-
Change: &statemachine.Change_AcceptProposalGroupChange{
30-
AcceptProposalGroupChange: &statemachine.Change_AcceptProposalGroup{
31-
GroupId: group.Id,
32-
AcceptedBy: &acceptedBy,
33-
},
34-
},
35-
})
28+
acceptedBy = "Majority"
29+
} else {
30+
continue
3631
}
37-
}
3832

39-
diff := len(e.currentState.ProposalGroups) - maxProposals
40-
if diff > 0 {
41-
e.currentState.ProposalGroups = e.currentState.ProposalGroups[diff:]
33+
e.Enqueue(&statemachine.Change{
34+
Origin: &changeOriginEngine,
35+
Change: &statemachine.Change_AcceptProposalGroupChange{
36+
AcceptProposalGroupChange: &statemachine.Change_AcceptProposalGroup{
37+
GroupId: group.Id,
38+
AcceptedBy: &acceptedBy,
39+
},
40+
},
41+
})
4242
}
4343
}
4444

45-
func uniqueOrigins(group *state.ProposalGroup) int {
45+
func (e *Engine) uniqueAcceptingOrigins(group *state.ProposalGroup) int {
4646
origins := map[string]bool{}
4747
for _, p := range group.Proposals {
4848
for _, o := range p.GameEvent.Origin {
49-
origins[o] = true
49+
if e.config.AutoRefConfigs[o].GameEventBehavior[p.GameEvent.Type.String()] == AutoRefConfig_BEHAVIOR_ACCEPT {
50+
origins[o] = true
51+
}
5052
}
5153
}
5254
return len(origins)

internal/app/publish/datamapper.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ func mapProposals(groups []*state.ProposalGroup) []*state.GameEventProposalGroup
1111
var mappedGroups []*state.GameEventProposalGroup
1212
for _, group := range groups {
1313
mappedGroup := state.GameEventProposalGroup{Accepted: group.Accepted}
14-
mappedGroup.GameEvent = []*state.GameEvent{}
14+
mappedGroup.GameEvents = []*state.GameEvent{}
1515
for _, proposal := range group.Proposals {
16-
mappedGroup.GameEvent = append(mappedGroup.GameEvent, proposal.GameEvent)
16+
mappedGroup.GameEvents = append(mappedGroup.GameEvents, proposal.GameEvent)
1717
}
1818
mappedGroups = append(mappedGroups, &mappedGroup)
1919
}

internal/app/state/ssl_gc_referee_message.pb.go

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

0 commit comments

Comments
 (0)