[I7] Help with voting mechanic

Inform 7 question here:

I’m trying to implement a voting sytem in a game where the player and NPCs can vote one another. I’ve got an inkling that I can do this using the relation property, but I’m hitting a dead end on how exactly.

Basically what I’ve got is something like:

Selection relates one person to one person. The verb to select (blah blah blah) implies the selection relation.

Voting is an action applying to one thing.

[some checks]

Carry out an actor voting a person (called the target):
now the target is selected by the actor.[/code]

But I’m not able to unpack the selecting relation in a useful way.

Essentially, what I want to be able to do is allow the player and the npcs vote for any player, accurately display who’s voting for who at the end of each turn, and trigger some events when a person receives enough votes.

Can anyone illuminate how I might begin to approach this?

If it were me, I’d do it with lists. Each character would have a list of who’s voted for them, and of course the number of votes in their favor is just the length of the list. But that may not be the most Inform way of doing it.

Maybe the problem is with declaring the selection relation as one-to-one? If you want someone to be able to get multiple votes it seems as though it should be a various-to-one relation.

…and there it is, it looks as though you can do most of what you want with the usual conjugations:

[code]Use the serial comma.

Selection relates various persons to one person. The verb to select [shouldn’t need the blah blah blah in 6L02] implies the selection relation.

Voting is an action applying to one thing.

Understand “vote for/-- [someone]” as voting.

[some checks]

Carry out an actor voting a person (called the target):
if the actor selects the target:
say “[The person asked] [reaffirm] [their] vote for [the target].”;
otherwise if the person asked selects someone:
say “[The person asked] [change] [their] vote to [the target].”;
say “[The person asked] [vote] for [the target].”;
now the actor selects the target.

To change is a verb. To vote is a verb. To reaffirm is a verb.

Convention is a room. Alice, Beezus, Connie, Delia, and Elizabeth are women in Convention. The player is Elizabeth.

Carry out examining:
say “Alice says, 'Oh! Someone who is worthy of such close scrutiny must be worthy of a vote!”;
try Alice voting the noun.

Before attacking:
say “Beezus says, ‘It is my duty to support the target of such unchecked aggression.’”;
try Beezus voting the noun.

First every turn:
repeat with the candidate running through persons:
say “[The candidate] [are] supported by [list of persons who select the candidate] for a total of [number of persons who select the candidate] vote[if the number of persons who select the candidate is not 1]s[end if].”

Every turn when someone (called the victor) is selected by three people:
say “[The victor] [are] acclaimed the victor.”;
end the story.

Test me with “x Alice/x Delia/vote Connie/vote Delia/hit Connie/hit Delia”.

Caveat: I understand that many-one relations can be expensive (or is it many-many ones?) Also, I put text in carry out rules; just too annoying to keep track of the previous vote in a test case. And “supported by nothing” is ugly but you know what to do there.

(EDIT: changed the example to keep an actual vote tally instead of using the “relations” command.}

Sorry to hijack this thread, but I’ve seen /-- used before, but I don’t know what it does exactly. So… what is it?

A slashed set of words means that any one of the words would be accepted. When – is one of the slashes it means that it’s optional to put a word there." So “vote for/-- [someone]” is just a shorter way of getting both “vote [someone]” and “vote for [someone].”

Ah that’s great Matt, thanks a lot! The many-to-one relationship was completely obvious only after it was pointed out.