trucoshi 0.1.8 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -4
- package/dist/lib/classes/Deck.js +9 -9
- package/dist/lib/classes/GameLoop.js +30 -72
- package/dist/lib/classes/Hand.js +87 -136
- package/dist/lib/classes/Lobby.d.ts +1 -1
- package/dist/lib/classes/Lobby.js +28 -29
- package/dist/lib/classes/Match.js +37 -80
- package/dist/lib/classes/Play.js +5 -5
- package/dist/lib/classes/Player.js +28 -38
- package/dist/lib/classes/Round.js +9 -10
- package/dist/lib/classes/Table.js +6 -6
- package/dist/lib/classes/Team.js +10 -12
- package/dist/lib/classes/Truco.js +25 -65
- package/dist/lib/constants.js +17 -18
- package/dist/lib/utils.js +7 -8
- package/dist/types.d.ts +43 -6
- package/dist/types.js +1 -1
- package/package.json +1 -1
|
@@ -1,112 +1,69 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
3
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
4
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
5
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
6
|
-
function step(op) {
|
|
7
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
8
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
9
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
10
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
11
|
-
switch (op[0]) {
|
|
12
|
-
case 0: case 1: t = op; break;
|
|
13
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
14
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
15
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
16
|
-
default:
|
|
17
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
18
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
19
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
20
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
21
|
-
if (t[2]) _.ops.pop();
|
|
22
|
-
_.trys.pop(); continue;
|
|
23
|
-
}
|
|
24
|
-
op = body.call(thisArg, _);
|
|
25
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
26
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
3
|
exports.Match = void 0;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
function Match(table, teams, matchPoint) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
var deck = (0, Deck_1.Deck)().shuffle();
|
|
37
|
-
var size = teams[0].players.length;
|
|
4
|
+
const Deck_1 = require("./Deck");
|
|
5
|
+
const Hand_1 = require("./Hand");
|
|
6
|
+
function Match(table, teams = [], matchPoint = 9) {
|
|
7
|
+
const deck = (0, Deck_1.Deck)().shuffle();
|
|
8
|
+
const size = teams[0].players.length;
|
|
38
9
|
if (size !== teams[1].players.length) {
|
|
39
10
|
throw new Error("Team size mismatch");
|
|
40
11
|
}
|
|
41
|
-
function handsGeneratorSequence() {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
return [3 /*break*/, 1];
|
|
62
|
-
case 3:
|
|
63
|
-
match.setCurrentHand(null);
|
|
64
|
-
teams_1 = match.addPoints(hand.points);
|
|
65
|
-
winner = teams_1.find(function (team) { return team.points.winner; });
|
|
66
|
-
if (winner) {
|
|
67
|
-
match.setWinner(winner);
|
|
68
|
-
match.setCurrentHand(null);
|
|
69
|
-
return [3 /*break*/, 4];
|
|
70
|
-
}
|
|
71
|
-
match.table.nextTurn();
|
|
72
|
-
return [3 /*break*/, 0];
|
|
73
|
-
case 4: return [4 /*yield*/, match];
|
|
74
|
-
case 5:
|
|
75
|
-
_a.sent();
|
|
76
|
-
return [2 /*return*/];
|
|
12
|
+
function* handsGeneratorSequence() {
|
|
13
|
+
while (!match.winner) {
|
|
14
|
+
deck.shuffle();
|
|
15
|
+
const hand = match.setCurrentHand((0, Hand_1.Hand)(match, deck, match.hands.length + 1));
|
|
16
|
+
match.pushHand(hand);
|
|
17
|
+
while (!hand.finished()) {
|
|
18
|
+
const { value } = hand.getNextPlayer();
|
|
19
|
+
if (value && value.finished()) {
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
match.setCurrentHand(value);
|
|
23
|
+
yield match;
|
|
24
|
+
}
|
|
25
|
+
match.setCurrentHand(null);
|
|
26
|
+
const teams = match.addPoints(hand.points);
|
|
27
|
+
const winner = teams.find((team) => team.points.winner);
|
|
28
|
+
if (winner) {
|
|
29
|
+
match.setWinner(winner);
|
|
30
|
+
match.setCurrentHand(null);
|
|
31
|
+
break;
|
|
77
32
|
}
|
|
78
|
-
|
|
33
|
+
match.table.nextTurn();
|
|
34
|
+
}
|
|
35
|
+
yield match;
|
|
79
36
|
}
|
|
80
|
-
|
|
81
|
-
|
|
37
|
+
const handsGenerator = handsGeneratorSequence();
|
|
38
|
+
const match = {
|
|
82
39
|
winner: null,
|
|
83
40
|
teams: teams,
|
|
84
41
|
hands: [],
|
|
85
|
-
table
|
|
42
|
+
table,
|
|
86
43
|
currentHand: null,
|
|
87
|
-
play
|
|
44
|
+
play() {
|
|
88
45
|
match.getNextTurn();
|
|
89
46
|
if (!match.currentHand) {
|
|
90
47
|
return null;
|
|
91
48
|
}
|
|
92
49
|
return match.currentHand.play();
|
|
93
50
|
},
|
|
94
|
-
addPoints
|
|
51
|
+
addPoints(points) {
|
|
95
52
|
match.teams[0].addPoints(matchPoint, points[0]);
|
|
96
53
|
match.teams[1].addPoints(matchPoint, points[1]);
|
|
97
54
|
return match.teams;
|
|
98
55
|
},
|
|
99
|
-
pushHand
|
|
56
|
+
pushHand(hand) {
|
|
100
57
|
match.hands.push(hand);
|
|
101
58
|
},
|
|
102
|
-
setCurrentHand
|
|
59
|
+
setCurrentHand(hand) {
|
|
103
60
|
match.currentHand = hand;
|
|
104
61
|
return match.currentHand;
|
|
105
62
|
},
|
|
106
|
-
setWinner
|
|
63
|
+
setWinner(winner) {
|
|
107
64
|
match.winner = winner;
|
|
108
65
|
},
|
|
109
|
-
getNextTurn
|
|
66
|
+
getNextTurn() {
|
|
110
67
|
return handsGenerator.next();
|
|
111
68
|
},
|
|
112
69
|
};
|
package/dist/lib/classes/Play.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PlayInstance = void 0;
|
|
4
|
-
|
|
4
|
+
const types_1 = require("../../types");
|
|
5
5
|
function PlayInstance(hand, teams) {
|
|
6
6
|
var _a, _b, _c;
|
|
7
|
-
|
|
7
|
+
const instance = {
|
|
8
8
|
state: hand.state,
|
|
9
|
-
teams
|
|
9
|
+
teams,
|
|
10
10
|
truco: hand.truco,
|
|
11
11
|
envido: hand.envido,
|
|
12
12
|
handIdx: hand.idx,
|
|
@@ -14,10 +14,10 @@ function PlayInstance(hand, teams) {
|
|
|
14
14
|
player: hand.currentPlayer,
|
|
15
15
|
commands: [],
|
|
16
16
|
rounds: hand.rounds,
|
|
17
|
-
use
|
|
17
|
+
use(idx, card) {
|
|
18
18
|
return hand.use(idx, card);
|
|
19
19
|
},
|
|
20
|
-
say
|
|
20
|
+
say(command) {
|
|
21
21
|
var _a;
|
|
22
22
|
if (!hand._currentPlayer || !((_a = instance.commands) === null || _a === void 0 ? void 0 : _a.includes(command))) {
|
|
23
23
|
return null;
|
|
@@ -1,73 +1,63 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
3
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
4
|
-
if (ar || !(i in from)) {
|
|
5
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
6
|
-
ar[i] = from[i];
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.Player = void 0;
|
|
13
|
-
function Player(id, teamIdx, isOwner) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
id: id,
|
|
4
|
+
function Player(id, teamIdx, isOwner = false) {
|
|
5
|
+
const player = {
|
|
6
|
+
id,
|
|
17
7
|
session: undefined,
|
|
18
|
-
teamIdx
|
|
8
|
+
teamIdx,
|
|
19
9
|
hand: [],
|
|
20
10
|
commands: [],
|
|
21
11
|
usedHand: [],
|
|
22
12
|
prevHand: [],
|
|
23
|
-
isOwner
|
|
13
|
+
isOwner,
|
|
24
14
|
isTurn: false,
|
|
25
15
|
disabled: false,
|
|
26
16
|
ready: false,
|
|
27
|
-
setOwner
|
|
17
|
+
setOwner(owner) {
|
|
28
18
|
player.isOwner = owner;
|
|
29
19
|
},
|
|
30
|
-
setTurn
|
|
20
|
+
setTurn(turn) {
|
|
31
21
|
player.isTurn = turn;
|
|
32
22
|
},
|
|
33
|
-
getPublicPlayer
|
|
34
|
-
|
|
23
|
+
getPublicPlayer() {
|
|
24
|
+
const { id, disabled, ready, usedHand, prevHand, teamIdx, isTurn, isOwner } = player;
|
|
35
25
|
return {
|
|
36
|
-
id
|
|
37
|
-
disabled
|
|
38
|
-
ready
|
|
39
|
-
usedHand
|
|
40
|
-
prevHand
|
|
41
|
-
teamIdx
|
|
42
|
-
isTurn
|
|
43
|
-
isOwner
|
|
44
|
-
hand: player.hand.map(
|
|
26
|
+
id,
|
|
27
|
+
disabled,
|
|
28
|
+
ready,
|
|
29
|
+
usedHand,
|
|
30
|
+
prevHand,
|
|
31
|
+
teamIdx,
|
|
32
|
+
isTurn,
|
|
33
|
+
isOwner,
|
|
34
|
+
hand: player.hand.map(() => "xx"),
|
|
45
35
|
session: undefined,
|
|
46
36
|
};
|
|
47
37
|
},
|
|
48
|
-
setSession
|
|
38
|
+
setSession(session) {
|
|
49
39
|
player.session = session;
|
|
50
40
|
},
|
|
51
|
-
enable
|
|
41
|
+
enable() {
|
|
52
42
|
player.disabled = false;
|
|
53
43
|
},
|
|
54
|
-
disable
|
|
44
|
+
disable() {
|
|
55
45
|
player.disabled = true;
|
|
56
46
|
},
|
|
57
|
-
setReady
|
|
47
|
+
setReady(ready) {
|
|
58
48
|
player.ready = ready;
|
|
59
49
|
},
|
|
60
|
-
setHand
|
|
61
|
-
player.prevHand =
|
|
50
|
+
setHand(hand) {
|
|
51
|
+
player.prevHand = [...player.usedHand];
|
|
62
52
|
player.hand = hand;
|
|
63
53
|
player.usedHand = [];
|
|
64
54
|
return hand;
|
|
65
55
|
},
|
|
66
|
-
useCard
|
|
56
|
+
useCard(idx, card) {
|
|
67
57
|
if (player.hand[idx] && player.hand[idx] === card) {
|
|
68
|
-
|
|
69
|
-
player.usedHand.push(
|
|
70
|
-
return
|
|
58
|
+
const card = player.hand.splice(idx, 1)[0];
|
|
59
|
+
player.usedHand.push(card);
|
|
60
|
+
return card;
|
|
71
61
|
}
|
|
72
62
|
return null;
|
|
73
63
|
},
|
|
@@ -1,23 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Round = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
const utils_1 = require("../utils");
|
|
5
|
+
const Deck_1 = require("./Deck");
|
|
6
6
|
function Round(turn) {
|
|
7
|
-
|
|
8
|
-
turn
|
|
7
|
+
const round = {
|
|
8
|
+
turn,
|
|
9
9
|
highest: -1,
|
|
10
10
|
winner: null,
|
|
11
11
|
cards: [],
|
|
12
12
|
tie: false,
|
|
13
|
-
nextTurn
|
|
13
|
+
nextTurn() {
|
|
14
14
|
round.turn++;
|
|
15
15
|
},
|
|
16
|
-
use
|
|
17
|
-
var
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
if (value === round.highest && player.teamIdx !== ((_b = round.winner) === null || _b === void 0 ? void 0 : _b.teamIdx)) {
|
|
16
|
+
use({ card, player }) {
|
|
17
|
+
var _a;
|
|
18
|
+
const value = (0, utils_1.getCardValue)(card);
|
|
19
|
+
if (value === round.highest && player.teamIdx !== ((_a = round.winner) === null || _a === void 0 ? void 0 : _a.teamIdx)) {
|
|
21
20
|
round.tie = true;
|
|
22
21
|
}
|
|
23
22
|
if (value > round.highest) {
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Table = void 0;
|
|
4
4
|
function Table(players, teams) {
|
|
5
|
-
|
|
6
|
-
players
|
|
5
|
+
const table = {
|
|
6
|
+
players,
|
|
7
7
|
cards: [],
|
|
8
8
|
forehandIdx: 0,
|
|
9
|
-
nextTurn
|
|
9
|
+
nextTurn() {
|
|
10
10
|
if (table.forehandIdx < table.players.length - 1) {
|
|
11
11
|
table.forehandIdx++;
|
|
12
12
|
}
|
|
@@ -15,10 +15,10 @@ function Table(players, teams) {
|
|
|
15
15
|
}
|
|
16
16
|
return table.player();
|
|
17
17
|
},
|
|
18
|
-
getPlayerPosition
|
|
19
|
-
return table.players.findIndex(
|
|
18
|
+
getPlayerPosition(id) {
|
|
19
|
+
return table.players.findIndex((p) => p.id === id);
|
|
20
20
|
},
|
|
21
|
-
player
|
|
21
|
+
player(idx) {
|
|
22
22
|
if (idx !== undefined) {
|
|
23
23
|
return table.players[idx];
|
|
24
24
|
}
|
package/dist/lib/classes/Team.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Team = void 0;
|
|
4
4
|
function Team(players) {
|
|
5
|
-
|
|
5
|
+
const team = {
|
|
6
6
|
_players: new Map(),
|
|
7
7
|
get players() {
|
|
8
8
|
return Array.from(team._players.values());
|
|
@@ -12,25 +12,23 @@ function Team(players) {
|
|
|
12
12
|
malas: 0,
|
|
13
13
|
winner: false,
|
|
14
14
|
},
|
|
15
|
-
getPublicTeam
|
|
15
|
+
getPublicTeam(playerSession) {
|
|
16
16
|
return {
|
|
17
17
|
points: team.points,
|
|
18
|
-
players: team.players.map(
|
|
19
|
-
return player.session === playerSession ? player : player.getPublicPlayer();
|
|
20
|
-
}),
|
|
18
|
+
players: team.players.map((player) => player.session === playerSession ? player : player.getPublicPlayer()),
|
|
21
19
|
};
|
|
22
20
|
},
|
|
23
|
-
isTeamDisabled
|
|
24
|
-
return team.players.reduce(
|
|
21
|
+
isTeamDisabled() {
|
|
22
|
+
return team.players.reduce((prev, curr) => prev && curr.disabled, true);
|
|
25
23
|
},
|
|
26
|
-
disable
|
|
24
|
+
disable(player) {
|
|
27
25
|
var _a;
|
|
28
26
|
(_a = team._players.get(player.session)) === null || _a === void 0 ? void 0 : _a.disable();
|
|
29
27
|
return team.isTeamDisabled();
|
|
30
28
|
},
|
|
31
|
-
addPoints
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
addPoints(matchPoint, points) {
|
|
30
|
+
const malas = team.points.malas + points;
|
|
31
|
+
const diff = malas - matchPoint;
|
|
34
32
|
if (diff > 0) {
|
|
35
33
|
team.points.malas = matchPoint;
|
|
36
34
|
team.points.buenas += diff;
|
|
@@ -44,7 +42,7 @@ function Team(players) {
|
|
|
44
42
|
return team.points;
|
|
45
43
|
},
|
|
46
44
|
};
|
|
47
|
-
players.forEach(
|
|
45
|
+
players.forEach((player) => team._players.set(player.session, player));
|
|
48
46
|
return team;
|
|
49
47
|
}
|
|
50
48
|
exports.Team = Team;
|
|
@@ -1,67 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
3
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
4
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
5
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
6
|
-
function step(op) {
|
|
7
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
8
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
9
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
10
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
11
|
-
switch (op[0]) {
|
|
12
|
-
case 0: case 1: t = op; break;
|
|
13
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
14
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
15
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
16
|
-
default:
|
|
17
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
18
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
19
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
20
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
21
|
-
if (t[2]) _.ops.pop();
|
|
22
|
-
_.trys.pop(); continue;
|
|
23
|
-
}
|
|
24
|
-
op = body.call(thisArg, _);
|
|
25
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
26
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
3
|
exports.Truco = void 0;
|
|
31
4
|
function Truco() {
|
|
32
|
-
function trucoAnswerGeneratorSequence() {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
if (truco.turn >= truco.players.length - 1) {
|
|
47
|
-
truco.setTurn(0);
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
truco.setTurn(truco.turn + 1);
|
|
51
|
-
}
|
|
52
|
-
i++;
|
|
53
|
-
return [4 /*yield*/, truco];
|
|
54
|
-
case 2:
|
|
55
|
-
_a.sent();
|
|
56
|
-
return [3 /*break*/, 1];
|
|
57
|
-
case 3: return [4 /*yield*/, truco];
|
|
58
|
-
case 4:
|
|
59
|
-
_a.sent();
|
|
60
|
-
return [2 /*return*/];
|
|
5
|
+
function* trucoAnswerGeneratorSequence() {
|
|
6
|
+
let i = 0;
|
|
7
|
+
while (i < truco.players.length && truco.answer === null) {
|
|
8
|
+
const player = truco.players[truco.turn];
|
|
9
|
+
truco.setCurrentPlayer(player);
|
|
10
|
+
if (player.disabled) {
|
|
11
|
+
truco.setCurrentPlayer(null);
|
|
12
|
+
}
|
|
13
|
+
if (truco.turn >= truco.players.length - 1) {
|
|
14
|
+
truco.setTurn(0);
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
truco.setTurn(truco.turn + 1);
|
|
61
18
|
}
|
|
62
|
-
|
|
19
|
+
i++;
|
|
20
|
+
yield truco;
|
|
21
|
+
}
|
|
22
|
+
yield truco;
|
|
63
23
|
}
|
|
64
|
-
|
|
24
|
+
const truco = {
|
|
65
25
|
turn: 0,
|
|
66
26
|
state: 1,
|
|
67
27
|
teamIdx: null,
|
|
@@ -69,17 +29,17 @@ function Truco() {
|
|
|
69
29
|
currentPlayer: null,
|
|
70
30
|
generator: trucoAnswerGeneratorSequence(),
|
|
71
31
|
players: [],
|
|
72
|
-
sayTruco
|
|
32
|
+
sayTruco(teamIdx, players) {
|
|
73
33
|
truco.teamIdx = teamIdx;
|
|
74
34
|
truco.answer = null;
|
|
75
35
|
truco.players = players;
|
|
76
36
|
truco.generator = trucoAnswerGeneratorSequence();
|
|
77
37
|
return truco;
|
|
78
38
|
},
|
|
79
|
-
setPlayers
|
|
39
|
+
setPlayers(players) {
|
|
80
40
|
truco.players = players;
|
|
81
41
|
},
|
|
82
|
-
setAnswer
|
|
42
|
+
setAnswer(answer) {
|
|
83
43
|
if (answer) {
|
|
84
44
|
truco.state++;
|
|
85
45
|
}
|
|
@@ -89,19 +49,19 @@ function Truco() {
|
|
|
89
49
|
truco.answer = answer;
|
|
90
50
|
return truco;
|
|
91
51
|
},
|
|
92
|
-
setTeam
|
|
52
|
+
setTeam(idx) {
|
|
93
53
|
truco.teamIdx = idx;
|
|
94
54
|
return truco.teamIdx;
|
|
95
55
|
},
|
|
96
|
-
setTurn
|
|
56
|
+
setTurn(turn) {
|
|
97
57
|
truco.turn = turn;
|
|
98
58
|
return truco.turn;
|
|
99
59
|
},
|
|
100
|
-
setCurrentPlayer
|
|
60
|
+
setCurrentPlayer(player) {
|
|
101
61
|
truco.currentPlayer = player;
|
|
102
62
|
return truco.currentPlayer;
|
|
103
63
|
},
|
|
104
|
-
getNextPlayer
|
|
64
|
+
getNextPlayer() {
|
|
105
65
|
return truco.generator.next();
|
|
106
66
|
},
|
|
107
67
|
};
|
package/dist/lib/constants.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var _a;
|
|
3
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
3
|
exports.EnvidoCalculator = exports.TEAM_SIZE_VALUES = exports.CARDS = void 0;
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
const types_1 = require("../types");
|
|
5
|
+
const utils_1 = require("./utils");
|
|
7
6
|
exports.CARDS = {
|
|
8
7
|
"1e": 14,
|
|
9
8
|
"1b": 13,
|
|
@@ -47,23 +46,23 @@ exports.CARDS = {
|
|
|
47
46
|
"4c": 0,
|
|
48
47
|
};
|
|
49
48
|
exports.TEAM_SIZE_VALUES = [1, 2, 3];
|
|
50
|
-
exports.EnvidoCalculator =
|
|
51
|
-
|
|
49
|
+
exports.EnvidoCalculator = {
|
|
50
|
+
[types_1.EEnvidoCommand.ENVIDO]: () => ({
|
|
52
51
|
accept: 2,
|
|
53
52
|
decline: 1,
|
|
54
53
|
next: [types_1.EEnvidoCommand.ENVIDO_ENVIDO, types_1.EEnvidoCommand.REAL_ENVIDO, types_1.EEnvidoCommand.FALTA_ENVIDO],
|
|
55
|
-
})
|
|
56
|
-
|
|
54
|
+
}),
|
|
55
|
+
[types_1.EEnvidoCommand.ENVIDO_ENVIDO]: () => ({
|
|
57
56
|
accept: 4,
|
|
58
57
|
decline: 2,
|
|
59
58
|
next: [types_1.EEnvidoCommand.REAL_ENVIDO, types_1.EEnvidoCommand.FALTA_ENVIDO],
|
|
60
|
-
})
|
|
61
|
-
|
|
59
|
+
}),
|
|
60
|
+
[types_1.EEnvidoCommand.REAL_ENVIDO]: () => ({
|
|
62
61
|
accept: 3,
|
|
63
62
|
decline: 1,
|
|
64
63
|
next: [types_1.EEnvidoCommand.FALTA_ENVIDO],
|
|
65
|
-
})
|
|
66
|
-
|
|
64
|
+
}),
|
|
65
|
+
[types_1.EEnvidoCommand.FALTA_ENVIDO]: (args) => {
|
|
67
66
|
if (!args || !args.teams || !args.matchPoint) {
|
|
68
67
|
return {
|
|
69
68
|
accept: 1,
|
|
@@ -71,15 +70,15 @@ exports.EnvidoCalculator = (_a = {},
|
|
|
71
70
|
next: [],
|
|
72
71
|
};
|
|
73
72
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
73
|
+
const { teams, matchPoint } = args;
|
|
74
|
+
const totals = teams.map((team) => team.points.malas + team.points.buenas);
|
|
75
|
+
const higher = (0, utils_1.getMaxNumberIndex)(totals);
|
|
76
|
+
const points = teams[higher].points;
|
|
77
|
+
const accept = points.buenas > 0 ? matchPoint - points.buenas : matchPoint - points.malas;
|
|
79
78
|
return {
|
|
80
|
-
accept
|
|
79
|
+
accept,
|
|
81
80
|
decline: 2,
|
|
82
81
|
next: [],
|
|
83
82
|
};
|
|
84
83
|
},
|
|
85
|
-
|
|
84
|
+
};
|
package/dist/lib/utils.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.checkHandWinner = exports.shuffleArray = exports.getCardValue = exports.getMaxNumberIndex = void 0;
|
|
4
|
-
|
|
4
|
+
const constants_1 = require("./constants");
|
|
5
5
|
function getMaxNumberIndex(array) {
|
|
6
|
-
return array.reduce(
|
|
6
|
+
return array.reduce((accumulator, current, index) => {
|
|
7
7
|
return current > array[accumulator] ? index : accumulator;
|
|
8
8
|
}, 0);
|
|
9
9
|
}
|
|
@@ -13,25 +13,24 @@ function getCardValue(card) {
|
|
|
13
13
|
}
|
|
14
14
|
exports.getCardValue = getCardValue;
|
|
15
15
|
function shuffleArray(array) {
|
|
16
|
-
|
|
17
|
-
var currentIndex = array.length, randomIndex;
|
|
16
|
+
let currentIndex = array.length, randomIndex;
|
|
18
17
|
while (currentIndex != 0) {
|
|
19
18
|
randomIndex = Math.floor(Math.random() * currentIndex);
|
|
20
19
|
currentIndex--;
|
|
21
|
-
|
|
20
|
+
[array[currentIndex], array[randomIndex]] = [array[randomIndex], array[currentIndex]];
|
|
22
21
|
}
|
|
23
22
|
return array;
|
|
24
23
|
}
|
|
25
24
|
exports.shuffleArray = shuffleArray;
|
|
26
25
|
function checkHandWinner(rounds, forehandTeamIdx) {
|
|
27
26
|
var _a, _b;
|
|
28
|
-
|
|
27
|
+
const roundsWon = {
|
|
29
28
|
0: 0,
|
|
30
29
|
1: 0,
|
|
31
30
|
ties: 0,
|
|
32
31
|
};
|
|
33
|
-
for (
|
|
34
|
-
|
|
32
|
+
for (let i = 0; i < rounds.length; i++) {
|
|
33
|
+
const round = rounds[i];
|
|
35
34
|
if (round.tie) {
|
|
36
35
|
roundsWon[0] += 1;
|
|
37
36
|
roundsWon[1] += 1;
|