Skip to content

Commit 0ae85bc

Browse files
committed
add control for toggling 2nd strategy.
1 parent 02942bc commit 0ae85bc

3 files changed

Lines changed: 65 additions & 5 deletions

File tree

play/js/Presets.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ kindayee: "can",
390390
candidates: 5,
391391
voters: 1,
392392
doFullStrategyConfig: true,
393-
doPercentFirst: true,
393+
doPercentFirst: false,
394394
arena_size: 600,
395395
arena_border: 0,
396396
spread_factor_voters: 2

play/js/Voters.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,7 @@ function GaussianVoters(config){ // this config comes from addVoters in main_san
636636
};
637637

638638
self.percentStrategy = config.percentStrategy
639+
self.second_strategy = config.second_strategy
639640
self.group_count = config.group_count
640641
self.group_spread = config.group_spread
641642
self.strategy = config.strategy
@@ -729,7 +730,7 @@ if (!self.x_voters) {
729730
var y = self.y + p[1];
730731

731732
var r1 = Math.random() * 100;
732-
if (r1 < self.percentStrategy) {
733+
if (r1 < self.percentStrategy && self.second_strategy) {
733734
var strategy = self.strategy // yes
734735
} else {
735736
var strategy = self.unstrategic; // no e.g. "zero strategy. judge on an absolute scale."
@@ -791,6 +792,7 @@ function SingleVoter(config){
791792
self.snowman = false;
792793
self.x_voters = false;
793794
self.percentStrategy = config.percentStrategy
795+
self.second_strategy = config.second_strategy
794796
self.group_count = config.group_count
795797
self.group_spread = config.group_spread
796798
self.strategy = config.strategy

play/js/main_sandbox.js

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function main(config){
3333
}
3434

3535
var initialConfig
36-
var allnames = ["systems","voters","custom_number_voters","group_count","group_spread","candidates","strategy","percentstrategy","unstrategic","frontrunners","poll","yee"]
36+
var allnames = ["systems","voters","custom_number_voters","group_count","group_spread","candidates","strategy","second strategy","percentstrategy","unstrategic","frontrunners","poll","yee"]
3737
var doms = {} // for hiding menus, later
3838
var stratsliders = [] // for hiding sliders, later
3939
var groupsliders = [] // for hiding sliders, later
@@ -68,7 +68,7 @@ function main(config){
6868
config.doPercentFirst = config.doPercentFirst || false;
6969
if (config.doPercentFirst) config.featurelist = config.featurelist.concat(["percentstrategy"]);
7070
config.doFullStrategyConfig = config.doFullStrategyConfig || false;
71-
if (config.doFullStrategyConfig) config.featurelist = config.featurelist.concat(["strategy","percentstrategy","unstrategic","frontrunners","poll","yee"])
71+
if (config.doFullStrategyConfig) config.featurelist = config.featurelist.concat(["unstrategic","second strategy","frontrunners","poll","yee"])
7272
// clear the grandfathered config settings
7373
config.doPercentFirst = undefined
7474
config.features = undefined
@@ -95,6 +95,7 @@ function main(config){
9595
}
9696

9797
config.unstrategic = config.unstrategic || "zero strategy. judge on an absolute scale.";
98+
config.second_strategy = config.second_strategy || false;
9899
config.keyyee = config.keyyee || "off";
99100
config.computeMethod = config.computeMethod || "ez";
100101
config.pixelsize = config.pixelsize || 30;
@@ -207,6 +208,7 @@ function main(config){
207208
group_spread: config.voter_group_spread[i],
208209
preFrontrunnerIds: config.preFrontrunnerIds,
209210
unstrategic: config.unstrategic,
211+
second_strategy: config.second_strategy,
210212
vid: i,
211213
snowman: config.snowman,
212214
x_voters: config.x_voters,
@@ -639,8 +641,8 @@ function main(config){
639641
// only the middle percent (for the yellow triangle)
640642

641643
// no reset...
644+
config.unstrategic = data.realname;
642645
for(var i=0;i<model.voters.length;i++){
643-
config.unstrategic = data.realname;
644646
model.voters[i].unstrategic = config.unstrategic
645647
}
646648
model.update();
@@ -656,6 +658,56 @@ function main(config){
656658
doms["unstrategic"] = chooseVoterStrategyOff.dom
657659

658660

661+
662+
663+
664+
// Is there a 2nd strategy?
665+
var second_strategy = [
666+
{realname: "opton for 2nd strategy", name:"+"}
667+
];
668+
var onChoose_second_strategy = function(data){
669+
670+
// update config and model
671+
var b = data.isOn
672+
config.second_strategy = b
673+
model.second_strategy = b
674+
for(var i=0;i<model.voters.length;i++){
675+
model.voters[i].second_strategy = b
676+
}
677+
model.update();
678+
679+
680+
// update gui
681+
var xlist = ["strategy","percentstrategy"]
682+
var featureset = new Set(config.featurelist)
683+
for (var i in xlist){
684+
var xi = xlist[i]
685+
if (data.isOn) {
686+
featureset.add(xi)
687+
doms[xi].hidden = false
688+
} else {
689+
featureset.delete(xi)
690+
doms[xi].hidden = true
691+
}
692+
}
693+
config.featurelist = Array.from(featureset)
694+
695+
696+
697+
};
698+
window.choose_second_strategy = new ButtonGroup({
699+
label: "",
700+
width: 40,
701+
data: second_strategy,
702+
onChoose: onChoose_second_strategy,
703+
isCheckbox: true
704+
});
705+
document.querySelector("#left").appendChild(choose_second_strategy.dom);
706+
doms["second strategy"] = choose_second_strategy.dom
707+
708+
709+
710+
659711

660712
// strategy
661713

@@ -1157,6 +1209,12 @@ function main(config){
11571209
}
11581210
}
11591211
if(window.chooseVoterStrategyOff) chooseVoterStrategyOff.highlight("realname", model.voters[0].unstrategic);
1212+
if(window.choose_second_strategy) {
1213+
if (config.second_strategy) {
1214+
choose_second_strategy.highlight("name", "+");
1215+
}
1216+
}
1217+
11601218
if(window.chooseFrun) chooseFrun.highlight("realname", model.preFrontrunnerIds);
11611219
if(stratsliders) {
11621220
for (i in stratsliders) {

0 commit comments

Comments
 (0)