trucoshi 0.0.2 → 0.0.5
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 +37 -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 +233 -0
- package/build/lib/classes/Match.d.ts +2 -0
- package/build/lib/classes/Match.js +115 -0
- package/build/lib/classes/Play.d.ts +2 -0
- package/build/lib/classes/Play.js +39 -0
- package/build/lib/classes/Player.d.ts +2 -0
- package/build/lib/classes/Player.js +38 -0
- package/build/lib/classes/Round.d.ts +2 -0
- package/build/lib/classes/Round.js +33 -0
- package/build/lib/classes/Table.d.ts +2 -0
- package/build/lib/classes/Table.js +30 -0
- package/build/lib/classes/Team.d.ts +2 -0
- package/build/lib/classes/Team.js +42 -0
- package/build/lib/classes/Truco.d.ts +2 -0
- package/build/lib/classes/Truco.js +110 -0
- package/build/lib/constants.d.ts +36 -28
- package/build/lib/constants.js +97 -12
- package/build/lib/index.d.ts +18 -0
- package/build/lib/index.js +161 -0
- package/build/lib/types.d.ts +121 -30
- package/build/lib/types.js +24 -12
- package/build/lib/utils.d.ts +3 -3
- package/build/lib/utils.js +11 -18
- package/build/server/index.js +13 -5
- package/build/server/match.d.ts +0 -0
- package/build/server/match.js +1 -0
- package/build/server/types.d.ts +11 -0
- package/build/server/types.js +15 -0
- package/build/test/autoplay.js +52 -31
- package/build/test/play.js +146 -81
- package/package.json +5 -4
- package/src/lib/classes/Deck.ts +25 -0
- package/src/lib/classes/Hand.ts +207 -0
- package/src/lib/classes/Match.ts +79 -0
- package/src/lib/classes/Play.ts +40 -0
- package/src/lib/classes/Player.ts +37 -0
- package/src/lib/classes/Round.ts +30 -0
- package/src/lib/classes/Table.ts +32 -0
- package/src/lib/classes/Team.ts +41 -0
- package/src/lib/classes/Truco.ts +72 -0
- package/src/lib/constants.ts +105 -11
- package/src/lib/index.ts +135 -0
- package/src/lib/types.ts +186 -80
- package/src/lib/utils.ts +50 -53
- package/src/server/index.ts +34 -22
- package/src/server/match.ts +0 -0
- package/src/server/types.ts +12 -0
- package/src/test/autoplay.ts +57 -41
- package/src/test/play.ts +122 -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,37 @@
|
|
|
1
|
+
# Trucoshi
|
|
2
|
+
|
|
3
|
+
### English
|
|
4
|
+
Pretends to be an Argentinian Truco game socket server that allows you to put Satoshis on the table ;)
|
|
5
|
+
|
|
6
|
+
### Spanish
|
|
7
|
+
Pretende ser un server basado en sockets del juego de Truco Argentino que te permita poner unos Satoshis en la mesa ;)
|
|
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
|
+
[] Bitcoin Lightning integration
|
|
29
|
+
[] Unit tests
|
|
30
|
+
|
|
31
|
+
# License
|
|
32
|
+
|
|
33
|
+
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.
|
|
34
|
+
|
|
35
|
+
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.
|
|
36
|
+
|
|
37
|
+
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,233 @@
|
|
|
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
|
+
var Truco_1 = require("./Truco");
|
|
36
|
+
function Hand(match, deck, idx) {
|
|
37
|
+
var _a;
|
|
38
|
+
match.teams.forEach(function (team) {
|
|
39
|
+
team.players.forEach(function (player) {
|
|
40
|
+
var playerHand = [deck.takeCard(), deck.takeCard(), deck.takeCard()];
|
|
41
|
+
player.setHand(playerHand);
|
|
42
|
+
player.enable();
|
|
43
|
+
// player.setHand(["5c", "4c", "6c"])
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
function roundsGeneratorSequence() {
|
|
47
|
+
var currentRoundIdx, forehandTeamIdx, round, previousRound, newTurn, value, player, winnerTeamIdx;
|
|
48
|
+
return __generator(this, function (_a) {
|
|
49
|
+
switch (_a.label) {
|
|
50
|
+
case 0:
|
|
51
|
+
currentRoundIdx = 0;
|
|
52
|
+
forehandTeamIdx = match.table.player(hand.turn).teamIdx;
|
|
53
|
+
_a.label = 1;
|
|
54
|
+
case 1:
|
|
55
|
+
if (!(currentRoundIdx < 3 && !hand.finished())) return [3 /*break*/, 9];
|
|
56
|
+
round = (0, Round_1.Round)(0);
|
|
57
|
+
hand.setCurrentRound(round);
|
|
58
|
+
hand.pushRound(round);
|
|
59
|
+
previousRound = hand.rounds[currentRoundIdx - 1];
|
|
60
|
+
// Put previous round winner as forehand
|
|
61
|
+
if (previousRound && previousRound.winner && !previousRound.tie) {
|
|
62
|
+
newTurn = match.table.getPlayerPosition(previousRound.winner.id);
|
|
63
|
+
if (newTurn !== -1) {
|
|
64
|
+
hand.setTurn(newTurn);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
_a.label = 2;
|
|
68
|
+
case 2:
|
|
69
|
+
if (!(round.turn < match.table.players.length)) return [3 /*break*/, 8];
|
|
70
|
+
_a.label = 3;
|
|
71
|
+
case 3:
|
|
72
|
+
if (!(hand.state === types_1.EHandState.WAITING_FOR_TRUCO_ANSWER)) return [3 /*break*/, 6];
|
|
73
|
+
value = hand.truco.getNextPlayer().value;
|
|
74
|
+
if (!(value && value.currentPlayer)) return [3 /*break*/, 5];
|
|
75
|
+
console.log({ value: value.currentPlayer });
|
|
76
|
+
hand.setCurrentPlayer(value.currentPlayer);
|
|
77
|
+
return [4 /*yield*/, hand];
|
|
78
|
+
case 4:
|
|
79
|
+
_a.sent();
|
|
80
|
+
_a.label = 5;
|
|
81
|
+
case 5: return [3 /*break*/, 3];
|
|
82
|
+
case 6:
|
|
83
|
+
player = match.table.player(hand.turn);
|
|
84
|
+
hand.setCurrentPlayer(player);
|
|
85
|
+
if (player.disabled) {
|
|
86
|
+
hand.setCurrentPlayer(null);
|
|
87
|
+
}
|
|
88
|
+
return [4 /*yield*/, hand];
|
|
89
|
+
case 7:
|
|
90
|
+
_a.sent();
|
|
91
|
+
return [3 /*break*/, 2];
|
|
92
|
+
case 8:
|
|
93
|
+
if (match.teams[0].isTeamDisabled() && match.teams[1].isTeamDisabled()) {
|
|
94
|
+
hand.setState(types_1.EHandState.FINISHED);
|
|
95
|
+
return [3 /*break*/, 9];
|
|
96
|
+
}
|
|
97
|
+
winnerTeamIdx = (0, utils_1.checkHandWinner)(hand.rounds, forehandTeamIdx);
|
|
98
|
+
if (match.teams[0].isTeamDisabled()) {
|
|
99
|
+
winnerTeamIdx = 1;
|
|
100
|
+
}
|
|
101
|
+
if (match.teams[1].isTeamDisabled()) {
|
|
102
|
+
winnerTeamIdx = 0;
|
|
103
|
+
}
|
|
104
|
+
if (winnerTeamIdx !== null) {
|
|
105
|
+
hand.addPoints(winnerTeamIdx, hand.truco.state);
|
|
106
|
+
hand.setState(types_1.EHandState.FINISHED);
|
|
107
|
+
}
|
|
108
|
+
currentRoundIdx++;
|
|
109
|
+
return [3 /*break*/, 1];
|
|
110
|
+
case 9: return [4 /*yield*/, hand];
|
|
111
|
+
case 10:
|
|
112
|
+
_a.sent();
|
|
113
|
+
return [2 /*return*/];
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
var roundsGenerator = roundsGeneratorSequence();
|
|
118
|
+
var commands = (_a = {},
|
|
119
|
+
_a[types_1.ESayCommand.MAZO] = function (player) {
|
|
120
|
+
hand.disablePlayer(player);
|
|
121
|
+
},
|
|
122
|
+
_a[types_1.ESayCommand.TRUCO] = function (player) {
|
|
123
|
+
var teamIdx = hand.truco.teamIdx;
|
|
124
|
+
if (teamIdx === null || teamIdx !== player.teamIdx) {
|
|
125
|
+
hand.setState(types_1.EHandState.WAITING_FOR_TRUCO_ANSWER);
|
|
126
|
+
hand.truco.sayTruco(player.teamIdx, match.teams[Number(!player.teamIdx)].players);
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
_a[types_1.ESayCommand.QUIERO] = function () {
|
|
130
|
+
if (hand.state === types_1.EHandState.WAITING_FOR_TRUCO_ANSWER) {
|
|
131
|
+
hand.truco.setAnswer(true);
|
|
132
|
+
hand.setState(types_1.EHandState.WAITING_PLAY);
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
_a[types_1.ESayCommand.NO_QUIERO] = function (player) {
|
|
136
|
+
if (hand.state === types_1.EHandState.WAITING_FOR_TRUCO_ANSWER) {
|
|
137
|
+
hand.truco.setAnswer(false);
|
|
138
|
+
hand.setState(types_1.EHandState.WAITING_PLAY);
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
_a[types_1.ESayCommand.FLOR] = function () { },
|
|
142
|
+
_a[types_1.ESayCommand.CONTRAFLOR] = function () { },
|
|
143
|
+
_a[types_1.EEnvidoCommand.ENVIDO] = function () { },
|
|
144
|
+
_a[types_1.EEnvidoCommand.ENVIDO_ENVIDO] = function () { },
|
|
145
|
+
_a[types_1.EEnvidoCommand.REAL_ENVIDO] = function () { },
|
|
146
|
+
_a[types_1.EEnvidoCommand.FALTA_ENVIDO] = function () { },
|
|
147
|
+
_a);
|
|
148
|
+
var hand = {
|
|
149
|
+
idx: idx,
|
|
150
|
+
turn: Number(match.table.forehandIdx),
|
|
151
|
+
state: types_1.EHandState.WAITING_PLAY,
|
|
152
|
+
rounds: [],
|
|
153
|
+
truco: (0, Truco_1.Truco)(),
|
|
154
|
+
envido: {
|
|
155
|
+
accept: 1,
|
|
156
|
+
decline: 2,
|
|
157
|
+
teamIdx: null,
|
|
158
|
+
},
|
|
159
|
+
points: [0, 0],
|
|
160
|
+
currentRound: null,
|
|
161
|
+
_currentPlayer: null,
|
|
162
|
+
set currentPlayer(player) {
|
|
163
|
+
hand._currentPlayer = player;
|
|
164
|
+
},
|
|
165
|
+
get currentPlayer() {
|
|
166
|
+
if (hand.state === types_1.EHandState.WAITING_FOR_TRUCO_ANSWER) {
|
|
167
|
+
return hand.truco.currentPlayer;
|
|
168
|
+
}
|
|
169
|
+
return hand._currentPlayer;
|
|
170
|
+
},
|
|
171
|
+
commands: commands,
|
|
172
|
+
play: function () {
|
|
173
|
+
return (0, Play_1.PlayInstance)(hand, match.teams);
|
|
174
|
+
},
|
|
175
|
+
use: function (idx) {
|
|
176
|
+
var player = hand.currentPlayer;
|
|
177
|
+
var round = hand.currentRound;
|
|
178
|
+
if (!player || !round) {
|
|
179
|
+
return null;
|
|
180
|
+
}
|
|
181
|
+
var card = player.useCard(idx);
|
|
182
|
+
if (card) {
|
|
183
|
+
hand.nextTurn();
|
|
184
|
+
return round.use({ player: player, card: card });
|
|
185
|
+
}
|
|
186
|
+
return null;
|
|
187
|
+
},
|
|
188
|
+
nextTurn: function () {
|
|
189
|
+
var _a;
|
|
190
|
+
if (hand.turn >= match.table.players.length - 1) {
|
|
191
|
+
hand.setTurn(0);
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
hand.setTurn(hand.turn + 1);
|
|
195
|
+
}
|
|
196
|
+
(_a = hand.currentRound) === null || _a === void 0 ? void 0 : _a.nextTurn();
|
|
197
|
+
},
|
|
198
|
+
getNextPlayer: function () {
|
|
199
|
+
return roundsGenerator.next();
|
|
200
|
+
},
|
|
201
|
+
disablePlayer: function (player) {
|
|
202
|
+
match.teams[player.teamIdx].disable(player);
|
|
203
|
+
},
|
|
204
|
+
addPoints: function (team, points) {
|
|
205
|
+
hand.points[team] = hand.points[team] + points;
|
|
206
|
+
},
|
|
207
|
+
pushRound: function (round) {
|
|
208
|
+
hand.rounds.push(round);
|
|
209
|
+
return round;
|
|
210
|
+
},
|
|
211
|
+
setTurn: function (turn) {
|
|
212
|
+
hand.turn = turn;
|
|
213
|
+
return match.table.player(hand.turn);
|
|
214
|
+
},
|
|
215
|
+
setCurrentRound: function (round) {
|
|
216
|
+
hand.currentRound = round;
|
|
217
|
+
return hand.currentRound;
|
|
218
|
+
},
|
|
219
|
+
setCurrentPlayer: function (player) {
|
|
220
|
+
hand._currentPlayer = player;
|
|
221
|
+
return hand._currentPlayer;
|
|
222
|
+
},
|
|
223
|
+
setState: function (state) {
|
|
224
|
+
hand.state = state;
|
|
225
|
+
return hand.state;
|
|
226
|
+
},
|
|
227
|
+
finished: function () {
|
|
228
|
+
return hand.state === types_1.EHandState.FINISHED;
|
|
229
|
+
},
|
|
230
|
+
};
|
|
231
|
+
return hand;
|
|
232
|
+
}
|
|
233
|
+
exports.Hand = Hand;
|
|
@@ -0,0 +1,115 @@
|
|
|
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
|
+
function Match(table, teams, matchPoint) {
|
|
34
|
+
if (teams === void 0) { teams = []; }
|
|
35
|
+
if (matchPoint === void 0) { matchPoint = 9; }
|
|
36
|
+
var deck = (0, Deck_1.Deck)().shuffle();
|
|
37
|
+
var size = teams[0].players.length;
|
|
38
|
+
if (size !== teams[1].players.length) {
|
|
39
|
+
throw new Error("Team size mismatch");
|
|
40
|
+
}
|
|
41
|
+
function handsGeneratorSequence() {
|
|
42
|
+
var hand, value, teams_1, winner;
|
|
43
|
+
return __generator(this, function (_a) {
|
|
44
|
+
switch (_a.label) {
|
|
45
|
+
case 0:
|
|
46
|
+
if (!!match.winner) return [3 /*break*/, 4];
|
|
47
|
+
deck.shuffle();
|
|
48
|
+
hand = match.setCurrentHand((0, Hand_1.Hand)(match, deck, match.hands.length + 1));
|
|
49
|
+
match.pushHand(hand);
|
|
50
|
+
_a.label = 1;
|
|
51
|
+
case 1:
|
|
52
|
+
if (!!hand.finished()) return [3 /*break*/, 3];
|
|
53
|
+
value = hand.getNextPlayer().value;
|
|
54
|
+
if (value && value.finished()) {
|
|
55
|
+
return [3 /*break*/, 1];
|
|
56
|
+
}
|
|
57
|
+
match.setCurrentHand(value);
|
|
58
|
+
return [4 /*yield*/, match];
|
|
59
|
+
case 2:
|
|
60
|
+
_a.sent();
|
|
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*/];
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
var handsGenerator = handsGeneratorSequence();
|
|
81
|
+
var match = {
|
|
82
|
+
winner: null,
|
|
83
|
+
teams: teams,
|
|
84
|
+
hands: [],
|
|
85
|
+
table: table,
|
|
86
|
+
currentHand: null,
|
|
87
|
+
play: function () {
|
|
88
|
+
match.getNextTurn();
|
|
89
|
+
if (!match.currentHand) {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
return match.currentHand.play();
|
|
93
|
+
},
|
|
94
|
+
addPoints: function (points) {
|
|
95
|
+
match.teams[0].addPoints(matchPoint, points[0]);
|
|
96
|
+
match.teams[1].addPoints(matchPoint, points[1]);
|
|
97
|
+
return match.teams;
|
|
98
|
+
},
|
|
99
|
+
pushHand: function (hand) {
|
|
100
|
+
match.hands.push(hand);
|
|
101
|
+
},
|
|
102
|
+
setCurrentHand: function (hand) {
|
|
103
|
+
match.currentHand = hand;
|
|
104
|
+
return match.currentHand;
|
|
105
|
+
},
|
|
106
|
+
setWinner: function (winner) {
|
|
107
|
+
match.winner = winner;
|
|
108
|
+
},
|
|
109
|
+
getNextTurn: function () {
|
|
110
|
+
return handsGenerator.next();
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
return match;
|
|
114
|
+
}
|
|
115
|
+
exports.Match = Match;
|
|
@@ -0,0 +1,39 @@
|
|
|
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
|
+
return hand.use(idx);
|
|
19
|
+
},
|
|
20
|
+
say: function (command) {
|
|
21
|
+
var _a;
|
|
22
|
+
if (!hand._currentPlayer || !((_a = instance.commands) === null || _a === void 0 ? void 0 : _a.includes(command))) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
hand.commands[command](hand._currentPlayer);
|
|
26
|
+
return command;
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
(_a = instance.commands) === null || _a === void 0 ? void 0 : _a.push(types_1.ESayCommand.MAZO);
|
|
30
|
+
(_b = instance.commands) === null || _b === void 0 ? void 0 : _b.push(types_1.ESayCommand.TRUCO);
|
|
31
|
+
if (hand.rounds.length === 1) {
|
|
32
|
+
(_c = instance.commands) === null || _c === void 0 ? void 0 : _c.push(types_1.EEnvidoCommand.ENVIDO);
|
|
33
|
+
}
|
|
34
|
+
if (hand.state === types_1.EHandState.WAITING_FOR_TRUCO_ANSWER) {
|
|
35
|
+
instance.commands = [types_1.ESayCommand.TRUCO, types_1.ESayCommand.QUIERO, types_1.ESayCommand.NO_QUIERO];
|
|
36
|
+
}
|
|
37
|
+
return instance;
|
|
38
|
+
}
|
|
39
|
+
exports.PlayInstance = PlayInstance;
|
|
@@ -0,0 +1,38 @@
|
|
|
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
|
+
commands: [],
|
|
10
|
+
usedHand: [],
|
|
11
|
+
disabled: false,
|
|
12
|
+
ready: false,
|
|
13
|
+
enable: function () {
|
|
14
|
+
player.disabled = false;
|
|
15
|
+
},
|
|
16
|
+
disable: function () {
|
|
17
|
+
player.disabled = true;
|
|
18
|
+
},
|
|
19
|
+
setReady: function (ready) {
|
|
20
|
+
player.ready = ready;
|
|
21
|
+
},
|
|
22
|
+
setHand: function (hand) {
|
|
23
|
+
player.hand = hand;
|
|
24
|
+
player.usedHand = [];
|
|
25
|
+
return hand;
|
|
26
|
+
},
|
|
27
|
+
useCard: function (idx) {
|
|
28
|
+
if (player.hand[idx]) {
|
|
29
|
+
var card = player.hand.splice(idx, 1)[0];
|
|
30
|
+
player.usedHand.push(card);
|
|
31
|
+
return card;
|
|
32
|
+
}
|
|
33
|
+
return null;
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
return player;
|
|
37
|
+
}
|
|
38
|
+
exports.Player = Player;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Round = void 0;
|
|
4
|
+
var utils_1 = require("../utils");
|
|
5
|
+
function Round(turn) {
|
|
6
|
+
var round = {
|
|
7
|
+
turn: turn,
|
|
8
|
+
highest: -1,
|
|
9
|
+
winner: null,
|
|
10
|
+
cards: [],
|
|
11
|
+
tie: false,
|
|
12
|
+
nextTurn: function () {
|
|
13
|
+
round.turn++;
|
|
14
|
+
},
|
|
15
|
+
use: function (_a) {
|
|
16
|
+
var _b;
|
|
17
|
+
var card = _a.card, player = _a.player;
|
|
18
|
+
var value = (0, utils_1.getCardValue)(card);
|
|
19
|
+
if (value === round.highest && player.teamIdx !== ((_b = round.winner) === null || _b === void 0 ? void 0 : _b.teamIdx)) {
|
|
20
|
+
round.tie = true;
|
|
21
|
+
}
|
|
22
|
+
if (value > round.highest) {
|
|
23
|
+
round.tie = false;
|
|
24
|
+
round.highest = value;
|
|
25
|
+
round.winner = player;
|
|
26
|
+
}
|
|
27
|
+
round.cards.push({ card: card, player: player });
|
|
28
|
+
return card;
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
return round;
|
|
32
|
+
}
|
|
33
|
+
exports.Round = Round;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Table = void 0;
|
|
4
|
+
function Table(players, teams) {
|
|
5
|
+
var table = {
|
|
6
|
+
players: players,
|
|
7
|
+
cards: [],
|
|
8
|
+
forehandIdx: 0,
|
|
9
|
+
nextTurn: function () {
|
|
10
|
+
if (table.forehandIdx < table.players.length - 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
|
+
return table;
|
|
29
|
+
}
|
|
30
|
+
exports.Table = Table;
|
|
@@ -0,0 +1,42 @@
|
|
|
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
|
+
isTeamDisabled: function () {
|
|
16
|
+
return team.players.reduce(function (prev, curr) { return prev && curr.disabled; }, true);
|
|
17
|
+
},
|
|
18
|
+
disable: function (player) {
|
|
19
|
+
var _a;
|
|
20
|
+
(_a = team._players.get(player.id)) === null || _a === void 0 ? void 0 : _a.disable();
|
|
21
|
+
return team.isTeamDisabled();
|
|
22
|
+
},
|
|
23
|
+
addPoints: function (matchPoint, points) {
|
|
24
|
+
var malas = team.points.malas + points;
|
|
25
|
+
var diff = malas - matchPoint;
|
|
26
|
+
if (diff > 0) {
|
|
27
|
+
team.points.malas = matchPoint;
|
|
28
|
+
team.points.buenas += diff;
|
|
29
|
+
if (team.points.buenas >= matchPoint) {
|
|
30
|
+
team.points.winner = true;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
team.points.malas = malas;
|
|
35
|
+
}
|
|
36
|
+
return team.points;
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
players.forEach(function (player) { return team._players.set(player.id, player); });
|
|
40
|
+
return team;
|
|
41
|
+
}
|
|
42
|
+
exports.Team = Team;
|