-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
161 lines (135 loc) · 5.68 KB
/
Copy pathindex.js
File metadata and controls
161 lines (135 loc) · 5.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
let fs = require('fs');
function shuffle(a) {
for(let i = a.length - 1; i > 0; i--){
const j = Math.floor(Math.random() * (i + 1));
[a[i], a[j]] = [a[j], a[i]];
}
return a;
}
let db = {
users: [],
friendships: [],
member_names: shuffle(["Python", "Ruby", "Brainf*ck", "JS", "Java", "R", "C", "Lua",
"C++", "C#", "F#", "Piet", "Matlab", "Haskell", "Assembly", "Smalltalk",
"Fortran", "COBOL", "Coffeescript", "Visual Basic", "Logo", "Shell", "Vimscript",
"Elixir", "Rust", "Go", "Groovy", "AspectJ", "PHP"])
};
if(fs.existsSync('db.json')){
db = JSON.parse(fs.readFileSync('db.json'));
}
act_names = ["Ethical Programming", "Assange Satisfaction", "AI Protection",
"Software Quality", "2038 Resolution", "Global Security"]
topic = ["Use of tabs in code", "Use of PC's in development", "Use of dynamically typed languages",
"Use of spaces for indentation in code", "Placing curly braces on a new line",
"Use of Macs in development", "Use of statically typed languages",
"Use of functional programming", "Use of comments", "Use of a gui in editing files",
"Use of gui git helpers", "Use of Object Orientated programming",
"Using console logging for debugging", "Coding classes that are larger than 100 lines",
"Writing lines that are longer than 80 characters", "Violation of PEP8 standards",
"Writing full stack JS", "Use of global variables", "Use of the singleton pattern",
"Use of Vue over React", "Use of React over Vue", "Use of NoSQL Databases"]
sanction = ["is punishible by death", "must be monitored by the government",
"is punishible by a jail sentence of 6 years",
"makes the programmer eligible for an honerary doctorate",
"is punishable by getting raided by Linus Torvolds",
"will be encouraged by government education programs",
"will be encouraged through $6 billion in marketing",
"is punishable by a fine $400", "is punishable by being exhiled from the state",
"will be encouraged by tax breaks", "must be traced by the ASIO",
"is punishable by being forced to use Dvorak", "is punishable by being forced to use vim",
"will award the programmer $200 in AWS credits", "is punishable by being banned from the RMIT programming club"]
connectors = ["unless", "if"]
modifiers = ["the programmer has a blood alcohol concentraction between 0.129 and 0.138",
"the programmer has a license", "the programmer is Linus Torvolds",
"Julian Assange gets angry", "PHP becomes mainstream", "the software uses React",
"the software uses blockchain", "the software uses big data", "the software uses artificial intelligence",
"vim is the developer's primary editor", "emacs is the developer's primary editor"]
function pick(list){
return list[Math.floor(Math.random() * list.length)];
}
if(process.argv[2] == 'users'){
db.users.forEach((user) => console.log(user.real_name + ": " + user.name));
}
else if (process.argv[2] == 'government'){
db.users.forEach((user) => {
console.log(user.real_name + ": " + (Math.random() > 0.5 ? "Goverment": "Opposition"));
});
}
else if (process.argv[2] == 'newuser'){
let id = db.users.length;
let name = "Member for " + db.member_names[id];
user = {
id: id,
name: name,
real_name: process.argv.slice(3).join(" ")
};
db.users.push(user);
console.log(user.real_name + ": " + user.name);
}
else if(process.argv[2] == 'bill'){
let name = pick(act_names) + " Act 2018" + (Math.random() > 0.5 ? " (Ammendment)": "");
console.log(name);
let clauses = [];
for(let i = 0; i < 3; i++){
let clause = pick(topic) + " " + pick(sanction);
if(Math.random() > 0.5){
clause += " " + pick(connectors) + " " + pick(modifiers);
}
console.log(" - " + clause);
}
}
else if(process.argv[2] == 'newfriend'){
let person1 = process.argv[3];
let person2 = process.argv[4];
db.friendships.push([person1, person2]);
}
else if(process.argv[2] == 'endfriend'){
let person1 = process.argv[3];
let person2 = process.argv[4];
db.friendships = db.friendships.filter((friendship) => {
return !(friendship.includes(person1) && friendship.includes(person2));
});
}
else if(process.argv[2] == 'power'){
dampening = 0.85;
function getFriends(user){
let friends = [];
for(let friendship of db.friendships){
if(user == friendship[0]){
friends.push(friendship[1]);
}
else if (user == friendship[1]){
friends.push(friendship[0]);
}
}
return friends;
}
let powers = {};
for(let player of db.users){
powers[player.real_name] = 1;
}
let new_powers = Object.assign({}, powers);
for(let i = 0; i < 10; i++){
for(let name in powers){
let power = powers[name];
let friends = getFriends(name);
for(let friend of friends){
power_to_give = dampening * (power / friends.length)
if(power_to_give === NaN){
console.log("Error");
console.log(name);
console.log(friend);
console.log(friends);
}
new_powers[friend] += power_to_give
new_powers[name] -= power_to_give
}
}
powers = Object.assign({}, new_powers);
}
Object.entries(powers).sort((ranking1, ranking2) => {
return ranking2[1] - ranking1[1];
}).forEach((ranking) => {
console.log(ranking[0] + ": " + ranking[1].toFixed(2));
});
}