trucoshi 0.3.53 → 0.4.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 (43) hide show
  1. package/dist/types.d.ts +58 -21
  2. package/dist/types.js +12 -9
  3. package/package.json +9 -9
  4. package/dist/index.d.ts +0 -2
  5. package/dist/index.js +0 -18
  6. package/dist/lib/classes/Deck.d.ts +0 -17
  7. package/dist/lib/classes/Deck.js +0 -41
  8. package/dist/lib/classes/Envido.d.ts +0 -34
  9. package/dist/lib/classes/Envido.js +0 -168
  10. package/dist/lib/classes/Flor.d.ts +0 -0
  11. package/dist/lib/classes/Flor.js +0 -1
  12. package/dist/lib/classes/GameLoop.d.ts +0 -28
  13. package/dist/lib/classes/GameLoop.js +0 -115
  14. package/dist/lib/classes/Hand.d.ts +0 -43
  15. package/dist/lib/classes/Hand.js +0 -295
  16. package/dist/lib/classes/Lobby.d.ts +0 -31
  17. package/dist/lib/classes/Lobby.js +0 -146
  18. package/dist/lib/classes/Match.d.ts +0 -21
  19. package/dist/lib/classes/Match.js +0 -90
  20. package/dist/lib/classes/Play.d.ts +0 -22
  21. package/dist/lib/classes/Play.js +0 -47
  22. package/dist/lib/classes/Player.d.ts +0 -36
  23. package/dist/lib/classes/Player.js +0 -117
  24. package/dist/lib/classes/Queue.d.ts +0 -5
  25. package/dist/lib/classes/Queue.js +0 -15
  26. package/dist/lib/classes/Round.d.ts +0 -17
  27. package/dist/lib/classes/Round.js +0 -33
  28. package/dist/lib/classes/Table.d.ts +0 -12
  29. package/dist/lib/classes/Table.js +0 -38
  30. package/dist/lib/classes/Team.d.ts +0 -20
  31. package/dist/lib/classes/Team.js +0 -59
  32. package/dist/lib/classes/Truco.d.ts +0 -30
  33. package/dist/lib/classes/Truco.js +0 -97
  34. package/dist/lib/classes/index.d.ts +0 -11
  35. package/dist/lib/classes/index.js +0 -27
  36. package/dist/lib/constants.d.ts +0 -43
  37. package/dist/lib/constants.js +0 -46
  38. package/dist/lib/index.d.ts +0 -2
  39. package/dist/lib/index.js +0 -18
  40. package/dist/lib/types.d.ts +0 -44
  41. package/dist/lib/types.js +0 -21
  42. package/dist/lib/utils.d.ts +0 -5
  43. package/dist/lib/utils.js +0 -58
