diff --git a/cmd/server/games.go b/cmd/server/games.go index d7b4459..e1c1c8a 100644 --- a/cmd/server/games.go +++ b/cmd/server/games.go @@ -381,12 +381,10 @@ func (games Games) CreateEventAssignmentRotation(ctx context.Context, id string, func (prev AllKillWords) ShuffleAssignees(killer, victim, word string) AllKillWords { m := prev.withoutAssignees() - if killerState, ok := prev[killer]; !ok { + if _, ok := prev[killer]; !ok { } else if victimState, ok := prev[victim]; !ok { } else { - v := m[killer] - v.Assignee = victimState.Assignee - m[killer] = v + m.assign(killer, victimState.Assignee) } for !func() bool { @@ -399,14 +397,20 @@ func (prev AllKillWords) ShuffleAssignees(killer, victim, word string) AllKillWo } for k, v := range allKillWords { - assignee := pop() - if k == assignee || prev[k].Assignee == assignee { + if v.Assignee != "" { + continue + } + v.Assignee = pop() + if k == v.Assignee || prev[k].Assignee == v.Assignee { return false } - v.Assignee = assignee allKillWords[k] = v } + if len(unassigned) > 0 { + panic(unassigned) + } + m = allKillWords return true }() { @@ -415,6 +419,12 @@ func (prev AllKillWords) ShuffleAssignees(killer, victim, word string) AllKillWo return m } +func (m AllKillWords) assign(killer, victim string) { + v := m[killer] + v.Assignee = victim + m[killer] = v +} + func (m AllKillWords) withoutAssignees() AllKillWords { now := time.Now() result := make(AllKillWords)