From: Carl Worth Date: Mon, 29 Jun 2020 21:23:28 +0000 (-0700) Subject: empathy: Don't let any player give kudos to themself X-Git-Url: https://git.cworth.org/git?p=lmno-server;a=commitdiff_plain;h=99eb3c3fd206ca16e950f1a07e6f189db9cfdaba empathy: Don't let any player give kudos to themself Which would not be very sporting of course, so we don't allow it. Note that this restriction is applied after the majority-ruled matching. So a player can't even give kudos to a word they didn't submit and then hope to get matched into it. It's also worth noting that the group can decide to split a group where one player gave kudos. That will mean that both sides of the split get kudos from the player, which seems to match the kudos-giving player's intent. --- diff --git a/empathy.js b/empathy.js index 01836df..d6b007b 100644 --- a/empathy.js +++ b/empathy.js @@ -348,8 +348,12 @@ class Empathy extends Game { for (let group of word_groups) { const words = group.words; - if (group.kudos) - this.kudos[player.name] = [...words]; + if (group.kudos) { + this.kudos[player.name] = { + player: player, + words: [...words] + }; + } for (let i = 0; i < words.length - 1; i++) { for (let j = i + 1; j < words.length; j++) { @@ -526,12 +530,16 @@ class Empathy extends Game { /* Apply kudos from each player to the word maps, (using a set so * that no word_map can get multiple kudos from a single * player). */ - for (let player of Object.keys(this.kudos)) { - for (let word of this.kudos[player]) { + for (let kudos of Object.values(this.kudos)) { + for (let word of kudos.words) { const word_canon = this.canonize(word); if (! word_maps[word_canon]) continue; - word_maps[word_canon].kudos.add(player); + /* Don't let any player give kudos to a group where they + * submitted a word themself. That just wouldn't be right. */ + if (! word_maps[word_canon].players.has(kudos.player)) { + word_maps[word_canon].kudos.add(kudos.player); + } } } @@ -611,7 +619,7 @@ class Empathy extends Game { return { word: group.words.join('/'), players: Array.from(group.players).map(p => p.name), - kudos: Array.from(group.kudos) + kudos: Array.from(group.kudos).map(p => p.name) }; } );