@@ -1,44 +0,0 @@
1
- import { ECommand, EEnvidoCommand } from "../types";
2
- import { IPlayer } from "./classes/Player";
3
- import { ITeam } from "./classes/Team";
4
- export declare enum EHandState {
5
- WAITING_PLAY = "WAITING_PLAY",
6
- WAITING_FOR_TRUCO_ANSWER = "WAITING_FOR_TRUCO_ANSWER",
7
- WAITING_ENVIDO_ANSWER = "WAITING_ENVIDO_ANSWER",
8
- FINISHED = "FINISHED"
9
- }
10
- export declare enum GAME_ERROR {
11
- MATCH_ALREADY_STARTED = "MATCH_ALREADY_STARTED",
12
- LOBBY_IS_FULL = "LOBBY_IS_FULL",
13
- UNEXPECTED_TEAM_SIZE = "UNEXPECTED_TEAM_SIZE",
14
- TEAM_NOT_READY = "TEAM_NOT_READY",
15
- TEAM_IS_FULL = "TEAM_IS_FULL",
16
- INVALID_ENVIDO_POINTS = "INVALID_ENVIDO_POINTS",
17
- ENVIDO_NOT_ACCEPTED = "ENVIDO_NOT_ACCEPTED",
18
- INVALID_COMAND = "INVALID_COMAND"
19
- }
20
- export interface EnvidoState {
21
- accept: number;
22
- decline: number;
23
- teamIdx: 0 | 1 | null;
24
- }
25
- export type IHandCommands = {
26
- [key in ECommand]: (player: IPlayer) => void;
27
- };
28
- export type IEnvidoCalculatorResult = {
29
- accept: number;
30
- decline: number;
31
- replace?: number;
32
- next: Array<ECommand>;
33
- };
34
- export type IFaltaEnvidoCalculatorArgs = {
35
- teams: [ITeam, ITeam];
36
- matchPoint: number;
37
- };
38
- export type IEnvidoCalculatorArgs = {
39
- stake: number;
40
- declineStake: number;
41
- } & (IFaltaEnvidoCalculatorArgs | never);
42
- export type IEnvidoCalculator = {
43
- [key in EEnvidoCommand]: (args?: IEnvidoCalculatorArgs) => IEnvidoCalculatorResult;
44
- };
package/dist/lib/types.js DELETED
@@ -1,21 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GAME_ERROR = exports.EHandState = void 0;
4
- var EHandState;
5
- (function (EHandState) {
6
- EHandState["WAITING_PLAY"] = "WAITING_PLAY";
7
- EHandState["WAITING_FOR_TRUCO_ANSWER"] = "WAITING_FOR_TRUCO_ANSWER";
8
- EHandState["WAITING_ENVIDO_ANSWER"] = "WAITING_ENVIDO_ANSWER";
9
- EHandState["FINISHED"] = "FINISHED";
10
- })(EHandState = exports.EHandState || (exports.EHandState = {}));
11
- var GAME_ERROR;
12
- (function (GAME_ERROR) {
13
- GAME_ERROR["MATCH_ALREADY_STARTED"] = "MATCH_ALREADY_STARTED";
14
- GAME_ERROR["LOBBY_IS_FULL"] = "LOBBY_IS_FULL";
15
- GAME_ERROR["UNEXPECTED_TEAM_SIZE"] = "UNEXPECTED_TEAM_SIZE";
16
- GAME_ERROR["TEAM_NOT_READY"] = "TEAM_NOT_READY";
17
- GAME_ERROR["TEAM_IS_FULL"] = "TEAM_IS_FULL";
18
- GAME_ERROR["INVALID_ENVIDO_POINTS"] = "INVALID_ENVIDO_POINTS";
19
- GAME_ERROR["ENVIDO_NOT_ACCEPTED"] = "ENVIDO_NOT_ACCEPTED";
20
- GAME_ERROR["INVALID_COMAND"] = "INVALID_COMAND";
21
- })(GAME_ERROR = exports.GAME_ERROR || (exports.GAME_ERROR = {}));
@@ -1,5 +0,0 @@
1
- import { ICard, IRound } from "./classes";
2
- export declare function getMaxNumberIndex<T = number>(array: Array<T>): number;
3
- export declare function getCardValue(card: ICard): number;
4
- export declare function shuffleArray<T = unknown>(array: Array<T>): T[];
5
- export declare function checkHandWinner(rounds: Array<IRound>, forehandTeamIdx: 0 | 1): null | 0 | 1;
package/dist/lib/utils.js DELETED
@@ -1,58 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.checkHandWinner = exports.shuffleArray = exports.getCardValue = exports.getMaxNumberIndex = void 0;
4
- const constants_1 = require("./constants");
5
- function getMaxNumberIndex(array) {
6
- return array.reduce((accumulator, current, index) => {
7
- return current > array[accumulator] ? index : accumulator;
8
- }, 0);
9
- }
10
- exports.getMaxNumberIndex = getMaxNumberIndex;
11
- function getCardValue(card) {
12
- return constants_1.CARDS[card] || -1;
13
- }
14
- exports.getCardValue = getCardValue;
15
- function shuffleArray(array) {
16
- let currentIndex = array.length, randomIndex;
17
- while (currentIndex != 0) {
18
- randomIndex = Math.floor(Math.random() * currentIndex);
19
- currentIndex--;
20
- [array[currentIndex], array[randomIndex]] = [array[randomIndex], array[currentIndex]];
21
- }
22
- return array;
23
- }
24
- exports.shuffleArray = shuffleArray;
25
- function checkHandWinner(rounds, forehandTeamIdx) {
26
- var _a, _b;
27
- const roundsWon = {
28
- 0: 0,
29
- 1: 0,
30
- ties: 0,
31
- };
32
- for (let i = 0; i < rounds.length; i++) {
33
- const round = rounds[i];
34
- if (round.tie) {
35
- roundsWon[0] += 1;
36
- roundsWon[1] += 1;
37
- roundsWon.ties = roundsWon.ties + 1;
38
- continue;
39
- }
40
- if (((_a = round.winner) === null || _a === void 0 ? void 0 : _a.teamIdx) === 0) {
41
- roundsWon[0] += 1;
42
- }
43
- if (((_b = round.winner) === null || _b === void 0 ? void 0 : _b.teamIdx) === 1) {
44
- roundsWon[1] += 1;
45
- }
46
- }
47
- if ((roundsWon[0] > 2 && roundsWon[1] > 2) || (rounds.length > 2 && roundsWon.ties > 0)) {
48
- return forehandTeamIdx;
49
- }
50
- if (roundsWon[0] >= 2 && roundsWon[1] < 2) {
51
- return 0;
52
- }
53
- if (roundsWon[1] >= 2 && roundsWon[0] < 2) {
54
- return 1;
55
- }
56
- return null;
57
- }
58
- exports.checkHandWinner = checkHandWinner;