trucoshi 0.0.1 → 0.0.4
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/.prettierrc.json +4 -0
- package/LICENSE +674 -0
- package/README.md +36 -0
- package/build/lib/classes/Deck.d.ts +2 -0
- package/build/lib/classes/Deck.js +27 -0
- package/build/lib/classes/Hand.d.ts +2 -0
- package/build/lib/classes/Hand.js +175 -0
- package/build/lib/classes/Match.d.ts +2 -0
- package/build/lib/classes/Match.js +116 -0
- package/build/lib/classes/Play.d.ts +2 -0
- package/build/lib/classes/Play.js +45 -0
- package/build/lib/classes/Player.d.ts +2 -0
- package/build/lib/classes/Player.js +26 -0
- package/build/lib/classes/Round.d.ts +2 -0
- package/build/lib/classes/Round.js +29 -0
- package/build/lib/classes/Table.d.ts +2 -0
- package/build/lib/classes/Table.js +37 -0
- package/build/lib/classes/Team.d.ts +2 -0
- package/build/lib/classes/Team.js +34 -0
- package/build/lib/constants.d.ts +30 -28
- package/build/lib/constants.js +90 -12
- package/build/lib/index.d.ts +11 -0
- package/build/lib/index.js +88 -0
- package/build/lib/types.d.ts +75 -29
- package/build/lib/types.js +22 -12
- package/build/lib/utils.d.ts +3 -3
- package/build/lib/utils.js +29 -19
- package/build/server/index.js +13 -5
- package/build/server/types.d.ts +11 -0
- package/build/server/types.js +15 -0
- package/build/test/autoplay.js +43 -31
- package/build/test/play.js +127 -81
- package/package.json +9 -8
- package/src/lib/classes/Deck.ts +25 -0
- package/src/lib/classes/Hand.ts +151 -0
- package/src/lib/classes/Match.ts +80 -0
- package/src/lib/classes/Play.ts +48 -0
- package/src/lib/classes/Player.ts +25 -0
- package/src/lib/classes/Round.ts +26 -0
- package/src/lib/classes/Table.ts +37 -0
- package/src/lib/classes/Team.ts +34 -0
- package/src/lib/constants.ts +97 -11
- package/src/lib/index.ts +57 -0
- package/src/lib/types.ts +140 -80
- package/src/lib/utils.ts +70 -52
- package/src/server/index.ts +34 -22
- package/src/server/types.ts +12 -0
- package/src/test/autoplay.ts +47 -41
- package/src/test/play.ts +113 -70
- package/build/lib/trucoshi.d.ts +0 -10
- package/build/lib/trucoshi.js +0 -363
- package/build/test/legacy.d.ts +0 -1
- package/build/test/legacy.js +0 -146
- package/src/lib/trucoshi.ts +0 -342
- package/src/test/legacy.ts +0 -68
package/README.md
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# Trucoshi
|
|
2
|
+
|
|
3
|
+
### English
|
|
4
|
+
Pretends to be an Argentinian Truco game socket server
|
|
5
|
+
|
|
6
|
+
### Spanish
|
|
7
|
+
Pretende ser un server basado en sockets del juego de Truco Argentino
|
|
8
|
+
|
|
9
|
+
# Test
|
|
10
|
+
Right now there's only a local CLI way of playing as there is no socket server implementation and its just the game logic.
|
|
11
|
+
|
|
12
|
+
### Installation
|
|
13
|
+
`yarn`
|
|
14
|
+
|
|
15
|
+
### Play
|
|
16
|
+
`yarn test:play`
|
|
17
|
+
|
|
18
|
+
### Autoplay
|
|
19
|
+
`yarn test:autoplay`
|
|
20
|
+
|
|
21
|
+
# Todo
|
|
22
|
+
[x] Logica de turnos, rondas y battalla de cartas
|
|
23
|
+
[x] Irse al mazo
|
|
24
|
+
[] Cantar truco
|
|
25
|
+
[] Cantar envido
|
|
26
|
+
[] Cantar flor
|
|
27
|
+
[] Socket server
|
|
28
|
+
[] Unit tests
|
|
29
|
+
|
|
30
|
+
# License
|
|
31
|
+
|
|
32
|
+
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
|
33
|
+
|
|
34
|
+
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
35
|
+
|
|
36
|
+
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Deck = void 0;
|
|
4
|
+
var constants_1 = require("../constants");
|
|
5
|
+
var utils_1 = require("../utils");
|
|
6
|
+
function Deck() {
|
|
7
|
+
var deck = {
|
|
8
|
+
cards: Object.keys(constants_1.CARDS),
|
|
9
|
+
usedCards: [],
|
|
10
|
+
takeCard: function () {
|
|
11
|
+
var card = deck.cards.shift();
|
|
12
|
+
deck.usedCards.push(card);
|
|
13
|
+
return card;
|
|
14
|
+
},
|
|
15
|
+
shuffle: function () {
|
|
16
|
+
deck.cards = deck.cards.concat(deck.usedCards);
|
|
17
|
+
deck.usedCards = [];
|
|
18
|
+
deck.cards = (0, utils_1.shuffleArray)(deck.cards);
|
|
19
|
+
if (deck.cards.length !== 40) {
|
|
20
|
+
throw new Error("This is not good");
|
|
21
|
+
}
|
|
22
|
+
return deck;
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
return deck;
|
|
26
|
+
}
|
|
27
|
+
exports.Deck = Deck;
|
|
@@ -0,0 +1,175 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
+
exports.Hand = void 0;
|
|
31
|
+
var types_1 = require("../types");
|
|
32
|
+
var utils_1 = require("../utils");
|
|
33
|
+
var Play_1 = require("./Play");
|
|
34
|
+
var Round_1 = require("./Round");
|
|
35
|
+
function Hand(match, deck, idx) {
|
|
36
|
+
var _a;
|
|
37
|
+
match.teams.forEach(function (team) {
|
|
38
|
+
team.players.forEach(function (player) {
|
|
39
|
+
var playerHand = [deck.takeCard(), deck.takeCard(), deck.takeCard()];
|
|
40
|
+
player.setHand(playerHand);
|
|
41
|
+
// player.setHand(["5c", "4c", "6c"])
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
function roundsGeneratorSequence() {
|
|
45
|
+
var currentRoundIdx, forehandTeamIdx, i, round, previousRound, newTurn, player, teamIdx;
|
|
46
|
+
return __generator(this, function (_a) {
|
|
47
|
+
switch (_a.label) {
|
|
48
|
+
case 0:
|
|
49
|
+
currentRoundIdx = 0;
|
|
50
|
+
forehandTeamIdx = match.table.player(hand.turn).teamIdx;
|
|
51
|
+
_a.label = 1;
|
|
52
|
+
case 1:
|
|
53
|
+
if (!(currentRoundIdx < 3 && !hand.finished())) return [3 /*break*/, 5];
|
|
54
|
+
i = 0;
|
|
55
|
+
round = (0, Round_1.Round)();
|
|
56
|
+
hand.setCurrentRound(round);
|
|
57
|
+
hand.pushRound(round);
|
|
58
|
+
previousRound = hand.rounds[currentRoundIdx - 1];
|
|
59
|
+
// Put previous round winner as forehand
|
|
60
|
+
if (previousRound && previousRound.winner && !previousRound.tie) {
|
|
61
|
+
newTurn = match.table.getPlayerPosition(previousRound.winner.id);
|
|
62
|
+
if (newTurn !== -1) {
|
|
63
|
+
hand.setTurn(newTurn);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
_a.label = 2;
|
|
67
|
+
case 2:
|
|
68
|
+
if (!(i < match.table.players.length)) return [3 /*break*/, 4];
|
|
69
|
+
player = match.table.player(hand.turn);
|
|
70
|
+
hand.setCurrentPlayer(player);
|
|
71
|
+
if (hand.disabledPlayerIds.includes(player.id)) {
|
|
72
|
+
hand.setCurrentPlayer(null);
|
|
73
|
+
}
|
|
74
|
+
if (hand.turn >= match.table.players.length - 1) {
|
|
75
|
+
hand.setTurn(0);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
hand.setTurn(hand.turn + 1);
|
|
79
|
+
}
|
|
80
|
+
i++;
|
|
81
|
+
return [4 /*yield*/, hand];
|
|
82
|
+
case 3:
|
|
83
|
+
_a.sent();
|
|
84
|
+
return [3 /*break*/, 2];
|
|
85
|
+
case 4:
|
|
86
|
+
teamIdx = (0, utils_1.checkHandWinner)(hand.rounds, forehandTeamIdx, hand.disabledPlayerIds, match.teams);
|
|
87
|
+
if (teamIdx !== null) {
|
|
88
|
+
hand.addPoints(teamIdx, hand.truco.state);
|
|
89
|
+
hand.setState(types_1.EHandState.FINISHED);
|
|
90
|
+
}
|
|
91
|
+
currentRoundIdx++;
|
|
92
|
+
return [3 /*break*/, 1];
|
|
93
|
+
case 5: return [4 /*yield*/, hand];
|
|
94
|
+
case 6:
|
|
95
|
+
_a.sent();
|
|
96
|
+
return [2 /*return*/];
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
var roundsGenerator = roundsGeneratorSequence();
|
|
101
|
+
var commands = (_a = {},
|
|
102
|
+
_a[types_1.ESayCommand.MAZO] = function (player) {
|
|
103
|
+
hand.disablePlayer(player);
|
|
104
|
+
},
|
|
105
|
+
_a[types_1.ESayCommand.TRUCO] = function (player) {
|
|
106
|
+
var teamIdx = hand.truco.teamIdx;
|
|
107
|
+
if (teamIdx === null || teamIdx !== player.teamIdx) {
|
|
108
|
+
hand.setState(types_1.EHandState.WAITING_FOR_TRUCO_ANSWER);
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
_a[types_1.ESayCommand.FLOR] = function () { },
|
|
112
|
+
_a[types_1.ESayCommand.CONTRAFLOR] = function () { },
|
|
113
|
+
_a[types_1.EEnvidoCommand.ENVIDO] = function () { },
|
|
114
|
+
_a[types_1.EEnvidoCommand.ENVIDO_ENVIDO] = function () { },
|
|
115
|
+
_a[types_1.EEnvidoCommand.REAL_ENVIDO] = function () { },
|
|
116
|
+
_a[types_1.EEnvidoCommand.FALTA_ENVIDO] = function () { },
|
|
117
|
+
_a);
|
|
118
|
+
var hand = {
|
|
119
|
+
idx: idx,
|
|
120
|
+
turn: Number(match.table.forehandIdx),
|
|
121
|
+
state: types_1.EHandState.WAITING_PLAY,
|
|
122
|
+
rounds: [],
|
|
123
|
+
truco: {
|
|
124
|
+
state: 1,
|
|
125
|
+
teamIdx: null,
|
|
126
|
+
},
|
|
127
|
+
envido: {
|
|
128
|
+
accept: 1,
|
|
129
|
+
decline: 2,
|
|
130
|
+
teamIdx: null,
|
|
131
|
+
},
|
|
132
|
+
points: [0, 0],
|
|
133
|
+
disabledPlayerIds: [],
|
|
134
|
+
currentRound: null,
|
|
135
|
+
currentPlayer: null,
|
|
136
|
+
commands: commands,
|
|
137
|
+
play: function () {
|
|
138
|
+
return (0, Play_1.PlayInstance)(hand, match.teams);
|
|
139
|
+
},
|
|
140
|
+
getNextPlayer: function () {
|
|
141
|
+
return roundsGenerator.next();
|
|
142
|
+
},
|
|
143
|
+
disablePlayer: function (player) {
|
|
144
|
+
hand.disabledPlayerIds.push(player.id);
|
|
145
|
+
},
|
|
146
|
+
addPoints: function (team, points) {
|
|
147
|
+
hand.points[team] = hand.points[team] + points;
|
|
148
|
+
},
|
|
149
|
+
pushRound: function (round) {
|
|
150
|
+
hand.rounds.push(round);
|
|
151
|
+
return round;
|
|
152
|
+
},
|
|
153
|
+
setTurn: function (turn) {
|
|
154
|
+
hand.turn = turn;
|
|
155
|
+
return match.table.player(hand.turn);
|
|
156
|
+
},
|
|
157
|
+
setCurrentRound: function (round) {
|
|
158
|
+
hand.currentRound = round;
|
|
159
|
+
return hand.currentRound;
|
|
160
|
+
},
|
|
161
|
+
setCurrentPlayer: function (player) {
|
|
162
|
+
hand.currentPlayer = player;
|
|
163
|
+
return hand.currentPlayer;
|
|
164
|
+
},
|
|
165
|
+
setState: function (state) {
|
|
166
|
+
hand.state = state;
|
|
167
|
+
return hand.state;
|
|
168
|
+
},
|
|
169
|
+
finished: function () {
|
|
170
|
+
return hand.state === types_1.EHandState.FINISHED;
|
|
171
|
+
},
|
|
172
|
+
};
|
|
173
|
+
return hand;
|
|
174
|
+
}
|
|
175
|
+
exports.Hand = Hand;
|
|
@@ -0,0 +1,116 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
+
exports.Match = void 0;
|
|
31
|
+
var Deck_1 = require("./Deck");
|
|
32
|
+
var Hand_1 = require("./Hand");
|
|
33
|
+
var Table_1 = require("./Table");
|
|
34
|
+
function Match(teams, matchPoint) {
|
|
35
|
+
if (teams === void 0) { teams = []; }
|
|
36
|
+
if (matchPoint === void 0) { matchPoint = 9; }
|
|
37
|
+
var deck = (0, Deck_1.Deck)().shuffle();
|
|
38
|
+
var size = teams[0].players.length;
|
|
39
|
+
if (size !== teams[1].players.length) {
|
|
40
|
+
throw new Error("Team size mismatch");
|
|
41
|
+
}
|
|
42
|
+
function handsGeneratorSequence() {
|
|
43
|
+
var hand, value, teams_1, winner;
|
|
44
|
+
return __generator(this, function (_a) {
|
|
45
|
+
switch (_a.label) {
|
|
46
|
+
case 0:
|
|
47
|
+
if (!!match.winner) return [3 /*break*/, 4];
|
|
48
|
+
deck.shuffle();
|
|
49
|
+
hand = match.setCurrentHand((0, Hand_1.Hand)(match, deck, match.hands.length + 1));
|
|
50
|
+
match.pushHand(hand);
|
|
51
|
+
_a.label = 1;
|
|
52
|
+
case 1:
|
|
53
|
+
if (!!hand.finished()) return [3 /*break*/, 3];
|
|
54
|
+
value = hand.getNextPlayer().value;
|
|
55
|
+
if (value && value.finished()) {
|
|
56
|
+
return [3 /*break*/, 1];
|
|
57
|
+
}
|
|
58
|
+
match.setCurrentHand(value);
|
|
59
|
+
return [4 /*yield*/, match];
|
|
60
|
+
case 2:
|
|
61
|
+
_a.sent();
|
|
62
|
+
return [3 /*break*/, 1];
|
|
63
|
+
case 3:
|
|
64
|
+
match.setCurrentHand(null);
|
|
65
|
+
teams_1 = match.addPoints(hand.points);
|
|
66
|
+
winner = teams_1.find(function (team) { return team.points.winner; });
|
|
67
|
+
if (winner) {
|
|
68
|
+
match.setWinner(winner);
|
|
69
|
+
match.setCurrentHand(null);
|
|
70
|
+
return [3 /*break*/, 4];
|
|
71
|
+
}
|
|
72
|
+
match.table.nextTurn();
|
|
73
|
+
return [3 /*break*/, 0];
|
|
74
|
+
case 4: return [4 /*yield*/, match];
|
|
75
|
+
case 5:
|
|
76
|
+
_a.sent();
|
|
77
|
+
return [2 /*return*/];
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
var handsGenerator = handsGeneratorSequence();
|
|
82
|
+
var match = {
|
|
83
|
+
winner: null,
|
|
84
|
+
teams: teams,
|
|
85
|
+
hands: [],
|
|
86
|
+
table: (0, Table_1.Table)(teams, size),
|
|
87
|
+
currentHand: null,
|
|
88
|
+
play: function () {
|
|
89
|
+
match.getNextTurn();
|
|
90
|
+
if (!match.currentHand) {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
return match.currentHand.play();
|
|
94
|
+
},
|
|
95
|
+
addPoints: function (points) {
|
|
96
|
+
match.teams[0].addPoints(matchPoint, points[0]);
|
|
97
|
+
match.teams[1].addPoints(matchPoint, points[1]);
|
|
98
|
+
return match.teams;
|
|
99
|
+
},
|
|
100
|
+
pushHand: function (hand) {
|
|
101
|
+
match.hands.push(hand);
|
|
102
|
+
},
|
|
103
|
+
setCurrentHand: function (hand) {
|
|
104
|
+
match.currentHand = hand;
|
|
105
|
+
return match.currentHand;
|
|
106
|
+
},
|
|
107
|
+
setWinner: function (winner) {
|
|
108
|
+
match.winner = winner;
|
|
109
|
+
},
|
|
110
|
+
getNextTurn: function () {
|
|
111
|
+
return handsGenerator.next();
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
return match;
|
|
115
|
+
}
|
|
116
|
+
exports.Match = Match;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PlayInstance = void 0;
|
|
4
|
+
var types_1 = require("../types");
|
|
5
|
+
function PlayInstance(hand, teams) {
|
|
6
|
+
var _a, _b, _c;
|
|
7
|
+
var instance = {
|
|
8
|
+
state: hand.state,
|
|
9
|
+
teams: teams,
|
|
10
|
+
truco: hand.truco,
|
|
11
|
+
envido: hand.envido,
|
|
12
|
+
handIdx: hand.idx,
|
|
13
|
+
roundIdx: hand.rounds.length,
|
|
14
|
+
player: hand.currentPlayer,
|
|
15
|
+
commands: [],
|
|
16
|
+
rounds: hand.rounds,
|
|
17
|
+
use: function (idx) {
|
|
18
|
+
var player = hand.currentPlayer;
|
|
19
|
+
var round = hand.currentRound;
|
|
20
|
+
if (!player || !round) {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
var card = player.useCard(idx);
|
|
24
|
+
if (card) {
|
|
25
|
+
return round.use({ player: player, card: card });
|
|
26
|
+
}
|
|
27
|
+
return null;
|
|
28
|
+
},
|
|
29
|
+
say: function (command) {
|
|
30
|
+
var _a;
|
|
31
|
+
if (!hand.currentPlayer || !((_a = instance.commands) === null || _a === void 0 ? void 0 : _a.includes(command))) {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
hand.commands[command](hand.currentPlayer);
|
|
35
|
+
return command;
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
(_a = instance.commands) === null || _a === void 0 ? void 0 : _a.push(types_1.ESayCommand.MAZO);
|
|
39
|
+
(_b = instance.commands) === null || _b === void 0 ? void 0 : _b.push(types_1.ESayCommand.TRUCO);
|
|
40
|
+
if (hand.rounds.length === 1) {
|
|
41
|
+
(_c = instance.commands) === null || _c === void 0 ? void 0 : _c.push(types_1.EEnvidoCommand.ENVIDO);
|
|
42
|
+
}
|
|
43
|
+
return instance;
|
|
44
|
+
}
|
|
45
|
+
exports.PlayInstance = PlayInstance;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Player = void 0;
|
|
4
|
+
function Player(id, teamIdx) {
|
|
5
|
+
var player = {
|
|
6
|
+
id: id,
|
|
7
|
+
teamIdx: teamIdx,
|
|
8
|
+
hand: [],
|
|
9
|
+
usedHand: [],
|
|
10
|
+
setHand: function (hand) {
|
|
11
|
+
player.hand = hand;
|
|
12
|
+
player.usedHand = [];
|
|
13
|
+
return hand;
|
|
14
|
+
},
|
|
15
|
+
useCard: function (idx) {
|
|
16
|
+
if (player.hand[idx]) {
|
|
17
|
+
var card = player.hand.splice(idx, 1)[0];
|
|
18
|
+
player.usedHand.push(card);
|
|
19
|
+
return card;
|
|
20
|
+
}
|
|
21
|
+
return null;
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
return player;
|
|
25
|
+
}
|
|
26
|
+
exports.Player = Player;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Round = void 0;
|
|
4
|
+
var utils_1 = require("../utils");
|
|
5
|
+
function Round() {
|
|
6
|
+
var round = {
|
|
7
|
+
highest: -1,
|
|
8
|
+
winner: null,
|
|
9
|
+
cards: [],
|
|
10
|
+
tie: false,
|
|
11
|
+
use: function (_a) {
|
|
12
|
+
var _b;
|
|
13
|
+
var card = _a.card, player = _a.player;
|
|
14
|
+
var value = (0, utils_1.getCardValue)(card);
|
|
15
|
+
if (value === round.highest && player.teamIdx !== ((_b = round.winner) === null || _b === void 0 ? void 0 : _b.teamIdx)) {
|
|
16
|
+
round.tie = true;
|
|
17
|
+
}
|
|
18
|
+
if (value > round.highest) {
|
|
19
|
+
round.tie = false;
|
|
20
|
+
round.highest = value;
|
|
21
|
+
round.winner = player;
|
|
22
|
+
}
|
|
23
|
+
round.cards.push({ card: card, player: player });
|
|
24
|
+
return card;
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
return round;
|
|
28
|
+
}
|
|
29
|
+
exports.Round = Round;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Table = void 0;
|
|
4
|
+
function Table(teams, size) {
|
|
5
|
+
var table = {
|
|
6
|
+
players: [],
|
|
7
|
+
cards: [],
|
|
8
|
+
forehandIdx: 0,
|
|
9
|
+
nextTurn: function () {
|
|
10
|
+
if (table.forehandIdx < size * 2 - 1) {
|
|
11
|
+
table.forehandIdx++;
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
table.forehandIdx = 0;
|
|
15
|
+
}
|
|
16
|
+
return table.player();
|
|
17
|
+
},
|
|
18
|
+
getPlayerPosition: function (id) {
|
|
19
|
+
return table.players.findIndex(function (p) { return p.id === id; });
|
|
20
|
+
},
|
|
21
|
+
player: function (idx) {
|
|
22
|
+
if (idx !== undefined) {
|
|
23
|
+
return table.players[idx];
|
|
24
|
+
}
|
|
25
|
+
return table.players[table.forehandIdx];
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
if (teams[0].players.length != size || teams[1].players.length != size) {
|
|
29
|
+
throw new Error("Unexpected team size");
|
|
30
|
+
}
|
|
31
|
+
for (var i = 0; i < size; i++) {
|
|
32
|
+
table.players.push(teams[0].players[i]);
|
|
33
|
+
table.players.push(teams[1].players[i]);
|
|
34
|
+
}
|
|
35
|
+
return table;
|
|
36
|
+
}
|
|
37
|
+
exports.Table = Table;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Team = void 0;
|
|
4
|
+
function Team(players) {
|
|
5
|
+
var team = {
|
|
6
|
+
_players: new Map(),
|
|
7
|
+
get players() {
|
|
8
|
+
return Array.from(team._players.values());
|
|
9
|
+
},
|
|
10
|
+
points: {
|
|
11
|
+
buenas: 0,
|
|
12
|
+
malas: 0,
|
|
13
|
+
winner: false,
|
|
14
|
+
},
|
|
15
|
+
addPoints: function (matchPoint, points) {
|
|
16
|
+
var malas = team.points.malas + points;
|
|
17
|
+
var diff = malas - matchPoint;
|
|
18
|
+
if (diff > 0) {
|
|
19
|
+
team.points.malas = matchPoint;
|
|
20
|
+
team.points.buenas += diff;
|
|
21
|
+
if (team.points.buenas >= matchPoint) {
|
|
22
|
+
team.points.winner = true;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
team.points.malas = malas;
|
|
27
|
+
}
|
|
28
|
+
return team.points;
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
players.forEach(function (player) { return team._players.set(player.id, player); });
|
|
32
|
+
return team;
|
|
33
|
+
}
|
|
34
|
+
exports.Team = Team;
|
package/build/lib/constants.d.ts
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
|
+
import { IEnvidoCalculator } from "./types";
|
|
1
2
|
export declare const CARDS: {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
3
|
+
"1e": number;
|
|
4
|
+
"1b": number;
|
|
5
|
+
"7e": number;
|
|
6
|
+
"7o": number;
|
|
7
|
+
"3e": number;
|
|
8
|
+
"3o": number;
|
|
9
|
+
"3b": number;
|
|
10
|
+
"3c": number;
|
|
11
|
+
"2e": number;
|
|
12
|
+
"2o": number;
|
|
13
|
+
"2b": number;
|
|
14
|
+
"2c": number;
|
|
15
|
+
"1o": number;
|
|
16
|
+
"1c": number;
|
|
16
17
|
re: number;
|
|
17
18
|
ro: number;
|
|
18
19
|
rb: number;
|
|
@@ -25,19 +26,20 @@ export declare const CARDS: {
|
|
|
25
26
|
po: number;
|
|
26
27
|
pb: number;
|
|
27
28
|
pc: number;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
29
|
+
"7b": number;
|
|
30
|
+
"7c": number;
|
|
31
|
+
"6e": number;
|
|
32
|
+
"6o": number;
|
|
33
|
+
"6b": number;
|
|
34
|
+
"6c": number;
|
|
35
|
+
"5e": number;
|
|
36
|
+
"5o": number;
|
|
37
|
+
"5b": number;
|
|
38
|
+
"5c": number;
|
|
39
|
+
"4e": number;
|
|
40
|
+
"4o": number;
|
|
41
|
+
"4b": number;
|
|
42
|
+
"4c": number;
|
|
42
43
|
};
|
|
43
44
|
export declare const COLORS: string[];
|
|
45
|
+
export declare const EnvidoCalculator: IEnvidoCalculator;
|