-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmap.js
More file actions
70 lines (63 loc) · 1.98 KB
/
Copy pathmap.js
File metadata and controls
70 lines (63 loc) · 1.98 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
var map = {
generate(nbPoints, nbNull, data_words) {
size = nbPoints * 2 + nbNull + 1;
words = this.pickWords(size, data_words);
values = this.pickValue(nbPoints, nbNull, size);
map = []
for(i = 0; i < size; i++) {
map.push([words[i], values[i], false]);
}
return map;
},
pickWords(size, data_words) {
words = [];
while (words.length < size) {
word = data_words[Math.floor(Math.random() * data_words.length)];
data_words = data_words.filter(w => w !== word);
words.push(word);
}
return words;
},
pickValue(nbPoints, nbNull, size) {
tab=[nbPoints, nbPoints, nbNull, 1];
values = [];
while (values.length < size) {
value = Math.floor(Math.random() * tab.length);
if (tab[value] > 0) {
tab[value] -= 1;
values.push(value)
}
}
return values;
},
toStringMaster(map) {
d = new Date();
date = d.getDate()+"/"+d.getMonth();
string = "**Partie du "+ date + "** \n";
map = map.sort((a,b) => a[1] - b[1]);
for(i = 0; i < map.length; i ++) {
if (map[i][1] == 0) valeur = "Bleu";
else if (map[i][1] == 1) valeur = "Rouge";
else if (map[i][1] == 3) valeur = "Traitre";
else valeur = "Témoins";
strW = map[i][0] + " -> __" + valeur + "__";
if (map[i][2])
strW = "~~"+strW+"~~";
string += strW + "\n";
}
return string;
},
toStringSpy(map) {
d = new Date();
date = d.getDate()+"/"+d.getMonth();
string = "**Partie du "+ date + "** \n";
for(i = 0; i < map.length; i ++) {
strW = map[i][0];
if (map[i][2])
strW = "~~"+strW+"~~";
string += strW + "\n";
}
return string;
}
}
module.exports = map;