From fab65a3dbc41accdd4782dfb67ac92544563ce11 Mon Sep 17 00:00:00 2001 From: Putnam Date: Tue, 17 Dec 2019 20:12:23 -0800 Subject: [PATCH] actually condorcet not IRV --- code/__DEFINES/citadel_defines.dm | 2 +- code/controllers/subsystem/ticker.dm | 2 +- code/controllers/subsystem/vote.dm | 41 +++++++++++----------------- 3 files changed, 18 insertions(+), 27 deletions(-) diff --git a/code/__DEFINES/citadel_defines.dm b/code/__DEFINES/citadel_defines.dm index 7cad6b5be7..55526eabc1 100644 --- a/code/__DEFINES/citadel_defines.dm +++ b/code/__DEFINES/citadel_defines.dm @@ -123,4 +123,4 @@ // Voting stuff (move this somewhere else eventually probs) #define PLURALITY_VOTING 0 #define APPROVAL_VOTING 1 -#define INSTANT_RUNOFF_VOTING 2 +#define RANKED_CHOICE_VOTING 2 diff --git a/code/controllers/subsystem/ticker.dm b/code/controllers/subsystem/ticker.dm index cbd7dfdd52..cad5798a4c 100755 --- a/code/controllers/subsystem/ticker.dm +++ b/code/controllers/subsystem/ticker.dm @@ -481,7 +481,7 @@ SUBSYSTEM_DEF(ticker) SSticker.modevoted = TRUE var/dynamic = CONFIG_GET(flag/dynamic_voting) if(dynamic) - SSvote.initiate_vote("dynamic","server",TRUE,INSTANT_RUNOFF_VOTING) + SSvote.initiate_vote("dynamic","server",TRUE,RANKED_CHOICE_VOTING) else SSvote.initiate_vote("roundtype","server",TRUE,PLURALITY_VOTING) diff --git a/code/controllers/subsystem/vote.dm b/code/controllers/subsystem/vote.dm index b8068215cf..42bd00d4af 100644 --- a/code/controllers/subsystem/vote.dm +++ b/code/controllers/subsystem/vote.dm @@ -86,30 +86,21 @@ SUBSYSTEM_DEF(vote) . += option return . -/datum/controller/subsystem/vote/proc/get_result_runoff() - var/already_lost_runoff = list() - for(var/n in 1 to choices.len) // if it takes more than this something REALLY wrong happened - for(var/ckey in voted) - choices[choices[voted[ckey][1]]]++ // jesus christ how horrifying - var/least_vote = 100000 - var/least_voted - for(var/i in 1 to choices.len) - var/option = choices[i] - if(choices[option] > voted.len/2) - message_admins("[option] has a majority, returning...") - return list(option) - else if(choices[option] < least_vote && !(option in already_lost_runoff)) - least_vote = choices[option] - least_voted = i - message_admins("[choices[least_voted]] lost the runoff, running again...") - already_lost_runoff += choices[least_voted] - for(var/ckey in voted) - voted[ckey] -= least_voted - for(var/option in choices) - choices[option] = 0 +/datum/controller/subsystem/vote/proc/calculate_condorcet_votes() + for(var/ckey in voted) + var/list/this_vote = voted[ckey] + for(var/a in 1 to choices.len) + for(var/b in a+1 to choices.len) + var/vote_sgn = SIGN(this_vote.Find(a)-this_vote.Find(b)) + if(vote_sgn==-1) + choices[choices[a]]++ + else if(vote_sgn==1) + choices[choices[b]]++ /datum/controller/subsystem/vote/proc/announce_result() - var/list/winners = vote_system == INSTANT_RUNOFF_VOTING ? get_result_runoff() : get_result() + if(vote_system == RANKED_CHOICE_VOTING) + calculate_condorcet_votes() + var/list/winners = get_result() var/text var/was_roundtype_vote = mode == "roundtype" || mode == "dynamic" if(winners.len > 0) @@ -233,7 +224,7 @@ SUBSYSTEM_DEF(vote) voted[usr.ckey] = list(vote) choices[choices[vote]]++ return vote - if(INSTANT_RUNOFF_VOTING) + if(RANKED_CHOICE_VOTING) if(usr.ckey in voted) if(vote in voted[usr.ckey]) voted[usr.ckey] -= vote @@ -346,7 +337,7 @@ SUBSYSTEM_DEF(vote) . += "

Vote one.

" if(APPROVAL_VOTING) . += "

Vote any number of choices.

" - if(INSTANT_RUNOFF_VOTING) + if(RANKED_CHOICE_VOTING) . += "

Vote by order of preference. Revoting will demote to the bottom.

" . += "Time Left: [time_remaining] s