Global-1 to Codename+200

main
Bel LaPointe 2024-12-15 18:25:47 -07:00
parent 02dc21c124
commit 15078a626d
5 changed files with 46 additions and 46 deletions

View File

@ -187,7 +187,7 @@ type (
}
KillWords struct {
Global KillWord
Codename KillWord
Assigned time.Time
Assignee string
@ -478,7 +478,7 @@ func (games Games) CreateEventGameReset(ctx context.Context, gid string) error {
}
func (words KillWords) Empty() bool {
return words.Global == (KillWord{}) && words.Assigned.IsZero() && words.Assignee == "" && words.Assignment.Empty()
return words.Codename == (KillWord{}) && words.Assigned.IsZero() && words.Assignee == "" && words.Assignment.Empty()
}
func (words KillWords) Privates() []KillWord {
@ -549,7 +549,7 @@ func (m AllKillWords) withoutAssignees() AllKillWords {
result := make(AllKillWords)
for k := range m {
result[k] = KillWords{
Global: m[k].Global,
Codename: m[k].Codename,
Assigned: now,
Assignee: "",
Assignment: m[k].Assignment,
@ -598,7 +598,7 @@ func (m AllKillWords) FillKillWords() AllKillWords {
}
func (m AllKillWords) fillKillWords(
poolGlobal []string,
poolCodename []string,
nPublic int,
poolPublic []string,
nPrivate int,
@ -607,8 +607,8 @@ func (m AllKillWords) fillKillWords(
result := maps.Clone(m)
m = result
for k, v := range m {
if v.Global.Word == "" {
v.Global = KillWord{Word: m.unusedGlobal(poolGlobal), Points: -1}
if v.Codename.Word == "" {
v.Codename = KillWord{Word: m.unusedCodename(poolCodename), Points: 200}
m[k] = v
}
if len(v.Assignment.Public) == 0 {
@ -629,11 +629,11 @@ func (m AllKillWords) fillKillWords(
return m
}
func (m AllKillWords) unusedGlobal(pool []string) string {
func (m AllKillWords) unusedCodename(pool []string) string {
inUse := func() []string {
result := []string{}
for _, killWords := range m {
result = append(result, killWords.Global.Word)
result = append(result, killWords.Codename.Word)
}
return result
}

View File

@ -128,8 +128,8 @@ func TestGames(t *testing.T) {
if v.Players[p].Points() != 0 {
t.Error("nonzero points after zero kills:", v.Players[p].Points())
}
if v.Players[p].KillWords.Global.Word == "" {
t.Error(p, "no killwords.global")
if v.Players[p].KillWords.Codename.Word == "" {
t.Error(p, "no killwords.Codename")
} else if v.Players[p].KillWords.Assigned.IsZero() {
t.Error(p, "no killwords.assigned")
} else if v.Players[p].KillWords.Assignee == "" {
@ -199,9 +199,9 @@ func TestParseEvent(t *testing.T) {
},
AllKillWords: map[string]KillWords{
"x": KillWords{
Global: KillWord{
Codename: KillWord{
Word: "a",
Points: -1,
Points: 200,
},
Assignee: "z",
Assigned: now,
@ -260,48 +260,48 @@ func TestAllKillWordsFill(t *testing.T) {
}{
"full": {
given: KillWords{
Global: kw(-1, "global"),
Codename: kw(200, "global"),
Assignment: ass("pub", "pri"),
},
expect: KillWords{
Global: kw(-1, "global"),
Codename: kw(200, "global"),
Assignment: ass("pub", "pri"),
},
},
"no ass": {
given: KillWords{
Global: kw(-1, "global"),
Codename: kw(200, "global"),
Assignment: Assignment{},
},
expect: KillWords{
Global: kw(-1, "global"),
Codename: kw(200, "global"),
Assignment: ass("filled-public", "filled-private"),
},
},
"no pub": {
given: KillWords{
Global: kw(-1, "global"),
Codename: kw(200, "global"),
Assignment: ass("", "pri"),
},
expect: KillWords{
Global: kw(-1, "global"),
Codename: kw(200, "global"),
Assignment: ass("filled-public", "pri"),
},
},
"no pri": {
given: KillWords{
Global: kw(-1, "global"),
Codename: kw(200, "global"),
Assignment: ass("pub", ""),
},
expect: KillWords{
Global: kw(-1, "global"),
Codename: kw(200, "global"),
Assignment: ass("pub", "filled-private"),
},
},
"empty": {
given: KillWords{},
expect: KillWords{
Global: kw(-1, "filled-global"),
Codename: kw(200, "filled-global"),
Assignment: ass("filled-public", "filled-private"),
},
},
@ -310,7 +310,7 @@ func TestAllKillWordsFill(t *testing.T) {
Assignment: ass("pub", "pri"),
},
expect: KillWords{
Global: kw(-1, "filled-global"),
Codename: kw(200, "filled-global"),
Assignment: ass("pub", "pri"),
},
},
@ -354,7 +354,7 @@ func TestAllKillWordsUnused(t *testing.T) {
t.Error("empty playerbase didnt think only option was unused")
}
if got := akw.unusedGlobal([]string{"x"}); got != "x" {
if got := akw.unusedCodename([]string{"x"}); got != "x" {
t.Error("empty playerbase didnt think only option was unused")
}
})
@ -363,7 +363,7 @@ func TestAllKillWordsUnused(t *testing.T) {
t.Run("private", func(t *testing.T) {
akw := make(AllKillWords)
akw["k"] = KillWords{
Global: KillWord{Word: "x"},
Codename: KillWord{Word: "x"},
Assignment: Assignment{
Private: []KillWord{{}, {Word: "y"}},
Public: []KillWord{{}, {Word: "x"}},
@ -377,13 +377,13 @@ func TestAllKillWordsUnused(t *testing.T) {
t.Run("global", func(t *testing.T) {
akw := make(AllKillWords)
akw["k"] = KillWords{
Global: KillWord{Word: "y"},
Codename: KillWord{Word: "y"},
Assignment: Assignment{
Private: []KillWord{{}, {Word: "x"}},
Public: []KillWord{{}, {Word: "x"}},
},
}
got := akw.unusedGlobal([]string{"x", "y"})
got := akw.unusedCodename([]string{"x", "y"})
if got != "x" {
t.Error("didnt return only unused option")
}
@ -391,7 +391,7 @@ func TestAllKillWordsUnused(t *testing.T) {
t.Run("public", func(t *testing.T) {
akw := make(AllKillWords)
akw["k"] = KillWords{
Global: KillWord{Word: "x"},
Codename: KillWord{Word: "x"},
Assignment: Assignment{
Private: []KillWord{{}, {Word: "x"}},
Public: []KillWord{{}, {Word: "y"}},

View File

@ -95,8 +95,8 @@ func (ugs *UserGameServer) listen(ctx context.Context, reader func(context.Conte
var points int
if gameState, err := ugs.games.GameState(ctx, ugs.ID); err != nil {
return err
} else if global := gameState.Players[killer].KillWords.Global; global.Word == word {
points = global.Points
} else if codename := gameState.Players[killer].KillWords.Codename; codename.Word == word {
points = codename.Points
} else if matches := slices.DeleteFunc(gameState.Players[victim].KillWords.Publics(), func(kw KillWord) bool { return kw.Word != word }); len(matches) > 0 {
points = matches[0].Points
} else if matches := slices.DeleteFunc(gameState.Players[victim].KillWords.Privates(), func(kw KillWord) bool { return kw.Word != word }); len(matches) > 0 {
@ -151,7 +151,7 @@ func (ugs *UserGameServer) State(ctx context.Context) (UserGameState, error) {
if isSelf := k == ugs.Session.ID; isSelf {
v.KillWords.Assignment = Assignment{}
} else {
v.KillWords.Global = KillWord{}
v.KillWords.Codename = KillWord{}
v.KillWords.Assignee = ""
for i := range v.Kills {
v.Kills[i].Victim = ""

View File

@ -83,8 +83,8 @@ func TestUserGameServer(t *testing.T) {
}
if isSelf := pid == ugs.Session.ID; isSelf {
if p.KillWords.Global.Word == "" || p.KillWords.Global.Points == 0 {
t.Error("self global missing field")
if p.KillWords.Codename.Word == "" || p.KillWords.Codename.Points == 0 {
t.Error("self codename missing field")
}
if p.KillWords.Assignee == "" {
t.Error("assignee is empty")
@ -96,8 +96,8 @@ func TestUserGameServer(t *testing.T) {
t.Error("self knows its own private")
}
} else {
if !p.KillWords.Global.Empty() {
t.Error("can see not self global")
if !p.KillWords.Codename.Empty() {
t.Error("can see not self Codename")
}
if p.KillWords.Assignee != "" {
t.Error("can see other player's assignee")
@ -167,8 +167,8 @@ func TestUserGameServer(t *testing.T) {
} else if kill.KillWord.Word == "" {
t.Errorf("dont know own kill word")
}
if p.KillWords.Global.Word == "" || p.KillWords.Global.Points == 0 {
t.Error("self global missing field")
if p.KillWords.Codename.Word == "" || p.KillWords.Codename.Points == 0 {
t.Error("self Codename missing field")
}
if p.KillWords.Assignee == "" {
t.Error("assignee is empty")
@ -190,8 +190,8 @@ func TestUserGameServer(t *testing.T) {
} else if kill.KillWord.Word != "" {
t.Errorf("know other's kill word")
}
if !p.KillWords.Global.Empty() {
t.Error("can see not self global")
if !p.KillWords.Codename.Empty() {
t.Error("can see not self Codename")
}
if p.KillWords.Assignee != "" {
t.Error("can see other player's assignee")
@ -248,8 +248,8 @@ func TestUserGameServer(t *testing.T) {
} else if kill.KillWord.Word == "" {
t.Errorf("dont know own kill word")
}
if p.KillWords.Global.Word == "" || p.KillWords.Global.Points == 0 {
t.Error("self global missing field")
if p.KillWords.Codename.Word == "" || p.KillWords.Codename.Points == 0 {
t.Error("self Codename missing field")
}
if p.KillWords.Assignee == "" {
t.Error("assignee is empty")
@ -271,8 +271,8 @@ func TestUserGameServer(t *testing.T) {
} else if kill.KillWord.Word == "" {
t.Errorf("dont know other's kill word")
}
if p.KillWords.Global.Empty() {
t.Error("cannot see not self global")
if p.KillWords.Codename.Empty() {
t.Error("cannot see not self Codename")
}
if p.KillWords.Assignee == "" {
t.Error("cannot see other player's assignee")

View File

@ -191,10 +191,10 @@ func (ws WS) inProgressMsgItem(ctx context.Context, ugs *UserGameServer, gameSta
tags := []inProgressMsgItemTag{}
if hasBeenKilledWithGlobal := slices.ContainsFunc(self.Kills, func(a Kill) bool {
return a.Victim == uid && a.KillWord.Word == self.KillWords.Global.Word
}); !hasBeenKilledWithGlobal {
tags = append(tags, newInProgressMsgItemTag(self.KillWords.Global))
if hasBeenKilledWithCodename := slices.ContainsFunc(self.Kills, func(a Kill) bool {
return a.Victim == uid && a.KillWord.Word == self.KillWords.Codename.Word
}); !hasBeenKilledWithCodename {
tags = append(tags, newInProgressMsgItemTag(self.KillWords.Codename))
}
for _, killWord := range append(