trucoshi 0.0.4 → 0.0.6
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 +3 -2
- package/build/lib/classes/Hand.js +87 -29
- package/build/lib/classes/Match.d.ts +2 -2
- package/build/lib/classes/Match.js +2 -3
- package/build/lib/classes/Play.js +6 -12
- package/build/lib/classes/Player.js +12 -0
- package/build/lib/classes/Round.d.ts +1 -1
- package/build/lib/classes/Round.js +5 -1
- package/build/lib/classes/Table.d.ts +2 -2
- package/build/lib/classes/Table.js +3 -10
- package/build/lib/classes/Team.js +8 -0
- package/build/lib/classes/Truco.d.ts +2 -0
- package/build/lib/classes/Truco.js +110 -0
- package/build/lib/constants.d.ts +6 -0
- package/build/lib/constants.js +8 -1
- package/build/lib/index.d.ts +13 -6
- package/build/lib/index.js +83 -10
- package/build/lib/types.d.ts +50 -5
- package/build/lib/types.js +2 -0
- package/build/lib/utils.d.ts +2 -2
- package/build/lib/utils.js +1 -18
- package/build/server/match.d.ts +0 -0
- package/build/server/match.js +1 -0
- package/build/test/autoplay.js +11 -2
- package/build/test/play.js +70 -51
- package/package.json +3 -2
- package/src/lib/classes/Hand.ts +82 -26
- package/src/lib/classes/Match.ts +3 -4
- package/src/lib/classes/Play.ts +9 -17
- package/src/lib/classes/Player.ts +13 -1
- package/src/lib/classes/Round.ts +5 -1
- package/src/lib/classes/Table.ts +8 -13
- package/src/lib/classes/Team.ts +7 -0
- package/src/lib/classes/Truco.ts +72 -0
- package/src/lib/constants.ts +8 -0
- package/src/lib/index.ts +95 -17
- package/src/lib/types.ts +51 -5
- package/src/lib/utils.ts +1 -22
- package/src/server/match.ts +0 -0
- package/src/test/autoplay.ts +12 -2
- package/src/test/play.ts +64 -55
package/README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# Trucoshi
|
|
2
2
|
|
|
3
3
|
### English
|
|
4
|
-
Pretends to be an Argentinian Truco game socket server
|
|
4
|
+
Pretends to be an Argentinian Truco game socket server that allows you to put Satoshis on the table ;)
|
|
5
5
|
|
|
6
6
|
### Spanish
|
|
7
|
-
Pretende ser un server basado en sockets del juego de Truco Argentino
|
|
7
|
+
Pretende ser un server basado en sockets del juego de Truco Argentino que te permita poner unos Satoshis en la mesa ;)
|
|
8
8
|
|
|
9
9
|
# Test
|
|
10
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.
|
|
@@ -25,6 +25,7 @@ Right now there's only a local CLI way of playing as there is no socket server i
|
|
|
25
25
|
[] Cantar envido
|
|
26
26
|
[] Cantar flor
|
|
27
27
|
[] Socket server
|
|
28
|
+
[] Bitcoin Lightning integration
|
|
28
29
|
[] Unit tests
|
|
29
30
|
|
|
30
31
|
# License
|
|
@@ -32,17 +32,19 @@ var types_1 = require("../types");
|
|
|
32
32
|
var utils_1 = require("../utils");
|
|
33
33
|
var Play_1 = require("./Play");
|
|
34
34
|
var Round_1 = require("./Round");
|
|
35
|
+
var Truco_1 = require("./Truco");
|
|
35
36
|
function Hand(match, deck, idx) {
|
|
36
37
|
var _a;
|
|
37
38
|
match.teams.forEach(function (team) {
|
|
38
39
|
team.players.forEach(function (player) {
|
|
39
40
|
var playerHand = [deck.takeCard(), deck.takeCard(), deck.takeCard()];
|
|
40
41
|
player.setHand(playerHand);
|
|
42
|
+
player.enable();
|
|
41
43
|
// player.setHand(["5c", "4c", "6c"])
|
|
42
44
|
});
|
|
43
45
|
});
|
|
44
46
|
function roundsGeneratorSequence() {
|
|
45
|
-
var currentRoundIdx, forehandTeamIdx,
|
|
47
|
+
var currentRoundIdx, forehandTeamIdx, round, previousRound, newTurn, value, player, winnerTeamIdx;
|
|
46
48
|
return __generator(this, function (_a) {
|
|
47
49
|
switch (_a.label) {
|
|
48
50
|
case 0:
|
|
@@ -50,9 +52,8 @@ function Hand(match, deck, idx) {
|
|
|
50
52
|
forehandTeamIdx = match.table.player(hand.turn).teamIdx;
|
|
51
53
|
_a.label = 1;
|
|
52
54
|
case 1:
|
|
53
|
-
if (!(currentRoundIdx < 3 && !hand.finished())) return [3 /*break*/,
|
|
54
|
-
|
|
55
|
-
round = (0, Round_1.Round)();
|
|
55
|
+
if (!(currentRoundIdx < 3 && !hand.finished())) return [3 /*break*/, 9];
|
|
56
|
+
round = (0, Round_1.Round)(0);
|
|
56
57
|
hand.setCurrentRound(round);
|
|
57
58
|
hand.pushRound(round);
|
|
58
59
|
previousRound = hand.rounds[currentRoundIdx - 1];
|
|
@@ -65,33 +66,49 @@ function Hand(match, deck, idx) {
|
|
|
65
66
|
}
|
|
66
67
|
_a.label = 2;
|
|
67
68
|
case 2:
|
|
68
|
-
if (!(
|
|
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:
|
|
69
83
|
player = match.table.player(hand.turn);
|
|
70
84
|
hand.setCurrentPlayer(player);
|
|
71
|
-
if (
|
|
85
|
+
if (player.disabled) {
|
|
72
86
|
hand.setCurrentPlayer(null);
|
|
73
87
|
}
|
|
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
88
|
return [4 /*yield*/, hand];
|
|
82
|
-
case
|
|
89
|
+
case 7:
|
|
83
90
|
_a.sent();
|
|
84
91
|
return [3 /*break*/, 2];
|
|
85
|
-
case
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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);
|
|
89
106
|
hand.setState(types_1.EHandState.FINISHED);
|
|
90
107
|
}
|
|
91
108
|
currentRoundIdx++;
|
|
92
109
|
return [3 /*break*/, 1];
|
|
93
|
-
case
|
|
94
|
-
case
|
|
110
|
+
case 9: return [4 /*yield*/, hand];
|
|
111
|
+
case 10:
|
|
95
112
|
_a.sent();
|
|
96
113
|
return [2 /*return*/];
|
|
97
114
|
}
|
|
@@ -106,6 +123,19 @@ function Hand(match, deck, idx) {
|
|
|
106
123
|
var teamIdx = hand.truco.teamIdx;
|
|
107
124
|
if (teamIdx === null || teamIdx !== player.teamIdx) {
|
|
108
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);
|
|
109
139
|
}
|
|
110
140
|
},
|
|
111
141
|
_a[types_1.ESayCommand.FLOR] = function () { },
|
|
@@ -120,28 +150,56 @@ function Hand(match, deck, idx) {
|
|
|
120
150
|
turn: Number(match.table.forehandIdx),
|
|
121
151
|
state: types_1.EHandState.WAITING_PLAY,
|
|
122
152
|
rounds: [],
|
|
123
|
-
truco:
|
|
124
|
-
state: 1,
|
|
125
|
-
teamIdx: null,
|
|
126
|
-
},
|
|
153
|
+
truco: (0, Truco_1.Truco)(),
|
|
127
154
|
envido: {
|
|
128
155
|
accept: 1,
|
|
129
156
|
decline: 2,
|
|
130
157
|
teamIdx: null,
|
|
131
158
|
},
|
|
132
159
|
points: [0, 0],
|
|
133
|
-
disabledPlayerIds: [],
|
|
134
160
|
currentRound: null,
|
|
135
|
-
|
|
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
|
+
},
|
|
136
171
|
commands: commands,
|
|
137
172
|
play: function () {
|
|
138
173
|
return (0, Play_1.PlayInstance)(hand, match.teams);
|
|
139
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
|
+
},
|
|
140
198
|
getNextPlayer: function () {
|
|
141
199
|
return roundsGenerator.next();
|
|
142
200
|
},
|
|
143
201
|
disablePlayer: function (player) {
|
|
144
|
-
|
|
202
|
+
match.teams[player.teamIdx].disable(player);
|
|
145
203
|
},
|
|
146
204
|
addPoints: function (team, points) {
|
|
147
205
|
hand.points[team] = hand.points[team] + points;
|
|
@@ -159,8 +217,8 @@ function Hand(match, deck, idx) {
|
|
|
159
217
|
return hand.currentRound;
|
|
160
218
|
},
|
|
161
219
|
setCurrentPlayer: function (player) {
|
|
162
|
-
hand.
|
|
163
|
-
return hand.
|
|
220
|
+
hand._currentPlayer = player;
|
|
221
|
+
return hand._currentPlayer;
|
|
164
222
|
},
|
|
165
223
|
setState: function (state) {
|
|
166
224
|
hand.state = state;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { IMatch, ITeam } from "../types";
|
|
2
|
-
export declare function Match(teams?: Array<ITeam>, matchPoint?: number): IMatch;
|
|
1
|
+
import { IMatch, ITable, ITeam } from "../types";
|
|
2
|
+
export declare function Match(table: ITable, teams?: Array<ITeam>, matchPoint?: number): IMatch;
|
|
@@ -30,8 +30,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
30
30
|
exports.Match = void 0;
|
|
31
31
|
var Deck_1 = require("./Deck");
|
|
32
32
|
var Hand_1 = require("./Hand");
|
|
33
|
-
|
|
34
|
-
function Match(teams, matchPoint) {
|
|
33
|
+
function Match(table, teams, matchPoint) {
|
|
35
34
|
if (teams === void 0) { teams = []; }
|
|
36
35
|
if (matchPoint === void 0) { matchPoint = 9; }
|
|
37
36
|
var deck = (0, Deck_1.Deck)().shuffle();
|
|
@@ -83,7 +82,7 @@ function Match(teams, matchPoint) {
|
|
|
83
82
|
winner: null,
|
|
84
83
|
teams: teams,
|
|
85
84
|
hands: [],
|
|
86
|
-
table:
|
|
85
|
+
table: table,
|
|
87
86
|
currentHand: null,
|
|
88
87
|
play: function () {
|
|
89
88
|
match.getNextTurn();
|
|
@@ -15,23 +15,14 @@ function PlayInstance(hand, teams) {
|
|
|
15
15
|
commands: [],
|
|
16
16
|
rounds: hand.rounds,
|
|
17
17
|
use: function (idx) {
|
|
18
|
-
|
|
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;
|
|
18
|
+
return hand.use(idx);
|
|
28
19
|
},
|
|
29
20
|
say: function (command) {
|
|
30
21
|
var _a;
|
|
31
|
-
if (!hand.
|
|
22
|
+
if (!hand._currentPlayer || !((_a = instance.commands) === null || _a === void 0 ? void 0 : _a.includes(command))) {
|
|
32
23
|
return null;
|
|
33
24
|
}
|
|
34
|
-
hand.commands[command](hand.
|
|
25
|
+
hand.commands[command](hand._currentPlayer);
|
|
35
26
|
return command;
|
|
36
27
|
},
|
|
37
28
|
};
|
|
@@ -40,6 +31,9 @@ function PlayInstance(hand, teams) {
|
|
|
40
31
|
if (hand.rounds.length === 1) {
|
|
41
32
|
(_c = instance.commands) === null || _c === void 0 ? void 0 : _c.push(types_1.EEnvidoCommand.ENVIDO);
|
|
42
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
|
+
}
|
|
43
37
|
return instance;
|
|
44
38
|
}
|
|
45
39
|
exports.PlayInstance = PlayInstance;
|
|
@@ -6,7 +6,19 @@ function Player(id, teamIdx) {
|
|
|
6
6
|
id: id,
|
|
7
7
|
teamIdx: teamIdx,
|
|
8
8
|
hand: [],
|
|
9
|
+
commands: [],
|
|
9
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
|
+
},
|
|
10
22
|
setHand: function (hand) {
|
|
11
23
|
player.hand = hand;
|
|
12
24
|
player.usedHand = [];
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { IRound } from "../types";
|
|
2
|
-
export declare function Round(): IRound;
|
|
2
|
+
export declare function Round(turn: number): IRound;
|
|
@@ -2,12 +2,16 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Round = void 0;
|
|
4
4
|
var utils_1 = require("../utils");
|
|
5
|
-
function Round() {
|
|
5
|
+
function Round(turn) {
|
|
6
6
|
var round = {
|
|
7
|
+
turn: turn,
|
|
7
8
|
highest: -1,
|
|
8
9
|
winner: null,
|
|
9
10
|
cards: [],
|
|
10
11
|
tie: false,
|
|
12
|
+
nextTurn: function () {
|
|
13
|
+
round.turn++;
|
|
14
|
+
},
|
|
11
15
|
use: function (_a) {
|
|
12
16
|
var _b;
|
|
13
17
|
var card = _a.card, player = _a.player;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { ITable, ITeam } from "../types";
|
|
2
|
-
export declare function Table(
|
|
1
|
+
import { IPlayer, ITable, ITeam } from "../types";
|
|
2
|
+
export declare function Table(players: Array<IPlayer>, teams: Array<ITeam>): ITable;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Table = void 0;
|
|
4
|
-
function Table(
|
|
4
|
+
function Table(players, teams) {
|
|
5
5
|
var table = {
|
|
6
|
-
players:
|
|
6
|
+
players: players,
|
|
7
7
|
cards: [],
|
|
8
8
|
forehandIdx: 0,
|
|
9
9
|
nextTurn: function () {
|
|
10
|
-
if (table.forehandIdx <
|
|
10
|
+
if (table.forehandIdx < table.players.length - 1) {
|
|
11
11
|
table.forehandIdx++;
|
|
12
12
|
}
|
|
13
13
|
else {
|
|
@@ -25,13 +25,6 @@ function Table(teams, size) {
|
|
|
25
25
|
return table.players[table.forehandIdx];
|
|
26
26
|
},
|
|
27
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
28
|
return table;
|
|
36
29
|
}
|
|
37
30
|
exports.Table = Table;
|
|
@@ -12,6 +12,14 @@ function Team(players) {
|
|
|
12
12
|
malas: 0,
|
|
13
13
|
winner: false,
|
|
14
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
|
+
},
|
|
15
23
|
addPoints: function (matchPoint, points) {
|
|
16
24
|
var malas = team.points.malas + points;
|
|
17
25
|
var diff = malas - matchPoint;
|
|
@@ -0,0 +1,110 @@
|
|
|
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.Truco = void 0;
|
|
31
|
+
function Truco() {
|
|
32
|
+
function trucoAnswerGeneratorSequence() {
|
|
33
|
+
var i, player;
|
|
34
|
+
return __generator(this, function (_a) {
|
|
35
|
+
switch (_a.label) {
|
|
36
|
+
case 0:
|
|
37
|
+
i = 0;
|
|
38
|
+
_a.label = 1;
|
|
39
|
+
case 1:
|
|
40
|
+
if (!(i < truco.players.length && truco.answer === null)) return [3 /*break*/, 3];
|
|
41
|
+
player = truco.players[truco.turn];
|
|
42
|
+
truco.setCurrentPlayer(player);
|
|
43
|
+
if (player.disabled) {
|
|
44
|
+
truco.setCurrentPlayer(null);
|
|
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*/];
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
var truco = {
|
|
65
|
+
turn: 0,
|
|
66
|
+
state: 1,
|
|
67
|
+
teamIdx: null,
|
|
68
|
+
answer: null,
|
|
69
|
+
currentPlayer: null,
|
|
70
|
+
generator: trucoAnswerGeneratorSequence(),
|
|
71
|
+
players: [],
|
|
72
|
+
sayTruco: function (teamIdx, players) {
|
|
73
|
+
truco.teamIdx = teamIdx;
|
|
74
|
+
truco.answer = null;
|
|
75
|
+
truco.players = players;
|
|
76
|
+
truco.generator = trucoAnswerGeneratorSequence();
|
|
77
|
+
return truco;
|
|
78
|
+
},
|
|
79
|
+
setPlayers: function (players) {
|
|
80
|
+
truco.players = players;
|
|
81
|
+
},
|
|
82
|
+
setAnswer: function (answer) {
|
|
83
|
+
if (answer) {
|
|
84
|
+
truco.state++;
|
|
85
|
+
}
|
|
86
|
+
if (answer !== null) {
|
|
87
|
+
truco.teamIdx = null;
|
|
88
|
+
}
|
|
89
|
+
truco.answer = answer;
|
|
90
|
+
return truco;
|
|
91
|
+
},
|
|
92
|
+
setTeam: function (idx) {
|
|
93
|
+
truco.teamIdx = idx;
|
|
94
|
+
return truco.teamIdx;
|
|
95
|
+
},
|
|
96
|
+
setTurn: function (turn) {
|
|
97
|
+
truco.turn = turn;
|
|
98
|
+
return truco.turn;
|
|
99
|
+
},
|
|
100
|
+
setCurrentPlayer: function (player) {
|
|
101
|
+
truco.currentPlayer = player;
|
|
102
|
+
return truco.currentPlayer;
|
|
103
|
+
},
|
|
104
|
+
getNextPlayer: function () {
|
|
105
|
+
return truco.generator.next();
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
return truco;
|
|
109
|
+
}
|
|
110
|
+
exports.Truco = Truco;
|
package/build/lib/constants.d.ts
CHANGED
|
@@ -42,4 +42,10 @@ export declare const CARDS: {
|
|
|
42
42
|
"4c": number;
|
|
43
43
|
};
|
|
44
44
|
export declare const COLORS: string[];
|
|
45
|
+
export declare const TEAM_SIZE_VALUES: number[];
|
|
46
|
+
export declare enum GAME_ERROR {
|
|
47
|
+
UNEXPECTED_TEAM_SIZE = "UNEXPECTED_TEAM_SIZE",
|
|
48
|
+
TEAM_NOT_READY = "TEAM_NOT_READY",
|
|
49
|
+
TEAM_IS_FULL = "TEAM_IS_FULL"
|
|
50
|
+
}
|
|
45
51
|
export declare const EnvidoCalculator: IEnvidoCalculator;
|
package/build/lib/constants.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var _a;
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.EnvidoCalculator = exports.COLORS = exports.CARDS = void 0;
|
|
4
|
+
exports.EnvidoCalculator = exports.GAME_ERROR = exports.TEAM_SIZE_VALUES = exports.COLORS = exports.CARDS = void 0;
|
|
5
5
|
var types_1 = require("./types");
|
|
6
6
|
var utils_1 = require("./utils");
|
|
7
7
|
exports.CARDS = {
|
|
@@ -56,6 +56,13 @@ exports.COLORS = [
|
|
|
56
56
|
"#f44336",
|
|
57
57
|
"#c2185b",
|
|
58
58
|
];
|
|
59
|
+
exports.TEAM_SIZE_VALUES = [1, 2, 3];
|
|
60
|
+
var GAME_ERROR;
|
|
61
|
+
(function (GAME_ERROR) {
|
|
62
|
+
GAME_ERROR["UNEXPECTED_TEAM_SIZE"] = "UNEXPECTED_TEAM_SIZE";
|
|
63
|
+
GAME_ERROR["TEAM_NOT_READY"] = "TEAM_NOT_READY";
|
|
64
|
+
GAME_ERROR["TEAM_IS_FULL"] = "TEAM_IS_FULL";
|
|
65
|
+
})(GAME_ERROR = exports.GAME_ERROR || (exports.GAME_ERROR = {}));
|
|
59
66
|
exports.EnvidoCalculator = (_a = {},
|
|
60
67
|
_a[types_1.EEnvidoCommand.ENVIDO] = function () { return ({
|
|
61
68
|
accept: 2,
|
package/build/lib/index.d.ts
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
|
-
import { IPlayInstance, ITeam } from "./types";
|
|
1
|
+
import { IPlayInstance, ITeam, ITrucoshi } from "./types";
|
|
2
2
|
export type IWinnerCallback = (winner: ITeam, teams: [ITeam, ITeam]) => Promise<void>;
|
|
3
|
-
export type ITurnCallback = (
|
|
3
|
+
export type ITurnCallback = (play: IPlayInstance) => Promise<void>;
|
|
4
|
+
export type ITrucoCallback = (play: IPlayInstance) => Promise<void>;
|
|
4
5
|
export interface IGameLoop {
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
_onTruco: ITrucoCallback;
|
|
7
|
+
_onTurn: ITurnCallback;
|
|
8
|
+
_onWinner: IWinnerCallback;
|
|
7
9
|
onTurn: (callback: ITurnCallback) => IGameLoop;
|
|
8
10
|
onWinner: (callback: IWinnerCallback) => IGameLoop;
|
|
9
|
-
|
|
11
|
+
onTruco: (callback: ITrucoCallback) => IGameLoop;
|
|
12
|
+
begin: () => void;
|
|
10
13
|
}
|
|
11
|
-
export declare function Trucoshi(
|
|
14
|
+
export declare function Trucoshi(teamSize?: 1 | 2 | 3): {
|
|
15
|
+
addPlayer: (id: string, teamIdx?: 0 | 1 | undefined) => import("./types").IPlayer;
|
|
16
|
+
removePlayer: (id: string) => ITrucoshi;
|
|
17
|
+
startMatch: (matchPoint?: 9 | 12 | 15 | undefined) => IGameLoop;
|
|
18
|
+
};
|