-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapz_cvsc.js
More file actions
81 lines (75 loc) · 1.78 KB
/
apz_cvsc.js
File metadata and controls
81 lines (75 loc) · 1.78 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
const readline = require("readline");
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
async function skaiciausIvedimas(msg) {
return new Promise((resolve, reject) => {
rl.question(msg, data => {
resolve(parseInt(data));
});
});
}
async function tekstoIvedimas(msg) {
return new Promise((resolve, reject) => {
rl.question(msg, data => {
resolve(data);
});
});
}
async function main() {
var kiek = await skaiciausIvedimas("Kiek kartu zaisti? ");
var c1Win = 0;
var c2Win = 0;
var draw = 0;
var aKiek = 0;
var pKiek = 0;
var zKiek = 0;
while (kiek > 0) {
var r = Math.random();
var c1;
if (r < 0.3333) {
c1 = "A";
aKiek += 1;
} else if (r < 0.6666) {
c1 = "P";
pKiek += 1;
} else {
c1 = "Z";
zKiek += 1;
}
r = Math.random();
var c2;
if (r < 0.3333) {
c2 = "A";
aKiek += 1;
} else if (r < 0.6666) {
c2 = "P";
pKiek += 1;
} else {
c2 = "Z";
zKiek += 1;
}
if (c1 == c2) {
draw += 1;
} else if (
(c1 == "A" && c2 == "Z") ||
(c1 == "P" && c2 == "A") ||
(c1 == "Z" && c2 == "P")
) {
c1Win += 1;
} else {
c2Win += 1;
}
kiek -= 1;
}
console.log("Lygiosios", draw);
console.log("Kompiuteris 1", c1Win);
console.log("Kompiuteris 2", c2Win);
console.log("-------");
console.log("Akmuo", aKiek);
console.log("Popierius", pKiek);
console.log("Zirkles", zKiek);
rl.close();
}
main();