trucoshi 0.2.0 → 0.2.1
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 -674
- package/README.md +60 -60
- package/dist/index.d.ts +2 -2
- package/dist/index.js +18 -18
- package/dist/lib/classes/Deck.d.ts +16 -16
- package/dist/lib/classes/Deck.js +38 -38
- package/dist/lib/classes/GameLoop.d.ts +20 -20
- package/dist/lib/classes/GameLoop.js +61 -61
- package/dist/lib/classes/Hand.d.ts +38 -38
- package/dist/lib/classes/Hand.js +184 -184
- package/dist/lib/classes/Lobby.d.ts +27 -27
- package/dist/lib/classes/Lobby.js +112 -112
- package/dist/lib/classes/Match.d.ts +18 -18
- package/dist/lib/classes/Match.js +72 -72
- package/dist/lib/classes/Play.d.ts +21 -21
- package/dist/lib/classes/Play.js +39 -39
- package/dist/lib/classes/Player.d.ts +26 -26
- package/dist/lib/classes/Player.js +67 -67
- package/dist/lib/classes/Round.d.ts +17 -17
- package/dist/lib/classes/Round.js +33 -33
- package/dist/lib/classes/Table.d.ts +12 -12
- package/dist/lib/classes/Table.js +30 -30
- package/dist/lib/classes/Team.d.ts +19 -19
- package/dist/lib/classes/Team.js +48 -48
- package/dist/lib/classes/Truco.d.ts +18 -18
- package/dist/lib/classes/Truco.js +70 -70
- package/dist/lib/classes/index.d.ts +11 -11
- package/dist/lib/classes/index.js +27 -27
- package/dist/lib/constants.d.ts +45 -45
- package/dist/lib/constants.js +84 -84
- package/dist/lib/index.d.ts +2 -2
- package/dist/lib/index.js +18 -18
- package/dist/lib/types.d.ts +50 -50
- package/dist/lib/types.js +34 -34
- package/dist/lib/utils.d.ts +5 -5
- package/dist/lib/utils.js +58 -58
- package/dist/types.d.ts +138 -133
- package/dist/types.js +65 -65
- package/package.json +1 -1
package/dist/lib/constants.js
CHANGED
|
@@ -1,84 +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
|
-
};
|
|
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
|
+
};
|
package/dist/lib/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from "./classes";
|
|
2
|
-
export * from "./constants";
|
|
1
|
+
export * from "./classes";
|
|
2
|
+
export * from "./constants";
|
package/dist/lib/index.js
CHANGED
|
@@ -1,18 +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);
|
|
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);
|
package/dist/lib/types.d.ts
CHANGED
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
import { IPlayer } from "./classes/Player";
|
|
2
|
-
import { ITeam } from "./classes/Team";
|
|
3
|
-
export declare enum ESayCommand {
|
|
4
|
-
QUIERO = "QUIERO",
|
|
5
|
-
NO_QUIERO = "NO_QUIERO",
|
|
6
|
-
TRUCO = "TRUCO",
|
|
7
|
-
MAZO = "MAZO",
|
|
8
|
-
FLOR = "FLOR",
|
|
9
|
-
CONTRAFLOR = "CONTRAFLOR"
|
|
10
|
-
}
|
|
11
|
-
export declare enum EEnvidoCommand {
|
|
12
|
-
ENVIDO = "ENVIDO",
|
|
13
|
-
ENVIDO_ENVIDO = "ENVIDO_ENVIDO",
|
|
14
|
-
REAL_ENVIDO = "REAL_ENVIDO",
|
|
15
|
-
FALTA_ENVIDO = "FALTA_ENVIDO"
|
|
16
|
-
}
|
|
17
|
-
export declare enum EHandState {
|
|
18
|
-
WAITING_PLAY = "WAITING_PLAY",
|
|
19
|
-
WAITING_FOR_TRUCO_ANSWER = "WAITING_FOR_TRUCO_ANSWER",
|
|
20
|
-
WAITING_ENVIDO_ANSWER = "WAITING_ENVIDO_ANSWER",
|
|
21
|
-
FINISHED = "FINISHED"
|
|
22
|
-
}
|
|
23
|
-
export type ECommand = ESayCommand | EEnvidoCommand;
|
|
24
|
-
export declare enum GAME_ERROR {
|
|
25
|
-
MATCH_ALREADY_STARTED = "MATCH_ALREADY_STARTED",
|
|
26
|
-
LOBBY_IS_FULL = "LOBBY_IS_FULL",
|
|
27
|
-
UNEXPECTED_TEAM_SIZE = "UNEXPECTED_TEAM_SIZE",
|
|
28
|
-
TEAM_NOT_READY = "TEAM_NOT_READY",
|
|
29
|
-
TEAM_IS_FULL = "TEAM_IS_FULL"
|
|
30
|
-
}
|
|
31
|
-
export interface EnvidoState {
|
|
32
|
-
accept: number;
|
|
33
|
-
decline: number;
|
|
34
|
-
teamIdx: 0 | 1 | null;
|
|
35
|
-
}
|
|
36
|
-
export type IHandCommands = {
|
|
37
|
-
[key in ECommand]: (player: IPlayer) => void;
|
|
38
|
-
};
|
|
39
|
-
export type IEnvidoCalculatorResult = {
|
|
40
|
-
accept: number;
|
|
41
|
-
decline: number;
|
|
42
|
-
next: Array<ECommand>;
|
|
43
|
-
};
|
|
44
|
-
export type IEnvidoCalculatorArgs = {
|
|
45
|
-
teams: [ITeam, ITeam];
|
|
46
|
-
matchPoint: number;
|
|
47
|
-
};
|
|
48
|
-
export type IEnvidoCalculator = {
|
|
49
|
-
[key in EEnvidoCommand]: (args?: IEnvidoCalculatorArgs) => IEnvidoCalculatorResult;
|
|
50
|
-
};
|
|
1
|
+
import { IPlayer } from "./classes/Player";
|
|
2
|
+
import { ITeam } from "./classes/Team";
|
|
3
|
+
export declare enum ESayCommand {
|
|
4
|
+
QUIERO = "QUIERO",
|
|
5
|
+
NO_QUIERO = "NO_QUIERO",
|
|
6
|
+
TRUCO = "TRUCO",
|
|
7
|
+
MAZO = "MAZO",
|
|
8
|
+
FLOR = "FLOR",
|
|
9
|
+
CONTRAFLOR = "CONTRAFLOR"
|
|
10
|
+
}
|
|
11
|
+
export declare enum EEnvidoCommand {
|
|
12
|
+
ENVIDO = "ENVIDO",
|
|
13
|
+
ENVIDO_ENVIDO = "ENVIDO_ENVIDO",
|
|
14
|
+
REAL_ENVIDO = "REAL_ENVIDO",
|
|
15
|
+
FALTA_ENVIDO = "FALTA_ENVIDO"
|
|
16
|
+
}
|
|
17
|
+
export declare enum EHandState {
|
|
18
|
+
WAITING_PLAY = "WAITING_PLAY",
|
|
19
|
+
WAITING_FOR_TRUCO_ANSWER = "WAITING_FOR_TRUCO_ANSWER",
|
|
20
|
+
WAITING_ENVIDO_ANSWER = "WAITING_ENVIDO_ANSWER",
|
|
21
|
+
FINISHED = "FINISHED"
|
|
22
|
+
}
|
|
23
|
+
export type ECommand = ESayCommand | EEnvidoCommand;
|
|
24
|
+
export declare enum GAME_ERROR {
|
|
25
|
+
MATCH_ALREADY_STARTED = "MATCH_ALREADY_STARTED",
|
|
26
|
+
LOBBY_IS_FULL = "LOBBY_IS_FULL",
|
|
27
|
+
UNEXPECTED_TEAM_SIZE = "UNEXPECTED_TEAM_SIZE",
|
|
28
|
+
TEAM_NOT_READY = "TEAM_NOT_READY",
|
|
29
|
+
TEAM_IS_FULL = "TEAM_IS_FULL"
|
|
30
|
+
}
|
|
31
|
+
export interface EnvidoState {
|
|
32
|
+
accept: number;
|
|
33
|
+
decline: number;
|
|
34
|
+
teamIdx: 0 | 1 | null;
|
|
35
|
+
}
|
|
36
|
+
export type IHandCommands = {
|
|
37
|
+
[key in ECommand]: (player: IPlayer) => void;
|
|
38
|
+
};
|
|
39
|
+
export type IEnvidoCalculatorResult = {
|
|
40
|
+
accept: number;
|
|
41
|
+
decline: number;
|
|
42
|
+
next: Array<ECommand>;
|
|
43
|
+
};
|
|
44
|
+
export type IEnvidoCalculatorArgs = {
|
|
45
|
+
teams: [ITeam, ITeam];
|
|
46
|
+
matchPoint: number;
|
|
47
|
+
};
|
|
48
|
+
export type IEnvidoCalculator = {
|
|
49
|
+
[key in EEnvidoCommand]: (args?: IEnvidoCalculatorArgs) => IEnvidoCalculatorResult;
|
|
50
|
+
};
|
package/dist/lib/types.js
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.GAME_ERROR = exports.EHandState = exports.EEnvidoCommand = exports.ESayCommand = void 0;
|
|
4
|
-
var ESayCommand;
|
|
5
|
-
(function (ESayCommand) {
|
|
6
|
-
ESayCommand["QUIERO"] = "QUIERO";
|
|
7
|
-
ESayCommand["NO_QUIERO"] = "NO_QUIERO";
|
|
8
|
-
ESayCommand["TRUCO"] = "TRUCO";
|
|
9
|
-
ESayCommand["MAZO"] = "MAZO";
|
|
10
|
-
ESayCommand["FLOR"] = "FLOR";
|
|
11
|
-
ESayCommand["CONTRAFLOR"] = "CONTRAFLOR";
|
|
12
|
-
})(ESayCommand = exports.ESayCommand || (exports.ESayCommand = {}));
|
|
13
|
-
var EEnvidoCommand;
|
|
14
|
-
(function (EEnvidoCommand) {
|
|
15
|
-
EEnvidoCommand["ENVIDO"] = "ENVIDO";
|
|
16
|
-
EEnvidoCommand["ENVIDO_ENVIDO"] = "ENVIDO_ENVIDO";
|
|
17
|
-
EEnvidoCommand["REAL_ENVIDO"] = "REAL_ENVIDO";
|
|
18
|
-
EEnvidoCommand["FALTA_ENVIDO"] = "FALTA_ENVIDO";
|
|
19
|
-
})(EEnvidoCommand = exports.EEnvidoCommand || (exports.EEnvidoCommand = {}));
|
|
20
|
-
var EHandState;
|
|
21
|
-
(function (EHandState) {
|
|
22
|
-
EHandState["WAITING_PLAY"] = "WAITING_PLAY";
|
|
23
|
-
EHandState["WAITING_FOR_TRUCO_ANSWER"] = "WAITING_FOR_TRUCO_ANSWER";
|
|
24
|
-
EHandState["WAITING_ENVIDO_ANSWER"] = "WAITING_ENVIDO_ANSWER";
|
|
25
|
-
EHandState["FINISHED"] = "FINISHED";
|
|
26
|
-
})(EHandState = exports.EHandState || (exports.EHandState = {}));
|
|
27
|
-
var GAME_ERROR;
|
|
28
|
-
(function (GAME_ERROR) {
|
|
29
|
-
GAME_ERROR["MATCH_ALREADY_STARTED"] = "MATCH_ALREADY_STARTED";
|
|
30
|
-
GAME_ERROR["LOBBY_IS_FULL"] = "LOBBY_IS_FULL";
|
|
31
|
-
GAME_ERROR["UNEXPECTED_TEAM_SIZE"] = "UNEXPECTED_TEAM_SIZE";
|
|
32
|
-
GAME_ERROR["TEAM_NOT_READY"] = "TEAM_NOT_READY";
|
|
33
|
-
GAME_ERROR["TEAM_IS_FULL"] = "TEAM_IS_FULL";
|
|
34
|
-
})(GAME_ERROR = exports.GAME_ERROR || (exports.GAME_ERROR = {}));
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GAME_ERROR = exports.EHandState = exports.EEnvidoCommand = exports.ESayCommand = void 0;
|
|
4
|
+
var ESayCommand;
|
|
5
|
+
(function (ESayCommand) {
|
|
6
|
+
ESayCommand["QUIERO"] = "QUIERO";
|
|
7
|
+
ESayCommand["NO_QUIERO"] = "NO_QUIERO";
|
|
8
|
+
ESayCommand["TRUCO"] = "TRUCO";
|
|
9
|
+
ESayCommand["MAZO"] = "MAZO";
|
|
10
|
+
ESayCommand["FLOR"] = "FLOR";
|
|
11
|
+
ESayCommand["CONTRAFLOR"] = "CONTRAFLOR";
|
|
12
|
+
})(ESayCommand = exports.ESayCommand || (exports.ESayCommand = {}));
|
|
13
|
+
var EEnvidoCommand;
|
|
14
|
+
(function (EEnvidoCommand) {
|
|
15
|
+
EEnvidoCommand["ENVIDO"] = "ENVIDO";
|
|
16
|
+
EEnvidoCommand["ENVIDO_ENVIDO"] = "ENVIDO_ENVIDO";
|
|
17
|
+
EEnvidoCommand["REAL_ENVIDO"] = "REAL_ENVIDO";
|
|
18
|
+
EEnvidoCommand["FALTA_ENVIDO"] = "FALTA_ENVIDO";
|
|
19
|
+
})(EEnvidoCommand = exports.EEnvidoCommand || (exports.EEnvidoCommand = {}));
|
|
20
|
+
var EHandState;
|
|
21
|
+
(function (EHandState) {
|
|
22
|
+
EHandState["WAITING_PLAY"] = "WAITING_PLAY";
|
|
23
|
+
EHandState["WAITING_FOR_TRUCO_ANSWER"] = "WAITING_FOR_TRUCO_ANSWER";
|
|
24
|
+
EHandState["WAITING_ENVIDO_ANSWER"] = "WAITING_ENVIDO_ANSWER";
|
|
25
|
+
EHandState["FINISHED"] = "FINISHED";
|
|
26
|
+
})(EHandState = exports.EHandState || (exports.EHandState = {}));
|
|
27
|
+
var GAME_ERROR;
|
|
28
|
+
(function (GAME_ERROR) {
|
|
29
|
+
GAME_ERROR["MATCH_ALREADY_STARTED"] = "MATCH_ALREADY_STARTED";
|
|
30
|
+
GAME_ERROR["LOBBY_IS_FULL"] = "LOBBY_IS_FULL";
|
|
31
|
+
GAME_ERROR["UNEXPECTED_TEAM_SIZE"] = "UNEXPECTED_TEAM_SIZE";
|
|
32
|
+
GAME_ERROR["TEAM_NOT_READY"] = "TEAM_NOT_READY";
|
|
33
|
+
GAME_ERROR["TEAM_IS_FULL"] = "TEAM_IS_FULL";
|
|
34
|
+
})(GAME_ERROR = exports.GAME_ERROR || (exports.GAME_ERROR = {}));
|
package/dist/lib/utils.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
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;
|
|
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
CHANGED
|
@@ -1,58 +1,58 @@
|
|
|
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;
|
|
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;
|