trucoshi 1.0.0 → 2.0.2
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/LICENSE +674 -0
- package/README.md +64 -0
- package/dist/lib/constants.d.ts +89 -0
- package/dist/lib/constants.js +89 -0
- package/dist/server/constants.d.ts +3 -0
- package/dist/server/constants.js +3 -0
- package/dist/types.d.ts +333 -0
- package/dist/types.js +113 -0
- package/package.json +71 -23
- package/.prettierrc.json +0 -3
- package/build/lib/constants.d.ts +0 -43
- package/build/lib/constants.js +0 -16
- package/build/lib/trucoshi.d.ts +0 -10
- package/build/lib/trucoshi.js +0 -363
- package/build/lib/types.d.ts +0 -101
- package/build/lib/types.js +0 -14
- package/build/lib/utils.d.ts +0 -5
- package/build/lib/utils.js +0 -66
- package/build/server/index.d.ts +0 -1
- package/build/server/index.js +0 -19
- package/build/server/types.d.ts +0 -0
- package/build/server/types.js +0 -1
- package/build/test/autoplay.d.ts +0 -1
- package/build/test/autoplay.js +0 -73
- package/build/test/legacy.d.ts +0 -1
- package/build/test/legacy.js +0 -146
- package/build/test/play.d.ts +0 -1
- package/build/test/play.js +0 -148
- package/nodemon.json +0 -6
- package/src/lib/constants.ts +0 -14
- package/src/lib/trucoshi.ts +0 -342
- package/src/lib/types.ts +0 -110
- package/src/lib/utils.ts +0 -69
- package/src/server/index.ts +0 -22
- package/src/server/types.ts +0 -0
- package/src/test/autoplay.ts +0 -41
- package/src/test/legacy.ts +0 -68
- package/src/test/play.ts +0 -70
- package/tsconfig.json +0 -18
package/package.json
CHANGED
|
@@ -1,23 +1,71 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "trucoshi",
|
|
3
|
-
"version": "
|
|
4
|
-
"main": "
|
|
5
|
-
"license": "
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
"
|
|
22
|
-
|
|
23
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "trucoshi",
|
|
3
|
+
"version": "2.0.2",
|
|
4
|
+
"main": "dist/types.js",
|
|
5
|
+
"license": "GPL-3.0",
|
|
6
|
+
"paths": {
|
|
7
|
+
"trucoshi": [
|
|
8
|
+
"./"
|
|
9
|
+
]
|
|
10
|
+
},
|
|
11
|
+
"scripts": {
|
|
12
|
+
"start": "nodemon",
|
|
13
|
+
"start:e2e": "dotenv -e .env.e2e -- nodemon",
|
|
14
|
+
"profiler": "yarn build && node --prof ./bin/trucoshi-server",
|
|
15
|
+
"build": "yarn run rimraf ./build && yarn run tsc --project . && yarn build:dist",
|
|
16
|
+
"build:dist": "yarn run rimraf ./dist && yarn run tsc --project ./tsconfig.dist.json",
|
|
17
|
+
"prepublishOnly": "yarn test && yarn build:dist",
|
|
18
|
+
"test": "dotenv -e .env.e2e -- yarn db:e2e:push --force-reset && dotenv -e .env.e2e -- ts-mocha --exit ./test/**/*.ts -t 50000",
|
|
19
|
+
"cli:autoplay": "yarn run ts-node src/cli/autoplay",
|
|
20
|
+
"cli:play": "yarn run ts-node src/cli/play",
|
|
21
|
+
"db:push": "prisma db push",
|
|
22
|
+
"db:studio": "prisma studio",
|
|
23
|
+
"db:migrate": "prisma migrate dev",
|
|
24
|
+
"db:e2e:push": "dotenv -e .env.e2e -- prisma db push",
|
|
25
|
+
"db:e2e:studio": "dotenv -e .env.e2e -- prisma studio",
|
|
26
|
+
"db:e2e:migrate": "dotenv -e .env.e2e -- prisma migrate dev"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@types/chai": "^4.3.4",
|
|
30
|
+
"@types/expect": "^24.3.0",
|
|
31
|
+
"@types/mocha": "^10.0.1",
|
|
32
|
+
"@types/node": "^18.11.18",
|
|
33
|
+
"chai": "^4.3.7",
|
|
34
|
+
"mocha": "^10.2.0",
|
|
35
|
+
"nodemon": "^2.0.20",
|
|
36
|
+
"prisma": "^4.14.1",
|
|
37
|
+
"socket.io-client": "^4.5.4",
|
|
38
|
+
"ts-mocha": "^10.0.0"
|
|
39
|
+
},
|
|
40
|
+
"files": [
|
|
41
|
+
"node_modules/.prisma/client/*",
|
|
42
|
+
"dist/lib/constants.js",
|
|
43
|
+
"dist/lib/constants.d.ts",
|
|
44
|
+
"dist/types.js",
|
|
45
|
+
"dist/types.d.ts",
|
|
46
|
+
"dist/server/constants.js",
|
|
47
|
+
"dist/server/constants.d.ts"
|
|
48
|
+
],
|
|
49
|
+
"dependencies": {
|
|
50
|
+
"@prisma/client": "^4.14.1",
|
|
51
|
+
"@socket.io/redis-adapter": "^8.2.1",
|
|
52
|
+
"@types/jsonwebtoken": "^9.0.5",
|
|
53
|
+
"@types/pino": "^7.0.5",
|
|
54
|
+
"@types/redis": "^4.0.11",
|
|
55
|
+
"axios": "^1.6.3",
|
|
56
|
+
"axios-cookiejar-support": "^5.0.0",
|
|
57
|
+
"dotenv": "^16.0.3",
|
|
58
|
+
"dotenv-cli": "^7.3.0",
|
|
59
|
+
"form-data": "^4.0.0",
|
|
60
|
+
"jsonwebtoken": "^9.0.2",
|
|
61
|
+
"lightning-accounts": "2.0.1",
|
|
62
|
+
"path-scurry": "^1.9.2",
|
|
63
|
+
"pino": "^8.11.0",
|
|
64
|
+
"pino-pretty": "^10.0.0",
|
|
65
|
+
"rimraf": "^4.1.1",
|
|
66
|
+
"socket.io": "^4.5.4",
|
|
67
|
+
"ts-node": "^10.9.1",
|
|
68
|
+
"tsc": "^2.0.4",
|
|
69
|
+
"typescript": "^5.3.3"
|
|
70
|
+
}
|
|
71
|
+
}
|
package/.prettierrc.json
DELETED
package/build/lib/constants.d.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
export declare const CARDS: {
|
|
2
|
-
'1e': number;
|
|
3
|
-
'1b': number;
|
|
4
|
-
'7e': number;
|
|
5
|
-
'7o': number;
|
|
6
|
-
'3e': number;
|
|
7
|
-
'3o': number;
|
|
8
|
-
'3b': number;
|
|
9
|
-
'3c': number;
|
|
10
|
-
'2e': number;
|
|
11
|
-
'2o': number;
|
|
12
|
-
'2b': number;
|
|
13
|
-
'2c': number;
|
|
14
|
-
'1o': number;
|
|
15
|
-
'1c': number;
|
|
16
|
-
re: number;
|
|
17
|
-
ro: number;
|
|
18
|
-
rb: number;
|
|
19
|
-
rc: number;
|
|
20
|
-
ce: number;
|
|
21
|
-
co: number;
|
|
22
|
-
cb: number;
|
|
23
|
-
cc: number;
|
|
24
|
-
pe: number;
|
|
25
|
-
po: number;
|
|
26
|
-
pb: number;
|
|
27
|
-
pc: number;
|
|
28
|
-
'7b': number;
|
|
29
|
-
'7c': number;
|
|
30
|
-
'6e': number;
|
|
31
|
-
'6o': number;
|
|
32
|
-
'6b': number;
|
|
33
|
-
'6c': number;
|
|
34
|
-
'5e': number;
|
|
35
|
-
'5o': number;
|
|
36
|
-
'5b': number;
|
|
37
|
-
'5c': number;
|
|
38
|
-
'4e': number;
|
|
39
|
-
'4o': number;
|
|
40
|
-
'4b': number;
|
|
41
|
-
'4c': number;
|
|
42
|
-
};
|
|
43
|
-
export declare const COLORS: string[];
|
package/build/lib/constants.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.COLORS = exports.CARDS = void 0;
|
|
4
|
-
exports.CARDS = {
|
|
5
|
-
'1e': 14, '1b': 13, '7e': 12, '7o': 11,
|
|
6
|
-
'3e': 10, '3o': 10, '3b': 10, '3c': 10,
|
|
7
|
-
'2e': 9, '2o': 9, '2b': 8, '2c': 8,
|
|
8
|
-
'1o': 7, '1c': 7, 're': 6, 'ro': 6,
|
|
9
|
-
'rb': 6, 'rc': 6, 'ce': 5, 'co': 5,
|
|
10
|
-
'cb': 5, 'cc': 5, 'pe': 4, 'po': 4,
|
|
11
|
-
'pb': 4, 'pc': 4, '7b': 3, '7c': 3,
|
|
12
|
-
'6e': 2, '6o': 2, '6b': 2, '6c': 2,
|
|
13
|
-
'5e': 1, '5o': 1, '5b': 1, '5c': 1,
|
|
14
|
-
'4e': 0, '4o': 0, '4b': 0, '4c': 0
|
|
15
|
-
};
|
|
16
|
-
exports.COLORS = ["#9b111", "#17c6c6", "#8c1d1d", "#9f9b9b", "#a5a5a5", "#f5a623", "#f44336", "#c2185b"];
|
package/build/lib/trucoshi.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { IMatch, IPlayer, ITeam } from "./types";
|
|
2
|
-
export declare function Match(teams?: Array<ITeam>, matchPoint?: number): IMatch;
|
|
3
|
-
export declare function Player(id: string, teamIdx: number): IPlayer;
|
|
4
|
-
export declare function Team(color: string, players: Array<IPlayer>): {
|
|
5
|
-
_players: Map<string, IPlayer>;
|
|
6
|
-
readonly players: IPlayer[];
|
|
7
|
-
color: string;
|
|
8
|
-
points: number;
|
|
9
|
-
addPoints(points: number): number;
|
|
10
|
-
};
|
package/build/lib/trucoshi.js
DELETED
|
@@ -1,363 +0,0 @@
|
|
|
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.Team = exports.Player = exports.Match = void 0;
|
|
31
|
-
var constants_1 = require("./constants");
|
|
32
|
-
var utils_1 = require("./utils");
|
|
33
|
-
function Deck() {
|
|
34
|
-
var _deck = {
|
|
35
|
-
cards: Object.keys(constants_1.CARDS),
|
|
36
|
-
usedCards: [],
|
|
37
|
-
takeCard: function () {
|
|
38
|
-
var card = _deck.cards.shift();
|
|
39
|
-
_deck.usedCards.push(card);
|
|
40
|
-
return card;
|
|
41
|
-
},
|
|
42
|
-
shuffle: function () {
|
|
43
|
-
_deck.cards = _deck.cards.concat(_deck.usedCards);
|
|
44
|
-
_deck.usedCards = [];
|
|
45
|
-
_deck.cards = (0, utils_1.shuffleArray)(_deck.cards);
|
|
46
|
-
if (_deck.cards.length !== 40) {
|
|
47
|
-
throw new Error("This is not good");
|
|
48
|
-
}
|
|
49
|
-
return _deck;
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
return _deck;
|
|
53
|
-
}
|
|
54
|
-
function Table(teams, size) {
|
|
55
|
-
var _table = {
|
|
56
|
-
players: [],
|
|
57
|
-
cards: [],
|
|
58
|
-
forehandIdx: 0,
|
|
59
|
-
nextTurn: function () {
|
|
60
|
-
if (_table.forehandIdx < (size * 2) - 1) {
|
|
61
|
-
_table.forehandIdx++;
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
_table.forehandIdx = 0;
|
|
65
|
-
}
|
|
66
|
-
return _table.player();
|
|
67
|
-
},
|
|
68
|
-
getPlayerPosition: function (id) {
|
|
69
|
-
return _table.players.findIndex(function (p) { return p.id === id; });
|
|
70
|
-
},
|
|
71
|
-
player: function (idx) {
|
|
72
|
-
if (idx !== undefined) {
|
|
73
|
-
return _table.players[idx];
|
|
74
|
-
}
|
|
75
|
-
return _table.players[_table.forehandIdx];
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
if (teams[0].players.length != size || teams[1].players.length != size) {
|
|
79
|
-
throw new Error("Unexpected team size");
|
|
80
|
-
}
|
|
81
|
-
for (var i = 0; i < size; i++) {
|
|
82
|
-
_table.players.push(teams[0].players[i]);
|
|
83
|
-
_table.players.push(teams[1].players[i]);
|
|
84
|
-
}
|
|
85
|
-
return _table;
|
|
86
|
-
}
|
|
87
|
-
function Round() {
|
|
88
|
-
var _round = {
|
|
89
|
-
highest: -1,
|
|
90
|
-
winner: null,
|
|
91
|
-
cards: [],
|
|
92
|
-
tie: false,
|
|
93
|
-
play: function (_a) {
|
|
94
|
-
var card = _a.card, player = _a.player;
|
|
95
|
-
var value = (0, utils_1.getCardValue)(card);
|
|
96
|
-
if (_round.highest > -1 && value === _round.highest) {
|
|
97
|
-
_round.tie = true;
|
|
98
|
-
}
|
|
99
|
-
if (value > _round.highest) {
|
|
100
|
-
_round.tie = false;
|
|
101
|
-
_round.highest = value;
|
|
102
|
-
_round.winner = player;
|
|
103
|
-
}
|
|
104
|
-
_round.cards.push({ card: card, player: player });
|
|
105
|
-
return card;
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
return _round;
|
|
109
|
-
}
|
|
110
|
-
function Match(teams, matchPoint) {
|
|
111
|
-
if (teams === void 0) { teams = []; }
|
|
112
|
-
if (matchPoint === void 0) { matchPoint = 9; }
|
|
113
|
-
var deck = Deck().shuffle();
|
|
114
|
-
var size = teams[0].players.length;
|
|
115
|
-
if (size !== teams[1].players.length) {
|
|
116
|
-
throw new Error("Team size mismatch");
|
|
117
|
-
}
|
|
118
|
-
function handsGeneratorSequence() {
|
|
119
|
-
var hand, value, hasWinner;
|
|
120
|
-
return __generator(this, function (_a) {
|
|
121
|
-
switch (_a.label) {
|
|
122
|
-
case 0:
|
|
123
|
-
if (!!_match.winner) return [3 /*break*/, 4];
|
|
124
|
-
deck.shuffle();
|
|
125
|
-
hand = _match.setCurrentHand(Hand(_match, deck, _match.hands.length + 1));
|
|
126
|
-
_match.pushHand(hand);
|
|
127
|
-
_a.label = 1;
|
|
128
|
-
case 1:
|
|
129
|
-
if (!!hand.finished) return [3 /*break*/, 3];
|
|
130
|
-
value = hand.getNextPlayer().value;
|
|
131
|
-
if (value && value.finished) {
|
|
132
|
-
return [3 /*break*/, 1];
|
|
133
|
-
}
|
|
134
|
-
_match.setCurrentHand(value);
|
|
135
|
-
return [4 /*yield*/, _match];
|
|
136
|
-
case 2:
|
|
137
|
-
_a.sent();
|
|
138
|
-
return [3 /*break*/, 1];
|
|
139
|
-
case 3:
|
|
140
|
-
_match.addPoints(hand.points);
|
|
141
|
-
_match.setCurrentHand(null);
|
|
142
|
-
hasWinner = (0, utils_1.checkMatchWinner)(teams, matchPoint);
|
|
143
|
-
if (hasWinner !== null) {
|
|
144
|
-
_match.setWinner(hasWinner);
|
|
145
|
-
_match.setCurrentHand(null);
|
|
146
|
-
}
|
|
147
|
-
_match.table.nextTurn();
|
|
148
|
-
return [3 /*break*/, 0];
|
|
149
|
-
case 4: return [4 /*yield*/, _match];
|
|
150
|
-
case 5:
|
|
151
|
-
_a.sent();
|
|
152
|
-
return [2 /*return*/];
|
|
153
|
-
}
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
var handsGenerator = handsGeneratorSequence();
|
|
157
|
-
var _match = {
|
|
158
|
-
winner: null,
|
|
159
|
-
teams: teams,
|
|
160
|
-
hands: [],
|
|
161
|
-
table: Table(teams, size),
|
|
162
|
-
currentHand: null,
|
|
163
|
-
play: function () {
|
|
164
|
-
_match.getNextTurn();
|
|
165
|
-
if (!_match.currentHand) {
|
|
166
|
-
return;
|
|
167
|
-
}
|
|
168
|
-
return _match.currentHand.play();
|
|
169
|
-
},
|
|
170
|
-
addPoints: function (points) {
|
|
171
|
-
_match.teams[0].addPoints(points[0]);
|
|
172
|
-
_match.teams[1].addPoints(points[1]);
|
|
173
|
-
},
|
|
174
|
-
pushHand: function (hand) {
|
|
175
|
-
_match.hands.push(hand);
|
|
176
|
-
},
|
|
177
|
-
setCurrentHand: function (hand) {
|
|
178
|
-
_match.currentHand = hand;
|
|
179
|
-
return _match.currentHand;
|
|
180
|
-
},
|
|
181
|
-
setWinner: function (winner) {
|
|
182
|
-
_match.winner = winner;
|
|
183
|
-
},
|
|
184
|
-
getNextTurn: function () {
|
|
185
|
-
return handsGenerator.next();
|
|
186
|
-
}
|
|
187
|
-
};
|
|
188
|
-
return _match;
|
|
189
|
-
}
|
|
190
|
-
exports.Match = Match;
|
|
191
|
-
function PlayInstance(hand) {
|
|
192
|
-
var _instance = {
|
|
193
|
-
handIdx: hand.idx,
|
|
194
|
-
roundIdx: hand.rounds.length,
|
|
195
|
-
player: hand.currentPlayer,
|
|
196
|
-
commands: [],
|
|
197
|
-
rounds: hand.rounds,
|
|
198
|
-
use: function (idx) {
|
|
199
|
-
var player = hand.currentPlayer;
|
|
200
|
-
var round = hand.currentRound;
|
|
201
|
-
if (!player || !round) {
|
|
202
|
-
return null;
|
|
203
|
-
}
|
|
204
|
-
var card = player.useCard(idx);
|
|
205
|
-
if (card) {
|
|
206
|
-
return round.play({ player: player, card: card });
|
|
207
|
-
}
|
|
208
|
-
return null;
|
|
209
|
-
},
|
|
210
|
-
say: function (command) {
|
|
211
|
-
if (!hand.currentPlayer) {
|
|
212
|
-
return null;
|
|
213
|
-
}
|
|
214
|
-
return hand;
|
|
215
|
-
}
|
|
216
|
-
};
|
|
217
|
-
return _instance;
|
|
218
|
-
}
|
|
219
|
-
function Hand(match, deck, idx) {
|
|
220
|
-
var truco = 1;
|
|
221
|
-
match.teams.forEach(function (team) {
|
|
222
|
-
team.players.forEach(function (player) {
|
|
223
|
-
var playerHand = [deck.takeCard(), deck.takeCard(), deck.takeCard()];
|
|
224
|
-
player.setHand(playerHand);
|
|
225
|
-
// player.setHand(["5c", "4c", "6c"])
|
|
226
|
-
});
|
|
227
|
-
});
|
|
228
|
-
function roundsGeneratorSequence() {
|
|
229
|
-
var currentRoundIdx, forehandTeamIdx, i, round, previousRound, newTurn, teamIdx;
|
|
230
|
-
return __generator(this, function (_a) {
|
|
231
|
-
switch (_a.label) {
|
|
232
|
-
case 0:
|
|
233
|
-
currentRoundIdx = 0;
|
|
234
|
-
forehandTeamIdx = match.table.player(_hand.turn).teamIdx;
|
|
235
|
-
_a.label = 1;
|
|
236
|
-
case 1:
|
|
237
|
-
if (!(currentRoundIdx < 3 && !_hand.finished)) return [3 /*break*/, 5];
|
|
238
|
-
i = 0;
|
|
239
|
-
round = Round();
|
|
240
|
-
_hand.setCurrentRound(round);
|
|
241
|
-
_hand.pushRound(round);
|
|
242
|
-
previousRound = _hand.rounds[currentRoundIdx - 1];
|
|
243
|
-
// Put previous round winner as forehand
|
|
244
|
-
if (previousRound && previousRound.winner && !previousRound.tie) {
|
|
245
|
-
newTurn = match.table.getPlayerPosition(previousRound.winner.id);
|
|
246
|
-
if (newTurn !== -1) {
|
|
247
|
-
_hand.setTurn(newTurn);
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
_a.label = 2;
|
|
251
|
-
case 2:
|
|
252
|
-
if (!(i < match.table.players.length)) return [3 /*break*/, 4];
|
|
253
|
-
_hand.setCurrentPlayer(match.table.player(_hand.turn));
|
|
254
|
-
if (_hand.turn >= match.table.players.length - 1) {
|
|
255
|
-
_hand.setTurn(0);
|
|
256
|
-
}
|
|
257
|
-
else {
|
|
258
|
-
_hand.setTurn(_hand.turn + 1);
|
|
259
|
-
}
|
|
260
|
-
i++;
|
|
261
|
-
return [4 /*yield*/, _hand];
|
|
262
|
-
case 3:
|
|
263
|
-
_a.sent();
|
|
264
|
-
return [3 /*break*/, 2];
|
|
265
|
-
case 4:
|
|
266
|
-
teamIdx = (0, utils_1.checkHandWinner)(_hand.rounds, forehandTeamIdx);
|
|
267
|
-
if (teamIdx !== null) {
|
|
268
|
-
_hand.addPoints(teamIdx, truco);
|
|
269
|
-
_hand.setFinished(true);
|
|
270
|
-
}
|
|
271
|
-
currentRoundIdx++;
|
|
272
|
-
return [3 /*break*/, 1];
|
|
273
|
-
case 5: return [4 /*yield*/, _hand];
|
|
274
|
-
case 6:
|
|
275
|
-
_a.sent();
|
|
276
|
-
return [2 /*return*/];
|
|
277
|
-
}
|
|
278
|
-
});
|
|
279
|
-
}
|
|
280
|
-
var roundsGenerator = roundsGeneratorSequence();
|
|
281
|
-
var _hand = {
|
|
282
|
-
idx: idx,
|
|
283
|
-
turn: Number(match.table.forehandIdx),
|
|
284
|
-
rounds: [],
|
|
285
|
-
finished: false,
|
|
286
|
-
points: {
|
|
287
|
-
0: 0,
|
|
288
|
-
1: 0
|
|
289
|
-
},
|
|
290
|
-
currentRound: null,
|
|
291
|
-
currentPlayer: null,
|
|
292
|
-
play: function () {
|
|
293
|
-
return PlayInstance(_hand);
|
|
294
|
-
},
|
|
295
|
-
pushRound: function (round) {
|
|
296
|
-
_hand.rounds.push(round);
|
|
297
|
-
return round;
|
|
298
|
-
},
|
|
299
|
-
setTurn: function (turn) {
|
|
300
|
-
_hand.turn = turn;
|
|
301
|
-
return match.table.player(_hand.turn);
|
|
302
|
-
},
|
|
303
|
-
addPoints: function (team, points) {
|
|
304
|
-
_hand.points[team] = _hand.points[team] + points;
|
|
305
|
-
},
|
|
306
|
-
setCurrentRound: function (round) {
|
|
307
|
-
_hand.currentRound = round;
|
|
308
|
-
return _hand.currentRound;
|
|
309
|
-
},
|
|
310
|
-
setCurrentPlayer: function (player) {
|
|
311
|
-
_hand.currentPlayer = player;
|
|
312
|
-
return _hand.currentPlayer;
|
|
313
|
-
},
|
|
314
|
-
setFinished: function (finshed) {
|
|
315
|
-
_hand.finished = finshed;
|
|
316
|
-
return _hand.finished;
|
|
317
|
-
},
|
|
318
|
-
getNextPlayer: function () {
|
|
319
|
-
return roundsGenerator.next();
|
|
320
|
-
},
|
|
321
|
-
};
|
|
322
|
-
return _hand;
|
|
323
|
-
}
|
|
324
|
-
function Player(id, teamIdx) {
|
|
325
|
-
var _player = {
|
|
326
|
-
id: id,
|
|
327
|
-
teamIdx: teamIdx,
|
|
328
|
-
hand: [],
|
|
329
|
-
usedHand: [],
|
|
330
|
-
setHand: function (hand) {
|
|
331
|
-
_player.hand = hand;
|
|
332
|
-
_player.usedHand = [];
|
|
333
|
-
return hand;
|
|
334
|
-
},
|
|
335
|
-
useCard: function (idx) {
|
|
336
|
-
if (_player.hand[idx]) {
|
|
337
|
-
var card = _player.hand.splice(idx, 1)[0];
|
|
338
|
-
_player.usedHand.push(card);
|
|
339
|
-
return card;
|
|
340
|
-
}
|
|
341
|
-
return null;
|
|
342
|
-
}
|
|
343
|
-
};
|
|
344
|
-
return _player;
|
|
345
|
-
}
|
|
346
|
-
exports.Player = Player;
|
|
347
|
-
function Team(color, players) {
|
|
348
|
-
var _team = {
|
|
349
|
-
_players: new Map(),
|
|
350
|
-
get players() {
|
|
351
|
-
return Array.from(_team._players.values());
|
|
352
|
-
},
|
|
353
|
-
color: color,
|
|
354
|
-
points: 0,
|
|
355
|
-
addPoints: function (points) {
|
|
356
|
-
_team.points += points;
|
|
357
|
-
return _team.points;
|
|
358
|
-
},
|
|
359
|
-
};
|
|
360
|
-
players.forEach(function (player) { return _team._players.set(player.id, player); });
|
|
361
|
-
return _team;
|
|
362
|
-
}
|
|
363
|
-
exports.Team = Team;
|
package/build/lib/types.d.ts
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import { CARDS } from "./constants";
|
|
2
|
-
export type ICard = keyof typeof CARDS;
|
|
3
|
-
export interface IDeck {
|
|
4
|
-
cards: Array<ICard>;
|
|
5
|
-
usedCards: Array<ICard>;
|
|
6
|
-
takeCard(): ICard;
|
|
7
|
-
shuffle(): IDeck;
|
|
8
|
-
}
|
|
9
|
-
export interface IPlayedCard {
|
|
10
|
-
player: IPlayer;
|
|
11
|
-
card: ICard;
|
|
12
|
-
}
|
|
13
|
-
export interface IPlayer {
|
|
14
|
-
teamIdx: number;
|
|
15
|
-
id: string;
|
|
16
|
-
hand: Array<ICard>;
|
|
17
|
-
usedHand: Array<ICard>;
|
|
18
|
-
setHand(hand: Array<ICard>): Array<ICard>;
|
|
19
|
-
useCard(idx: number): ICard | null;
|
|
20
|
-
}
|
|
21
|
-
export interface ITeam {
|
|
22
|
-
color: string;
|
|
23
|
-
_players: Map<string, IPlayer>;
|
|
24
|
-
players: Array<IPlayer>;
|
|
25
|
-
points: number;
|
|
26
|
-
addPoints(points: number): number;
|
|
27
|
-
}
|
|
28
|
-
export interface IMatch {
|
|
29
|
-
teams: [ITeam, ITeam];
|
|
30
|
-
hands: Array<IHand>;
|
|
31
|
-
winner: ITeam | null;
|
|
32
|
-
currentHand: IHand | null;
|
|
33
|
-
table: ITable;
|
|
34
|
-
play(): IPlayInstance | undefined;
|
|
35
|
-
addPoints(points: IPoints): void;
|
|
36
|
-
pushHand(hand: IHand): void;
|
|
37
|
-
setCurrentHand(hand: IHand | null): IHand | null;
|
|
38
|
-
setWinner(winner: ITeam): void;
|
|
39
|
-
getNextTurn(): IteratorResult<IMatch | null, IMatch | null | void>;
|
|
40
|
-
}
|
|
41
|
-
export type IPoints = {
|
|
42
|
-
0: number;
|
|
43
|
-
1: number;
|
|
44
|
-
2?: number;
|
|
45
|
-
};
|
|
46
|
-
export type IGetNextPlayerResult = {
|
|
47
|
-
currentPlayer?: IPlayer;
|
|
48
|
-
currentRound?: IRound;
|
|
49
|
-
points?: IPoints;
|
|
50
|
-
};
|
|
51
|
-
export declare enum EHandPlayCommand {
|
|
52
|
-
TRUCO = 0,
|
|
53
|
-
ENVIDO = 1,
|
|
54
|
-
ENVIDO_ENVIDO = 2,
|
|
55
|
-
REAL_ENVIDO = 3,
|
|
56
|
-
FALTA_ENVIDO = 4,
|
|
57
|
-
MAZO = 5,
|
|
58
|
-
FLOR = 6,
|
|
59
|
-
CONTRAFLOR = 7
|
|
60
|
-
}
|
|
61
|
-
export interface IPlayInstance {
|
|
62
|
-
handIdx: number;
|
|
63
|
-
roundIdx: number;
|
|
64
|
-
player: IPlayer | null;
|
|
65
|
-
commands: Array<EHandPlayCommand> | null;
|
|
66
|
-
rounds: Array<IRound> | null;
|
|
67
|
-
use(idx: number): ICard | null;
|
|
68
|
-
say(command: EHandPlayCommand): IHand | null;
|
|
69
|
-
}
|
|
70
|
-
export interface IHand {
|
|
71
|
-
idx: number;
|
|
72
|
-
turn: number;
|
|
73
|
-
finished: boolean;
|
|
74
|
-
points: IPoints;
|
|
75
|
-
rounds: Array<IRound>;
|
|
76
|
-
currentPlayer: IPlayer | null;
|
|
77
|
-
currentRound: IRound | null;
|
|
78
|
-
play(): IPlayInstance;
|
|
79
|
-
pushRound(round: IRound): IRound;
|
|
80
|
-
setTurn(turn: number): IPlayer;
|
|
81
|
-
addPoints(team: 0 | 1, points: number): void;
|
|
82
|
-
setCurrentRound(round: IRound | null): IRound | null;
|
|
83
|
-
setCurrentPlayer(player: IPlayer | null): IPlayer | null;
|
|
84
|
-
setFinished(finshed: boolean): boolean;
|
|
85
|
-
getNextPlayer(): IteratorResult<IHand, IHand | void>;
|
|
86
|
-
}
|
|
87
|
-
export interface ITable {
|
|
88
|
-
forehandIdx: number;
|
|
89
|
-
cards: Array<Array<IPlayedCard>>;
|
|
90
|
-
players: Array<IPlayer>;
|
|
91
|
-
nextTurn(): IPlayer;
|
|
92
|
-
player(idx?: number): IPlayer;
|
|
93
|
-
getPlayerPosition(id: string): number;
|
|
94
|
-
}
|
|
95
|
-
export interface IRound {
|
|
96
|
-
tie: boolean;
|
|
97
|
-
winner: IPlayer | null;
|
|
98
|
-
highest: number;
|
|
99
|
-
cards: Array<IPlayedCard>;
|
|
100
|
-
play(playedCard: IPlayedCard): ICard;
|
|
101
|
-
}
|
package/build/lib/types.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EHandPlayCommand = void 0;
|
|
4
|
-
var EHandPlayCommand;
|
|
5
|
-
(function (EHandPlayCommand) {
|
|
6
|
-
EHandPlayCommand[EHandPlayCommand["TRUCO"] = 0] = "TRUCO";
|
|
7
|
-
EHandPlayCommand[EHandPlayCommand["ENVIDO"] = 1] = "ENVIDO";
|
|
8
|
-
EHandPlayCommand[EHandPlayCommand["ENVIDO_ENVIDO"] = 2] = "ENVIDO_ENVIDO";
|
|
9
|
-
EHandPlayCommand[EHandPlayCommand["REAL_ENVIDO"] = 3] = "REAL_ENVIDO";
|
|
10
|
-
EHandPlayCommand[EHandPlayCommand["FALTA_ENVIDO"] = 4] = "FALTA_ENVIDO";
|
|
11
|
-
EHandPlayCommand[EHandPlayCommand["MAZO"] = 5] = "MAZO";
|
|
12
|
-
EHandPlayCommand[EHandPlayCommand["FLOR"] = 6] = "FLOR";
|
|
13
|
-
EHandPlayCommand[EHandPlayCommand["CONTRAFLOR"] = 7] = "CONTRAFLOR";
|
|
14
|
-
})(EHandPlayCommand = exports.EHandPlayCommand || (exports.EHandPlayCommand = {}));
|
package/build/lib/utils.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { ICard, IRound, ITeam } from "./types";
|
|
2
|
-
export declare function getCardValue(card: ICard): number;
|
|
3
|
-
export declare function shuffleArray<T = never>(array: Array<T>): T[];
|
|
4
|
-
export declare function checkHandWinner(rounds: Array<IRound>, forehandTeamIdx: 0 | 1): null | 0 | 1;
|
|
5
|
-
export declare function checkMatchWinner(teams: Array<ITeam>, matchPoint: number): ITeam | null;
|