trucoshi 1.0.0

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.
@@ -0,0 +1,3 @@
1
+ {
2
+ "tabWidth": 2,
3
+ }
@@ -0,0 +1,43 @@
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[];
@@ -0,0 +1,16 @@
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"];
@@ -0,0 +1,10 @@
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
+ };
@@ -0,0 +1,363 @@
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;
@@ -0,0 +1,101 @@
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
+ }
@@ -0,0 +1,14 @@
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 = {}));
@@ -0,0 +1,5 @@
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;
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.checkMatchWinner = exports.checkHandWinner = exports.shuffleArray = exports.getCardValue = void 0;
4
+ var constants_1 = require("./constants");
5
+ function getCardValue(card) {
6
+ return constants_1.CARDS[card] || -1;
7
+ }
8
+ exports.getCardValue = getCardValue;
9
+ function shuffleArray(array) {
10
+ var _a;
11
+ var currentIndex = array.length, randomIndex;
12
+ while (currentIndex != 0) {
13
+ randomIndex = Math.floor(Math.random() * currentIndex);
14
+ currentIndex--;
15
+ _a = [
16
+ array[randomIndex], array[currentIndex]
17
+ ], array[currentIndex] = _a[0], array[randomIndex] = _a[1];
18
+ }
19
+ return array;
20
+ }
21
+ exports.shuffleArray = shuffleArray;
22
+ function checkHandWinner(rounds, forehandTeamIdx) {
23
+ var _a, _b;
24
+ var roundsWon = {
25
+ 0: 0,
26
+ 1: 0,
27
+ 2: 0 // tied rounds
28
+ };
29
+ for (var i = 0; i < rounds.length; i++) {
30
+ var round = rounds[i];
31
+ if (round.tie) {
32
+ roundsWon[0] += 1;
33
+ roundsWon[1] += 1;
34
+ roundsWon[2] = (roundsWon[2] || 0) + 1;
35
+ continue;
36
+ }
37
+ if (((_a = round.winner) === null || _a === void 0 ? void 0 : _a.teamIdx) === 0) {
38
+ roundsWon[0] += 1;
39
+ }
40
+ if (((_b = round.winner) === null || _b === void 0 ? void 0 : _b.teamIdx) === 1) {
41
+ roundsWon[1] += 1;
42
+ }
43
+ }
44
+ var ties = roundsWon[2] || 0;
45
+ if ((roundsWon[0] > 2 && roundsWon[1] > 2) || (rounds.length > 2 && ties > 0)) {
46
+ return forehandTeamIdx;
47
+ }
48
+ if (roundsWon[0] >= 2 && roundsWon[1] < 2) {
49
+ return 0;
50
+ }
51
+ if (roundsWon[1] >= 2 && roundsWon[0] < 2) {
52
+ return 1;
53
+ }
54
+ return null;
55
+ }
56
+ exports.checkHandWinner = checkHandWinner;
57
+ function checkMatchWinner(teams, matchPoint) {
58
+ if (teams[0].points >= matchPoint) {
59
+ return teams[0];
60
+ }
61
+ if (teams[1].points >= matchPoint) {
62
+ return teams[1];
63
+ }
64
+ return null;
65
+ }
66
+ exports.checkMatchWinner = checkMatchWinner;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var http_1 = require("http");
4
+ var socket_io_1 = require("socket.io");
5
+ var PORT = 4001;
6
+ var httpServer = (0, http_1.createServer)();
7
+ var io = new socket_io_1.Server(httpServer, {
8
+ cors: {
9
+ origin: "http://localhost:3000",
10
+ methods: ["GET", "POST"]
11
+ }
12
+ });
13
+ io.on("connection", function (socket) {
14
+ socket.on('ping', function (msg) {
15
+ io.emit('pong', msg);
16
+ });
17
+ });
18
+ httpServer.listen(PORT);
19
+ console.log('Listening on port', PORT);
File without changes
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1 @@
1
+ export {};