trucoshi 0.1.7 → 0.2.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.
Files changed (39) hide show
  1. package/LICENSE +674 -674
  2. package/README.md +60 -37
  3. package/dist/index.d.ts +2 -0
  4. package/dist/index.js +18 -18
  5. package/dist/lib/classes/Deck.d.ts +16 -0
  6. package/dist/lib/classes/Deck.js +38 -0
  7. package/dist/lib/classes/GameLoop.d.ts +20 -0
  8. package/dist/lib/classes/GameLoop.js +61 -0
  9. package/dist/lib/classes/Hand.d.ts +38 -0
  10. package/dist/lib/classes/Hand.js +184 -0
  11. package/dist/lib/classes/Lobby.d.ts +27 -0
  12. package/dist/lib/classes/Lobby.js +112 -0
  13. package/dist/lib/classes/Match.d.ts +18 -0
  14. package/dist/lib/classes/Match.js +72 -0
  15. package/dist/lib/classes/Play.d.ts +21 -0
  16. package/dist/lib/classes/Play.js +39 -0
  17. package/dist/lib/classes/Player.d.ts +26 -0
  18. package/dist/lib/classes/Player.js +67 -0
  19. package/dist/lib/classes/Round.d.ts +17 -0
  20. package/dist/lib/classes/Round.js +33 -0
  21. package/dist/lib/classes/Table.d.ts +12 -0
  22. package/dist/lib/classes/Table.js +30 -0
  23. package/dist/lib/classes/Team.d.ts +19 -0
  24. package/dist/lib/classes/Team.js +48 -0
  25. package/dist/lib/classes/Truco.d.ts +18 -0
  26. package/dist/lib/classes/Truco.js +70 -0
  27. package/dist/lib/classes/index.d.ts +11 -0
  28. package/dist/lib/classes/index.js +27 -0
  29. package/dist/lib/constants.d.ts +45 -0
  30. package/dist/lib/constants.js +84 -0
  31. package/dist/lib/index.d.ts +2 -0
  32. package/dist/lib/index.js +18 -0
  33. package/dist/lib/types.d.ts +50 -0
  34. package/dist/lib/types.js +34 -0
  35. package/dist/lib/utils.d.ts +5 -0
  36. package/dist/lib/utils.js +58 -0
  37. package/dist/types.d.ts +133 -0
  38. package/dist/types.js +65 -0
  39. package/package.json +7 -3
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Match = void 0;
4
+ const Deck_1 = require("./Deck");
5
+ const Hand_1 = require("./Hand");
6
+ function Match(table, teams = [], matchPoint = 9) {
7
+ const deck = (0, Deck_1.Deck)().shuffle();
8
+ const size = teams[0].players.length;
9
+ if (size !== teams[1].players.length) {
10
+ throw new Error("Team size mismatch");
11
+ }
12
+ function* handsGeneratorSequence() {
13
+ while (!match.winner) {
14
+ deck.shuffle();
15
+ const hand = match.setCurrentHand((0, Hand_1.Hand)(match, deck, match.hands.length + 1));
16
+ match.pushHand(hand);
17
+ while (!hand.finished()) {
18
+ const { value } = hand.getNextPlayer();
19
+ if (value && value.finished()) {
20
+ continue;
21
+ }
22
+ match.setCurrentHand(value);
23
+ yield match;
24
+ }
25
+ match.setCurrentHand(null);
26
+ const teams = match.addPoints(hand.points);
27
+ const winner = teams.find((team) => team.points.winner);
28
+ if (winner) {
29
+ match.setWinner(winner);
30
+ match.setCurrentHand(null);
31
+ break;
32
+ }
33
+ match.table.nextTurn();
34
+ }
35
+ yield match;
36
+ }
37
+ const handsGenerator = handsGeneratorSequence();
38
+ const match = {
39
+ winner: null,
40
+ teams: teams,
41
+ hands: [],
42
+ table,
43
+ currentHand: null,
44
+ play() {
45
+ match.getNextTurn();
46
+ if (!match.currentHand) {
47
+ return null;
48
+ }
49
+ return match.currentHand.play();
50
+ },
51
+ addPoints(points) {
52
+ match.teams[0].addPoints(matchPoint, points[0]);
53
+ match.teams[1].addPoints(matchPoint, points[1]);
54
+ return match.teams;
55
+ },
56
+ pushHand(hand) {
57
+ match.hands.push(hand);
58
+ },
59
+ setCurrentHand(hand) {
60
+ match.currentHand = hand;
61
+ return match.currentHand;
62
+ },
63
+ setWinner(winner) {
64
+ match.winner = winner;
65
+ },
66
+ getNextTurn() {
67
+ return handsGenerator.next();
68
+ },
69
+ };
70
+ return match;
71
+ }
72
+ exports.Match = Match;
@@ -0,0 +1,21 @@
1
+ import { ECommand, EHandState, EnvidoState } from "../../types";
2
+ import { ICard } from "./Deck";
3
+ import { IHand } from "./Hand";
4
+ import { IPlayer } from "./Player";
5
+ import { IRound } from "./Round";
6
+ import { ITeam } from "./Team";
7
+ import { ITruco } from "./Truco";
8
+ export interface IPlayInstance {
9
+ teams: [ITeam, ITeam];
10
+ handIdx: number;
11
+ roundIdx: number;
12
+ state: EHandState;
13
+ truco: ITruco;
14
+ envido: EnvidoState;
15
+ player: IPlayer | null;
16
+ commands: Array<ECommand> | null;
17
+ rounds: Array<IRound> | null;
18
+ use(idx: number, card: ICard): ICard | null;
19
+ say(command: ECommand): ECommand | null;
20
+ }
21
+ export declare function PlayInstance(hand: IHand, teams: [ITeam, ITeam]): IPlayInstance;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PlayInstance = void 0;
4
+ const types_1 = require("../../types");
5
+ function PlayInstance(hand, teams) {
6
+ var _a, _b, _c;
7
+ const instance = {
8
+ state: hand.state,
9
+ 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(idx, card) {
18
+ return hand.use(idx, card);
19
+ },
20
+ say(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,26 @@
1
+ import { ECommand } from "../../types";
2
+ import { ICard } from "./Deck";
3
+ export interface IPlayer {
4
+ teamIdx: number;
5
+ id: string;
6
+ session?: string;
7
+ hand: Array<ICard>;
8
+ commands: Array<ECommand>;
9
+ usedHand: Array<ICard>;
10
+ prevHand: Array<ICard>;
11
+ isTurn: boolean;
12
+ isOwner: boolean;
13
+ disabled: boolean;
14
+ ready: boolean;
15
+ setTurn(turn: boolean): void;
16
+ getPublicPlayer(): IPublicPlayer;
17
+ setSession(session: string): void;
18
+ enable(): void;
19
+ disable(): void;
20
+ setOwner(owner: boolean): void;
21
+ setReady(ready: boolean): void;
22
+ setHand(hand: Array<ICard>): Array<ICard>;
23
+ useCard(idx: number, card: ICard): ICard | null;
24
+ }
25
+ export type IPublicPlayer = Pick<IPlayer, "id" | "disabled" | "ready" | "hand" | "usedHand" | "prevHand" | "teamIdx" | "session" | "isTurn" | "isOwner">;
26
+ export declare function Player(id: string, teamIdx: number, isOwner?: boolean): IPlayer;
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Player = void 0;
4
+ function Player(id, teamIdx, isOwner = false) {
5
+ const player = {
6
+ id,
7
+ session: undefined,
8
+ teamIdx,
9
+ hand: [],
10
+ commands: [],
11
+ usedHand: [],
12
+ prevHand: [],
13
+ isOwner,
14
+ isTurn: false,
15
+ disabled: false,
16
+ ready: false,
17
+ setOwner(owner) {
18
+ player.isOwner = owner;
19
+ },
20
+ setTurn(turn) {
21
+ player.isTurn = turn;
22
+ },
23
+ getPublicPlayer() {
24
+ const { id, disabled, ready, usedHand, prevHand, teamIdx, isTurn, isOwner } = player;
25
+ return {
26
+ id,
27
+ disabled,
28
+ ready,
29
+ usedHand,
30
+ prevHand,
31
+ teamIdx,
32
+ isTurn,
33
+ isOwner,
34
+ hand: player.hand.map(() => "xx"),
35
+ session: undefined,
36
+ };
37
+ },
38
+ setSession(session) {
39
+ player.session = session;
40
+ },
41
+ enable() {
42
+ player.disabled = false;
43
+ },
44
+ disable() {
45
+ player.disabled = true;
46
+ },
47
+ setReady(ready) {
48
+ player.ready = ready;
49
+ },
50
+ setHand(hand) {
51
+ player.prevHand = [...player.usedHand];
52
+ player.hand = hand;
53
+ player.usedHand = [];
54
+ return hand;
55
+ },
56
+ useCard(idx, card) {
57
+ if (player.hand[idx] && player.hand[idx] === card) {
58
+ const card = player.hand.splice(idx, 1)[0];
59
+ player.usedHand.push(card);
60
+ return card;
61
+ }
62
+ return null;
63
+ },
64
+ };
65
+ return player;
66
+ }
67
+ exports.Player = Player;
@@ -0,0 +1,17 @@
1
+ import { ICard, IPlayedCard } from "./Deck";
2
+ import { IPlayer } from "./Player";
3
+ export interface IRound {
4
+ tie: boolean;
5
+ winner: IPlayer | null;
6
+ highest: number;
7
+ cards: Array<IPlayedCard>;
8
+ turn: number;
9
+ nextTurn(): void;
10
+ use(playedCard: IPlayedCard): ICard;
11
+ }
12
+ export interface IRoundPoints {
13
+ 0: number;
14
+ 1: number;
15
+ ties: number;
16
+ }
17
+ export declare function Round(turn: number): IRound;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Round = void 0;
4
+ const utils_1 = require("../utils");
5
+ const Deck_1 = require("./Deck");
6
+ function Round(turn) {
7
+ const round = {
8
+ turn,
9
+ highest: -1,
10
+ winner: null,
11
+ cards: [],
12
+ tie: false,
13
+ nextTurn() {
14
+ round.turn++;
15
+ },
16
+ use({ card, player }) {
17
+ var _a;
18
+ const value = (0, utils_1.getCardValue)(card);
19
+ if (value === round.highest && player.teamIdx !== ((_a = round.winner) === null || _a === void 0 ? void 0 : _a.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((0, Deck_1.PlayedCard)(player, card));
28
+ return card;
29
+ },
30
+ };
31
+ return round;
32
+ }
33
+ exports.Round = Round;
@@ -0,0 +1,12 @@
1
+ import { IPlayedCard } from "./Deck";
2
+ import { IPlayer } from "./Player";
3
+ import { ITeam } from "./Team";
4
+ export interface ITable {
5
+ forehandIdx: number;
6
+ cards: Array<Array<IPlayedCard>>;
7
+ players: Array<IPlayer>;
8
+ nextTurn(): IPlayer;
9
+ player(idx?: number): IPlayer;
10
+ getPlayerPosition(id: string): number;
11
+ }
12
+ export declare function Table(players: Array<IPlayer>, teams: Array<ITeam>): ITable;
@@ -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
+ const table = {
6
+ players,
7
+ cards: [],
8
+ forehandIdx: 0,
9
+ nextTurn() {
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(id) {
19
+ return table.players.findIndex((p) => p.id === id);
20
+ },
21
+ player(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,19 @@
1
+ import { IPlayer, IPublicPlayer } from "./Player";
2
+ export interface ITeam {
3
+ _players: Map<string, IPlayer>;
4
+ players: Array<IPlayer>;
5
+ points: ITeamPoints;
6
+ getPublicTeam(playerSession?: string): IPublicTeam;
7
+ isTeamDisabled(): boolean;
8
+ disable(player: IPlayer): boolean;
9
+ addPoints(matchPoint: number, points: number): ITeamPoints;
10
+ }
11
+ export type IPublicTeam = Pick<ITeam, "points"> & {
12
+ players: Array<IPublicPlayer>;
13
+ };
14
+ export interface ITeamPoints {
15
+ buenas: number;
16
+ malas: number;
17
+ winner: boolean;
18
+ }
19
+ export declare function Team(players: Array<IPlayer>): ITeam;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Team = void 0;
4
+ function Team(players) {
5
+ const 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
+ getPublicTeam(playerSession) {
16
+ return {
17
+ points: team.points,
18
+ players: team.players.map((player) => player.session === playerSession ? player : player.getPublicPlayer()),
19
+ };
20
+ },
21
+ isTeamDisabled() {
22
+ return team.players.reduce((prev, curr) => prev && curr.disabled, true);
23
+ },
24
+ disable(player) {
25
+ var _a;
26
+ (_a = team._players.get(player.session)) === null || _a === void 0 ? void 0 : _a.disable();
27
+ return team.isTeamDisabled();
28
+ },
29
+ addPoints(matchPoint, points) {
30
+ const malas = team.points.malas + points;
31
+ const diff = malas - matchPoint;
32
+ if (diff > 0) {
33
+ team.points.malas = matchPoint;
34
+ team.points.buenas += diff;
35
+ if (team.points.buenas >= matchPoint) {
36
+ team.points.winner = true;
37
+ }
38
+ }
39
+ else {
40
+ team.points.malas = malas;
41
+ }
42
+ return team.points;
43
+ },
44
+ };
45
+ players.forEach((player) => team._players.set(player.session, player));
46
+ return team;
47
+ }
48
+ exports.Team = Team;
@@ -0,0 +1,18 @@
1
+ import { IPlayer } from "./Player";
2
+ export interface ITruco {
3
+ state: 1 | 2 | 3 | 4;
4
+ teamIdx: 0 | 1 | null;
5
+ answer: boolean | null;
6
+ turn: number;
7
+ players: Array<IPlayer>;
8
+ currentPlayer: IPlayer | null;
9
+ generator: Generator<ITruco, void, unknown>;
10
+ sayTruco(teamIdx: 0 | 1, players: Array<IPlayer>): ITruco;
11
+ setPlayers(players: Array<IPlayer>): void;
12
+ setAnswer(answer: boolean | null): ITruco;
13
+ setTurn(turn: number): number;
14
+ setTeam(idx: 0 | 1): 0 | 1;
15
+ setCurrentPlayer(player: IPlayer | null): IPlayer | null;
16
+ getNextPlayer(): IteratorResult<ITruco, ITruco | void>;
17
+ }
18
+ export declare function Truco(): ITruco;
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Truco = void 0;
4
+ function Truco() {
5
+ function* trucoAnswerGeneratorSequence() {
6
+ let i = 0;
7
+ while (i < truco.players.length && truco.answer === null) {
8
+ const player = truco.players[truco.turn];
9
+ truco.setCurrentPlayer(player);
10
+ if (player.disabled) {
11
+ truco.setCurrentPlayer(null);
12
+ }
13
+ if (truco.turn >= truco.players.length - 1) {
14
+ truco.setTurn(0);
15
+ }
16
+ else {
17
+ truco.setTurn(truco.turn + 1);
18
+ }
19
+ i++;
20
+ yield truco;
21
+ }
22
+ yield truco;
23
+ }
24
+ const truco = {
25
+ turn: 0,
26
+ state: 1,
27
+ teamIdx: null,
28
+ answer: null,
29
+ currentPlayer: null,
30
+ generator: trucoAnswerGeneratorSequence(),
31
+ players: [],
32
+ sayTruco(teamIdx, players) {
33
+ truco.teamIdx = teamIdx;
34
+ truco.answer = null;
35
+ truco.players = players;
36
+ truco.generator = trucoAnswerGeneratorSequence();
37
+ return truco;
38
+ },
39
+ setPlayers(players) {
40
+ truco.players = players;
41
+ },
42
+ setAnswer(answer) {
43
+ if (answer) {
44
+ truco.state++;
45
+ }
46
+ if (answer !== null) {
47
+ truco.teamIdx = null;
48
+ }
49
+ truco.answer = answer;
50
+ return truco;
51
+ },
52
+ setTeam(idx) {
53
+ truco.teamIdx = idx;
54
+ return truco.teamIdx;
55
+ },
56
+ setTurn(turn) {
57
+ truco.turn = turn;
58
+ return truco.turn;
59
+ },
60
+ setCurrentPlayer(player) {
61
+ truco.currentPlayer = player;
62
+ return truco.currentPlayer;
63
+ },
64
+ getNextPlayer() {
65
+ return truco.generator.next();
66
+ },
67
+ };
68
+ return truco;
69
+ }
70
+ exports.Truco = Truco;
@@ -0,0 +1,11 @@
1
+ export * from "./Deck";
2
+ export * from "./GameLoop";
3
+ export * from "./Hand";
4
+ export * from "./Lobby";
5
+ export * from "./Match";
6
+ export * from "./Play";
7
+ export * from "./Player";
8
+ export * from "./Round";
9
+ export * from "./Table";
10
+ export * from "./Team";
11
+ export * from "./Truco";
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./Deck"), exports);
18
+ __exportStar(require("./GameLoop"), exports);
19
+ __exportStar(require("./Hand"), exports);
20
+ __exportStar(require("./Lobby"), exports);
21
+ __exportStar(require("./Match"), exports);
22
+ __exportStar(require("./Play"), exports);
23
+ __exportStar(require("./Player"), exports);
24
+ __exportStar(require("./Round"), exports);
25
+ __exportStar(require("./Table"), exports);
26
+ __exportStar(require("./Team"), exports);
27
+ __exportStar(require("./Truco"), exports);
@@ -0,0 +1,45 @@
1
+ import { IEnvidoCalculator } from "../types";
2
+ export declare const CARDS: {
3
+ "1e": number;
4
+ "1b": number;
5
+ "7e": number;
6
+ "7o": number;
7
+ "3e": number;
8
+ "3o": number;
9
+ "3b": number;
10
+ "3c": number;
11
+ "2e": number;
12
+ "2o": number;
13
+ "2b": number;
14
+ "2c": number;
15
+ "1o": number;
16
+ "1c": number;
17
+ re: number;
18
+ ro: number;
19
+ rb: number;
20
+ rc: number;
21
+ ce: number;
22
+ co: number;
23
+ cb: number;
24
+ cc: number;
25
+ pe: number;
26
+ po: number;
27
+ pb: number;
28
+ pc: number;
29
+ "7b": number;
30
+ "7c": number;
31
+ "6e": number;
32
+ "6o": number;
33
+ "6b": number;
34
+ "6c": number;
35
+ "5e": number;
36
+ "5o": number;
37
+ "5b": number;
38
+ "5c": number;
39
+ "4e": number;
40
+ "4o": number;
41
+ "4b": number;
42
+ "4c": number;
43
+ };
44
+ export declare const TEAM_SIZE_VALUES: number[];
45
+ export declare const EnvidoCalculator: IEnvidoCalculator;
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EnvidoCalculator = exports.TEAM_SIZE_VALUES = exports.CARDS = void 0;
4
+ const types_1 = require("../types");
5
+ const utils_1 = require("./utils");
6
+ exports.CARDS = {
7
+ "1e": 14,
8
+ "1b": 13,
9
+ "7e": 12,
10
+ "7o": 11,
11
+ "3e": 10,
12
+ "3o": 10,
13
+ "3b": 10,
14
+ "3c": 10,
15
+ "2e": 9,
16
+ "2o": 9,
17
+ "2b": 8,
18
+ "2c": 8,
19
+ "1o": 7,
20
+ "1c": 7,
21
+ re: 6,
22
+ ro: 6,
23
+ rb: 6,
24
+ rc: 6,
25
+ ce: 5,
26
+ co: 5,
27
+ cb: 5,
28
+ cc: 5,
29
+ pe: 4,
30
+ po: 4,
31
+ pb: 4,
32
+ pc: 4,
33
+ "7b": 3,
34
+ "7c": 3,
35
+ "6e": 2,
36
+ "6o": 2,
37
+ "6b": 2,
38
+ "6c": 2,
39
+ "5e": 1,
40
+ "5o": 1,
41
+ "5b": 1,
42
+ "5c": 1,
43
+ "4e": 0,
44
+ "4o": 0,
45
+ "4b": 0,
46
+ "4c": 0,
47
+ };
48
+ exports.TEAM_SIZE_VALUES = [1, 2, 3];
49
+ exports.EnvidoCalculator = {
50
+ [types_1.EEnvidoCommand.ENVIDO]: () => ({
51
+ accept: 2,
52
+ decline: 1,
53
+ next: [types_1.EEnvidoCommand.ENVIDO_ENVIDO, types_1.EEnvidoCommand.REAL_ENVIDO, types_1.EEnvidoCommand.FALTA_ENVIDO],
54
+ }),
55
+ [types_1.EEnvidoCommand.ENVIDO_ENVIDO]: () => ({
56
+ accept: 4,
57
+ decline: 2,
58
+ next: [types_1.EEnvidoCommand.REAL_ENVIDO, types_1.EEnvidoCommand.FALTA_ENVIDO],
59
+ }),
60
+ [types_1.EEnvidoCommand.REAL_ENVIDO]: () => ({
61
+ accept: 3,
62
+ decline: 1,
63
+ next: [types_1.EEnvidoCommand.FALTA_ENVIDO],
64
+ }),
65
+ [types_1.EEnvidoCommand.FALTA_ENVIDO]: (args) => {
66
+ if (!args || !args.teams || !args.matchPoint) {
67
+ return {
68
+ accept: 1,
69
+ decline: 1,
70
+ next: [],
71
+ };
72
+ }
73
+ const { teams, matchPoint } = args;
74
+ const totals = teams.map((team) => team.points.malas + team.points.buenas);
75
+ const higher = (0, utils_1.getMaxNumberIndex)(totals);
76
+ const points = teams[higher].points;
77
+ const accept = points.buenas > 0 ? matchPoint - points.buenas : matchPoint - points.malas;
78
+ return {
79
+ accept,
80
+ decline: 2,
81
+ next: [],
82
+ };
83
+ },
84
+ };
@@ -0,0 +1,2 @@
1
+ export * from "./classes";
2
+ export * from "./constants";
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./classes"), exports);
18
+ __exportStar(require("./constants"), exports);