-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
60 lines (48 loc) · 1.42 KB
/
index.js
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
'use strict';
let Bot = require('javascript-jass-bot');
class BotStrategy {
requestTrumpf(cards) {
let amountPerColor = {
HEARTS: 0,
SPADES: 0,
CLUBS: 0,
DIAMONDS: 0
};
cards.forEach((card) => {
amountPerColor[card.color]++;
switch (card.number) {
case 9: // Nell
amountPerColor[card.color]++;
break;
case 11: // Buur
amountPerColor[card.color] += 2;
break;
}
});
let max = 0, trumpf;
for (let color in amountPerColor) {
if (amountPerColor[color] > max) {
max = amountPerColor[color];
trumpf = color;
}
}
console.log('cards', cards);
console.log('amountPerColor', amountPerColor);
console.log('trumpf', trumpf);
let response = {};
response.mode = 'TRUMPF';
response.trumpfColor = trumpf;
return response;
}
playCard(myCards, playedCards, gameState) {
// e.g. play random
return myCards[Math.floor(Math.random() * myCards.length)];
}
gameFinished(data) {
console.log(data);
}
notifyError(error) {
console.log(error);
}
}
new Bot(process.argv[2]).withStrategy(new BotStrategy()).connect(process.argv[3] + ':3000');