trucoshi 0.3.3 → 0.3.4
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/dist/lib/classes/Envido.d.ts +34 -0
- package/dist/lib/classes/Envido.js +167 -0
- package/dist/lib/classes/Flor.d.ts +0 -0
- package/dist/lib/classes/Flor.js +1 -0
- package/dist/lib/classes/GameLoop.d.ts +3 -0
- package/dist/lib/classes/GameLoop.js +31 -4
- package/dist/lib/classes/Hand.d.ts +7 -3
- package/dist/lib/classes/Hand.js +149 -51
- package/dist/lib/classes/Lobby.js +1 -1
- package/dist/lib/classes/Match.d.ts +1 -0
- package/dist/lib/classes/Match.js +1 -0
- package/dist/lib/classes/Play.d.ts +4 -3
- package/dist/lib/classes/Play.js +21 -6
- package/dist/lib/classes/Player.d.ts +7 -2
- package/dist/lib/classes/Player.js +58 -6
- package/dist/lib/classes/Table.d.ts +4 -4
- package/dist/lib/classes/Table.js +15 -7
- package/dist/lib/classes/Truco.d.ts +11 -2
- package/dist/lib/classes/Truco.js +19 -53
- package/dist/lib/constants.d.ts +0 -2
- package/dist/lib/constants.js +1 -39
- package/dist/lib/types.d.ts +10 -2
- package/dist/lib/types.js +3 -0
- package/dist/types.d.ts +21 -19
- package/dist/types.js +22 -7
- package/package.json +1 -1
package/dist/lib/classes/Play.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PlayInstance = void 0;
|
|
4
|
-
const types_1 = require("
|
|
4
|
+
const types_1 = require("../types");
|
|
5
5
|
function PlayInstance(hand, prevHand, teams) {
|
|
6
6
|
const instance = {
|
|
7
7
|
state: hand.state,
|
|
@@ -17,13 +17,28 @@ function PlayInstance(hand, prevHand, teams) {
|
|
|
17
17
|
return hand.use(idx, card);
|
|
18
18
|
},
|
|
19
19
|
say(command, player) {
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
try {
|
|
21
|
+
const fn = hand.say[command];
|
|
22
|
+
if (fn) {
|
|
23
|
+
if (!player.commands.includes(command)) {
|
|
24
|
+
throw new Error(types_1.GAME_ERROR.INVALID_COMAND);
|
|
25
|
+
}
|
|
26
|
+
fn(player);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
if (!player.envido.includes(command)) {
|
|
30
|
+
throw new Error(types_1.GAME_ERROR.INVALID_ENVIDO_POINTS);
|
|
31
|
+
}
|
|
32
|
+
hand.sayEnvidoPoints(player, command);
|
|
33
|
+
}
|
|
34
|
+
return command;
|
|
35
|
+
}
|
|
36
|
+
catch (e) {
|
|
37
|
+
console.error(e);
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
22
40
|
},
|
|
23
41
|
};
|
|
24
|
-
if (!hand.truco.waitingAnswer) {
|
|
25
|
-
teams.forEach((team) => team.players.forEach((player) => player._commands.add(types_1.ESayCommand.MAZO)));
|
|
26
|
-
}
|
|
27
42
|
return instance;
|
|
28
43
|
}
|
|
29
44
|
exports.PlayInstance = PlayInstance;
|
|
@@ -6,25 +6,30 @@ export interface IPlayer {
|
|
|
6
6
|
key: string;
|
|
7
7
|
session?: string;
|
|
8
8
|
hand: Array<ICard>;
|
|
9
|
+
envido: Array<number>;
|
|
9
10
|
_commands: Set<ECommand>;
|
|
10
11
|
get commands(): Array<ECommand>;
|
|
11
12
|
usedHand: Array<ICard>;
|
|
12
13
|
prevHand: Array<ICard>;
|
|
13
14
|
isTurn: boolean;
|
|
15
|
+
hasFlor: boolean;
|
|
16
|
+
isEnvidoTurn: boolean;
|
|
14
17
|
isOwner: boolean;
|
|
15
18
|
disabled: boolean;
|
|
16
19
|
ready: boolean;
|
|
20
|
+
resetCommands(): void;
|
|
21
|
+
calculateEnvido(): Array<number>;
|
|
17
22
|
setTurn(turn: boolean): void;
|
|
23
|
+
setEnvidoTurn(turn: boolean): void;
|
|
18
24
|
getPublicPlayer(): IPublicPlayer;
|
|
19
25
|
setSession(session: string): void;
|
|
20
26
|
enable(): void;
|
|
21
27
|
disable(): void;
|
|
22
|
-
setOwner(owner: boolean): void;
|
|
23
28
|
setReady(ready: boolean): void;
|
|
24
29
|
setHand(hand: Array<ICard>): Array<ICard>;
|
|
25
30
|
useCard(idx: number, card: ICard): ICard | null;
|
|
26
31
|
}
|
|
27
|
-
export type IPublicPlayer = Pick<IPlayer, "id" | "key" | "disabled" | "ready" | "hand" | "usedHand" | "prevHand" | "teamIdx" | "session" | "isTurn" | "isOwner"> & {
|
|
32
|
+
export type IPublicPlayer = Pick<IPlayer, "id" | "key" | "disabled" | "ready" | "hand" | "envido" | "usedHand" | "prevHand" | "teamIdx" | "session" | "hasFlor" | "isTurn" | "isEnvidoTurn" | "isOwner"> & {
|
|
28
33
|
commands: Array<ECommand>;
|
|
29
34
|
};
|
|
30
35
|
export declare function Player(key: string, id: string, teamIdx: number, isOwner?: boolean): IPlayer;
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Player = void 0;
|
|
4
|
+
const types_1 = require("../../types");
|
|
5
|
+
const filterEnvidoCommands = (command) => Object.values(types_1.EEnvidoCommand).includes(command) ||
|
|
6
|
+
Object.values(types_1.EAnswerCommand).includes(command) ||
|
|
7
|
+
Object.values(types_1.EEnvidoAnswerCommand).includes(command);
|
|
8
|
+
const filterNotEnvidoCommands = (command) => !Object.values(types_1.EEnvidoCommand).includes(command) &&
|
|
9
|
+
!Object.values(types_1.EEnvidoAnswerCommand).includes(command);
|
|
4
10
|
function Player(key, id, teamIdx, isOwner = false) {
|
|
5
11
|
const player = {
|
|
6
12
|
key,
|
|
@@ -11,31 +17,41 @@ function Player(key, id, teamIdx, isOwner = false) {
|
|
|
11
17
|
_commands: new Set(),
|
|
12
18
|
usedHand: [],
|
|
13
19
|
prevHand: [],
|
|
20
|
+
envido: [],
|
|
14
21
|
isOwner,
|
|
15
22
|
isTurn: false,
|
|
23
|
+
hasFlor: false,
|
|
24
|
+
isEnvidoTurn: false,
|
|
16
25
|
disabled: false,
|
|
17
26
|
ready: false,
|
|
18
27
|
get commands() {
|
|
19
28
|
return Array.from(player._commands.values());
|
|
20
29
|
},
|
|
21
|
-
|
|
22
|
-
player.
|
|
30
|
+
resetCommands() {
|
|
31
|
+
player._commands = new Set();
|
|
23
32
|
},
|
|
24
33
|
setTurn(turn) {
|
|
25
34
|
player.isTurn = turn;
|
|
26
35
|
},
|
|
36
|
+
setEnvidoTurn(turn) {
|
|
37
|
+
player.isTurn = turn;
|
|
38
|
+
player.isEnvidoTurn = turn;
|
|
39
|
+
},
|
|
27
40
|
getPublicPlayer() {
|
|
28
|
-
const { id, key, commands, disabled, ready, usedHand, prevHand, teamIdx, isTurn, isOwner, } = player;
|
|
41
|
+
const { id, key, commands, disabled, ready, usedHand, prevHand, teamIdx, hasFlor, isTurn, isEnvidoTurn, isOwner, envido, } = player;
|
|
29
42
|
return {
|
|
30
43
|
id,
|
|
31
44
|
key,
|
|
32
45
|
commands,
|
|
33
46
|
disabled,
|
|
34
47
|
ready,
|
|
48
|
+
envido,
|
|
35
49
|
usedHand,
|
|
36
50
|
prevHand,
|
|
37
51
|
teamIdx,
|
|
52
|
+
hasFlor,
|
|
38
53
|
isTurn,
|
|
54
|
+
isEnvidoTurn,
|
|
39
55
|
isOwner,
|
|
40
56
|
hand: player.hand.map(() => "xx"),
|
|
41
57
|
session: undefined,
|
|
@@ -53,6 +69,42 @@ function Player(key, id, teamIdx, isOwner = false) {
|
|
|
53
69
|
setReady(ready) {
|
|
54
70
|
player.ready = ready;
|
|
55
71
|
},
|
|
72
|
+
calculateEnvido() {
|
|
73
|
+
let flor = null;
|
|
74
|
+
const hand = player.hand.map((c) => {
|
|
75
|
+
let num = c.charAt(0);
|
|
76
|
+
const palo = c.charAt(1);
|
|
77
|
+
if (num === "p") {
|
|
78
|
+
num = "10";
|
|
79
|
+
}
|
|
80
|
+
if (num === "c") {
|
|
81
|
+
num = "11";
|
|
82
|
+
}
|
|
83
|
+
if (num === "r") {
|
|
84
|
+
num = "12";
|
|
85
|
+
}
|
|
86
|
+
if (flor === null || flor === palo) {
|
|
87
|
+
flor = palo;
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
flor = null;
|
|
91
|
+
}
|
|
92
|
+
return [num, palo];
|
|
93
|
+
});
|
|
94
|
+
player.hasFlor = Boolean(flor);
|
|
95
|
+
const possibles = hand.flatMap((v, i) => hand.slice(i + 1).map((w) => [v, w]));
|
|
96
|
+
const actual = possibles.filter((couple) => couple[0][1] === couple[1][1]);
|
|
97
|
+
player.envido = actual.map((couple) => {
|
|
98
|
+
const n1 = couple[0][0].at(-1);
|
|
99
|
+
const n2 = couple[1][0].at(-1);
|
|
100
|
+
return Number(n1) + Number(n2) + 20;
|
|
101
|
+
});
|
|
102
|
+
if (player.envido.length) {
|
|
103
|
+
return player.envido;
|
|
104
|
+
}
|
|
105
|
+
player.envido = Array.from(new Set(hand.map((c) => Number(c[0].at(-1)))));
|
|
106
|
+
return player.envido;
|
|
107
|
+
},
|
|
56
108
|
setHand(hand) {
|
|
57
109
|
player.prevHand = [...player.usedHand];
|
|
58
110
|
player.hand = hand;
|
|
@@ -61,10 +113,10 @@ function Player(key, id, teamIdx, isOwner = false) {
|
|
|
61
113
|
},
|
|
62
114
|
useCard(idx, card) {
|
|
63
115
|
if (player.hand[idx] && player.hand[idx] === card) {
|
|
64
|
-
const
|
|
65
|
-
player.usedHand.push(
|
|
116
|
+
const playedCard = player.hand.splice(idx, 1)[0];
|
|
117
|
+
player.usedHand.push(playedCard);
|
|
66
118
|
player.isTurn = false;
|
|
67
|
-
return
|
|
119
|
+
return playedCard;
|
|
68
120
|
}
|
|
69
121
|
return null;
|
|
70
122
|
},
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { IPlayedCard } from "./Deck";
|
|
2
2
|
import { IPlayer } from "./Player";
|
|
3
|
-
import { ITeam } from "./Team";
|
|
4
3
|
export interface ITable {
|
|
5
4
|
forehandIdx: number;
|
|
6
5
|
cards: Array<Array<IPlayedCard>>;
|
|
7
6
|
players: Array<IPlayer>;
|
|
8
7
|
nextTurn(): IPlayer;
|
|
9
|
-
|
|
10
|
-
getPlayerPosition(
|
|
8
|
+
getPlayer(idx?: number, forehandFirst?: boolean): IPlayer;
|
|
9
|
+
getPlayerPosition(key: string, forehandFirst?: boolean): number;
|
|
10
|
+
getPlayersForehandFirst(forehandIdx?: number): Array<IPlayer>;
|
|
11
11
|
}
|
|
12
|
-
export declare function Table(players: Array<IPlayer
|
|
12
|
+
export declare function Table(players: Array<IPlayer>): ITable;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Table = void 0;
|
|
4
|
-
function Table(players
|
|
4
|
+
function Table(players) {
|
|
5
5
|
const table = {
|
|
6
6
|
players,
|
|
7
7
|
cards: [],
|
|
@@ -13,16 +13,24 @@ function Table(players, teams) {
|
|
|
13
13
|
else {
|
|
14
14
|
table.forehandIdx = 0;
|
|
15
15
|
}
|
|
16
|
-
return table.
|
|
16
|
+
return table.getPlayer();
|
|
17
17
|
},
|
|
18
|
-
getPlayerPosition(
|
|
19
|
-
|
|
18
|
+
getPlayerPosition(key, forehandFirst = false) {
|
|
19
|
+
const array = forehandFirst ? table.getPlayersForehandFirst() : table.players;
|
|
20
|
+
return array.findIndex((p) => p.key === key);
|
|
20
21
|
},
|
|
21
|
-
|
|
22
|
+
getPlayersForehandFirst(forehand) {
|
|
23
|
+
const idx = forehand !== undefined ? forehand : table.forehandIdx;
|
|
24
|
+
const cut = players.slice(idx, table.players.length);
|
|
25
|
+
const end = players.slice(0, idx);
|
|
26
|
+
return cut.concat(end);
|
|
27
|
+
},
|
|
28
|
+
getPlayer(idx, forehandFirst = false) {
|
|
29
|
+
const array = forehandFirst ? table.getPlayersForehandFirst() : table.players;
|
|
22
30
|
if (idx !== undefined) {
|
|
23
|
-
return
|
|
31
|
+
return array[idx];
|
|
24
32
|
}
|
|
25
|
-
return
|
|
33
|
+
return array[0];
|
|
26
34
|
},
|
|
27
35
|
};
|
|
28
36
|
return table;
|
|
@@ -1,5 +1,11 @@
|
|
|
1
|
+
import { ECommand, ETrucoCommand } from "../../types";
|
|
1
2
|
import { IPlayer } from "./Player";
|
|
2
3
|
import { ITeam } from "./Team";
|
|
4
|
+
interface IPlayerCurrentCommands {
|
|
5
|
+
player: IPlayer;
|
|
6
|
+
add: Array<ECommand>;
|
|
7
|
+
del: Array<ECommand>;
|
|
8
|
+
}
|
|
3
9
|
export interface ITruco {
|
|
4
10
|
state: 1 | 2 | 3 | 4;
|
|
5
11
|
teamIdx: 0 | 1 | null;
|
|
@@ -8,14 +14,17 @@ export interface ITruco {
|
|
|
8
14
|
turn: number;
|
|
9
15
|
teams: [ITeam, ITeam];
|
|
10
16
|
players: Array<IPlayer>;
|
|
17
|
+
currentCommands: Array<IPlayerCurrentCommands>;
|
|
11
18
|
currentPlayer: IPlayer | null;
|
|
12
19
|
generator: Generator<ITruco, void, unknown>;
|
|
13
|
-
sayTruco(player: IPlayer
|
|
14
|
-
sayAnswer(player: IPlayer, answer: boolean | null
|
|
20
|
+
sayTruco(player: IPlayer): ITruco;
|
|
21
|
+
sayAnswer(player: IPlayer, answer: boolean | null): ITruco;
|
|
15
22
|
setTurn(turn: number): number;
|
|
16
23
|
setTeam(idx: 0 | 1): 0 | 1;
|
|
24
|
+
getNextTrucoCommand(): ETrucoCommand | null;
|
|
17
25
|
setCurrentPlayer(player: IPlayer | null): IPlayer | null;
|
|
18
26
|
getNextPlayer(): IteratorResult<ITruco, ITruco | void>;
|
|
19
27
|
reset(): void;
|
|
20
28
|
}
|
|
21
29
|
export declare function Truco(teams: [ITeam, ITeam]): ITruco;
|
|
30
|
+
export {};
|
|
@@ -10,6 +10,12 @@ const EMPTY_TRUCO = {
|
|
|
10
10
|
currentPlayer: null,
|
|
11
11
|
players: [],
|
|
12
12
|
};
|
|
13
|
+
const TRUCO_STATE_MAP = {
|
|
14
|
+
1: types_1.ETrucoCommand.TRUCO,
|
|
15
|
+
2: types_1.ETrucoCommand.RE_TRUCO,
|
|
16
|
+
3: types_1.ETrucoCommand.VALE_CUATRO,
|
|
17
|
+
4: null,
|
|
18
|
+
};
|
|
13
19
|
function Truco(teams) {
|
|
14
20
|
function* trucoAnswerGeneratorSequence() {
|
|
15
21
|
let i = 0;
|
|
@@ -30,18 +36,17 @@ function Truco(teams) {
|
|
|
30
36
|
}
|
|
31
37
|
yield truco;
|
|
32
38
|
}
|
|
33
|
-
const truco = Object.assign(Object.assign({}, EMPTY_TRUCO), { state: 1, teams, generator: trucoAnswerGeneratorSequence(),
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
player._commands.delete(types_1.ESayCommand.NO_QUIERO);
|
|
38
|
-
}));
|
|
39
|
+
const truco = Object.assign(Object.assign({}, EMPTY_TRUCO), { state: 1, teams, currentCommands: [], generator: trucoAnswerGeneratorSequence(), getNextTrucoCommand() {
|
|
40
|
+
return TRUCO_STATE_MAP[truco.state];
|
|
41
|
+
},
|
|
42
|
+
reset() {
|
|
39
43
|
Object.assign(truco, EMPTY_TRUCO);
|
|
40
44
|
},
|
|
41
|
-
sayTruco(player
|
|
45
|
+
sayTruco(player) {
|
|
42
46
|
if (truco.state === 4) {
|
|
43
47
|
return truco;
|
|
44
48
|
}
|
|
49
|
+
truco.turn = 0;
|
|
45
50
|
const playerTeamIdx = player.teamIdx;
|
|
46
51
|
const teamIdx = truco.teamIdx;
|
|
47
52
|
if (teamIdx === null || teamIdx !== playerTeamIdx) {
|
|
@@ -52,59 +57,23 @@ function Truco(teams) {
|
|
|
52
57
|
truco.answer = null;
|
|
53
58
|
truco.players = teams[opponentIdx].players;
|
|
54
59
|
truco.generator = trucoAnswerGeneratorSequence();
|
|
55
|
-
teams[playerTeamIdx].players.forEach((player) => {
|
|
56
|
-
player._commands.delete(types_1.ESayCommand.TRUCO);
|
|
57
|
-
player._commands.delete(types_1.ESayCommand.QUIERO);
|
|
58
|
-
player._commands.delete(types_1.ESayCommand.NO_QUIERO);
|
|
59
|
-
});
|
|
60
|
-
teams[opponentIdx].players.forEach((player) => {
|
|
61
|
-
if (truco.state < 4) {
|
|
62
|
-
player._commands.add(types_1.ESayCommand.TRUCO);
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
player._commands.delete(types_1.ESayCommand.TRUCO);
|
|
66
|
-
}
|
|
67
|
-
player._commands.add(types_1.ESayCommand.QUIERO);
|
|
68
|
-
player._commands.add(types_1.ESayCommand.NO_QUIERO);
|
|
69
|
-
});
|
|
70
|
-
callback();
|
|
71
60
|
return truco;
|
|
72
61
|
}
|
|
73
62
|
return truco;
|
|
74
63
|
},
|
|
75
|
-
sayAnswer(player, answer
|
|
76
|
-
const opponentIdx = Number(!player.teamIdx);
|
|
64
|
+
sayAnswer(player, answer) {
|
|
77
65
|
if (player.teamIdx === truco.teamIdx) {
|
|
78
66
|
return truco;
|
|
79
67
|
}
|
|
80
|
-
if (answer) {
|
|
81
|
-
teams[player.teamIdx].players.forEach((player) => {
|
|
82
|
-
player._commands.add(types_1.ESayCommand.TRUCO);
|
|
83
|
-
player._commands.delete(types_1.ESayCommand.NO_QUIERO);
|
|
84
|
-
player._commands.delete(types_1.ESayCommand.QUIERO);
|
|
85
|
-
if (truco.state > 3) {
|
|
86
|
-
player._commands.delete(types_1.ESayCommand.TRUCO);
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
teams[opponentIdx].players.forEach((player) => {
|
|
90
|
-
player._commands.delete(types_1.ESayCommand.TRUCO);
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
if (answer === false) {
|
|
94
|
-
truco.state--;
|
|
95
|
-
const playerTeam = teams[player.teamIdx];
|
|
96
|
-
playerTeam.players.forEach((player) => playerTeam.disable(player));
|
|
97
|
-
teams[player.teamIdx].players.forEach((player) => {
|
|
98
|
-
player._commands.delete(types_1.ESayCommand.QUIERO);
|
|
99
|
-
player._commands.delete(types_1.ESayCommand.TRUCO);
|
|
100
|
-
player._commands.delete(types_1.ESayCommand.NO_QUIERO);
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
68
|
if (answer !== null) {
|
|
69
|
+
truco.currentCommands = [];
|
|
70
|
+
if (answer === false) {
|
|
71
|
+
truco.state--;
|
|
72
|
+
const playerTeam = teams[player.teamIdx];
|
|
73
|
+
playerTeam.players.forEach((player) => playerTeam.disable(player));
|
|
74
|
+
}
|
|
104
75
|
truco.waitingAnswer = false;
|
|
105
|
-
truco.teamIdx = Number(!player.teamIdx);
|
|
106
76
|
truco.answer = answer;
|
|
107
|
-
callback();
|
|
108
77
|
}
|
|
109
78
|
return truco;
|
|
110
79
|
},
|
|
@@ -123,9 +92,6 @@ function Truco(teams) {
|
|
|
123
92
|
getNextPlayer() {
|
|
124
93
|
return truco.generator.next();
|
|
125
94
|
} });
|
|
126
|
-
teams.forEach((team) => team.players.forEach((player) => {
|
|
127
|
-
player._commands.add(types_1.ESayCommand.TRUCO);
|
|
128
|
-
}));
|
|
129
95
|
return truco;
|
|
130
96
|
}
|
|
131
97
|
exports.Truco = Truco;
|
package/dist/lib/constants.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { IEnvidoCalculator } from "../types";
|
|
2
1
|
export declare const CARDS: {
|
|
3
2
|
"1e": number;
|
|
4
3
|
"1b": number;
|
|
@@ -42,4 +41,3 @@ export declare const CARDS: {
|
|
|
42
41
|
"4c": number;
|
|
43
42
|
};
|
|
44
43
|
export declare const TEAM_SIZE_VALUES: number[];
|
|
45
|
-
export declare const EnvidoCalculator: IEnvidoCalculator;
|
package/dist/lib/constants.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const types_1 = require("../types");
|
|
5
|
-
const utils_1 = require("./utils");
|
|
3
|
+
exports.TEAM_SIZE_VALUES = exports.CARDS = void 0;
|
|
6
4
|
exports.CARDS = {
|
|
7
5
|
"1e": 14,
|
|
8
6
|
"1b": 13,
|
|
@@ -46,39 +44,3 @@ exports.CARDS = {
|
|
|
46
44
|
"4c": 0,
|
|
47
45
|
};
|
|
48
46
|
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/types.d.ts
CHANGED
|
@@ -12,7 +12,10 @@ export declare enum GAME_ERROR {
|
|
|
12
12
|
LOBBY_IS_FULL = "LOBBY_IS_FULL",
|
|
13
13
|
UNEXPECTED_TEAM_SIZE = "UNEXPECTED_TEAM_SIZE",
|
|
14
14
|
TEAM_NOT_READY = "TEAM_NOT_READY",
|
|
15
|
-
TEAM_IS_FULL = "TEAM_IS_FULL"
|
|
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"
|
|
16
19
|
}
|
|
17
20
|
export interface EnvidoState {
|
|
18
21
|
accept: number;
|
|
@@ -25,12 +28,17 @@ export type IHandCommands = {
|
|
|
25
28
|
export type IEnvidoCalculatorResult = {
|
|
26
29
|
accept: number;
|
|
27
30
|
decline: number;
|
|
31
|
+
replace?: number;
|
|
28
32
|
next: Array<ECommand>;
|
|
29
33
|
};
|
|
30
|
-
export type
|
|
34
|
+
export type IFaltaEnvidoCalculatorArgs = {
|
|
31
35
|
teams: [ITeam, ITeam];
|
|
32
36
|
matchPoint: number;
|
|
33
37
|
};
|
|
38
|
+
export type IEnvidoCalculatorArgs = {
|
|
39
|
+
stake: number;
|
|
40
|
+
declineStake: number;
|
|
41
|
+
} & (IFaltaEnvidoCalculatorArgs | never);
|
|
34
42
|
export type IEnvidoCalculator = {
|
|
35
43
|
[key in EEnvidoCommand]: (args?: IEnvidoCalculatorArgs) => IEnvidoCalculatorResult;
|
|
36
44
|
};
|
package/dist/lib/types.js
CHANGED
|
@@ -15,4 +15,7 @@ var GAME_ERROR;
|
|
|
15
15
|
GAME_ERROR["UNEXPECTED_TEAM_SIZE"] = "UNEXPECTED_TEAM_SIZE";
|
|
16
16
|
GAME_ERROR["TEAM_NOT_READY"] = "TEAM_NOT_READY";
|
|
17
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";
|
|
18
21
|
})(GAME_ERROR = exports.GAME_ERROR || (exports.GAME_ERROR = {}));
|
package/dist/types.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export interface IPublicMatch {
|
|
|
10
10
|
matchSessionId: string;
|
|
11
11
|
teams: Array<IPublicTeam>;
|
|
12
12
|
players: Array<IPublicPlayer>;
|
|
13
|
-
me: IPublicPlayer;
|
|
13
|
+
me: IPublicPlayer | null;
|
|
14
14
|
rounds: IPlayedCard[][];
|
|
15
15
|
}
|
|
16
16
|
export interface IPublicMatchInfo {
|
|
@@ -36,7 +36,7 @@ export interface IChatRoom {
|
|
|
36
36
|
messages: Array<IChatMessage>;
|
|
37
37
|
send(user: IChatMessage["user"], message: string): void;
|
|
38
38
|
system(message: string): void;
|
|
39
|
-
command(team: 0 | 1, command: ECommand): void;
|
|
39
|
+
command(team: 0 | 1, command: ECommand | number): void;
|
|
40
40
|
emit(): void;
|
|
41
41
|
}
|
|
42
42
|
export declare enum EChatSystem {
|
|
@@ -51,16 +51,26 @@ export declare enum EMatchTableState {
|
|
|
51
51
|
FINISHED = 3
|
|
52
52
|
}
|
|
53
53
|
export declare enum ESayCommand {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
MAZO = "MAZO",
|
|
54
|
+
MAZO = "MAZO"
|
|
55
|
+
}
|
|
56
|
+
export declare enum EFlorCommand {
|
|
58
57
|
FLOR = "FLOR",
|
|
59
58
|
CONTRAFLOR = "CONTRAFLOR"
|
|
60
59
|
}
|
|
60
|
+
export declare enum ETrucoCommand {
|
|
61
|
+
TRUCO = "TRUCO",
|
|
62
|
+
RE_TRUCO = "RE_TRUCO",
|
|
63
|
+
VALE_CUATRO = "VALE_CUATRO"
|
|
64
|
+
}
|
|
65
|
+
export declare enum EAnswerCommand {
|
|
66
|
+
QUIERO = "QUIERO",
|
|
67
|
+
NO_QUIERO = "NO_QUIERO"
|
|
68
|
+
}
|
|
69
|
+
export declare enum EEnvidoAnswerCommand {
|
|
70
|
+
SON_BUENAS = "SON_BUENAS"
|
|
71
|
+
}
|
|
61
72
|
export declare enum EEnvidoCommand {
|
|
62
73
|
ENVIDO = "ENVIDO",
|
|
63
|
-
ENVIDO_ENVIDO = "ENVIDO_ENVIDO",
|
|
64
74
|
REAL_ENVIDO = "REAL_ENVIDO",
|
|
65
75
|
FALTA_ENVIDO = "FALTA_ENVIDO"
|
|
66
76
|
}
|
|
@@ -68,9 +78,10 @@ export declare enum EHandState {
|
|
|
68
78
|
WAITING_PLAY = "WAITING_PLAY",
|
|
69
79
|
WAITING_FOR_TRUCO_ANSWER = "WAITING_FOR_TRUCO_ANSWER",
|
|
70
80
|
WAITING_ENVIDO_ANSWER = "WAITING_ENVIDO_ANSWER",
|
|
81
|
+
WAITING_ENVIDO_POINTS_ANSWER = "WAITING_ENVIDO_POINTS_ANSWER",
|
|
71
82
|
FINISHED = "FINISHED"
|
|
72
83
|
}
|
|
73
|
-
export type ECommand = ESayCommand | EEnvidoCommand;
|
|
84
|
+
export type ECommand = ESayCommand | EEnvidoCommand | EAnswerCommand | EEnvidoAnswerCommand | ETrucoCommand | EFlorCommand;
|
|
74
85
|
export declare enum GAME_ERROR {
|
|
75
86
|
MATCH_ALREADY_STARTED = "MATCH_ALREADY_STARTED",
|
|
76
87
|
LOBBY_IS_FULL = "LOBBY_IS_FULL",
|
|
@@ -78,11 +89,6 @@ export declare enum GAME_ERROR {
|
|
|
78
89
|
TEAM_NOT_READY = "TEAM_NOT_READY",
|
|
79
90
|
TEAM_IS_FULL = "TEAM_IS_FULL"
|
|
80
91
|
}
|
|
81
|
-
export interface EnvidoState {
|
|
82
|
-
accept: number;
|
|
83
|
-
decline: number;
|
|
84
|
-
teamIdx: 0 | 1 | null;
|
|
85
|
-
}
|
|
86
92
|
export type IHandCommands = {
|
|
87
93
|
[key in ECommand]: (player: IPlayer) => void;
|
|
88
94
|
};
|
|
@@ -132,9 +138,7 @@ export interface ClientToServerEvents {
|
|
|
132
138
|
[EClientEvent.START_MATCH]: (callback: IEventCallback<{
|
|
133
139
|
matchSessionId?: string;
|
|
134
140
|
}>) => void;
|
|
135
|
-
[EClientEvent.FETCH_MATCH]: (session: string | null, matchId: string, callback: IEventCallback
|
|
136
|
-
match?: IPublicMatch | null;
|
|
137
|
-
}>) => void;
|
|
141
|
+
[EClientEvent.FETCH_MATCH]: (session: string | null, matchId: string, callback: IEventCallback) => void;
|
|
138
142
|
[EClientEvent.LIST_MATCHES]: (filters: {
|
|
139
143
|
state?: Array<EMatchTableState>;
|
|
140
144
|
}, callback: IEventCallback<{
|
|
@@ -173,10 +177,8 @@ export type IWaitingSayData = {
|
|
|
173
177
|
command: ECommand;
|
|
174
178
|
};
|
|
175
179
|
export type IWaitingSayCallback = (data: IWaitingSayData) => void | null;
|
|
176
|
-
export interface TMap<K, V> extends Map<K, V> {
|
|
177
|
-
find(finder: (value: V) => boolean): V | void;
|
|
178
|
-
}
|
|
179
180
|
export declare class TMap<K, V> extends Map<K, V> {
|
|
181
|
+
find(finder: (value: V) => boolean): V | void;
|
|
180
182
|
findAll(finder: (value: V) => boolean): V[];
|
|
181
183
|
getOrThrow(key?: K): NonNullable<V>;
|
|
182
184
|
}
|
package/dist/types.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TMap = exports.ETrucoshiMatchState = exports.EServerEvent = exports.EClientEvent = exports.GAME_ERROR = exports.EHandState = exports.EEnvidoCommand = exports.ESayCommand = exports.EMatchTableState = exports.EChatSystem = void 0;
|
|
3
|
+
exports.TMap = exports.ETrucoshiMatchState = exports.EServerEvent = exports.EClientEvent = exports.GAME_ERROR = exports.EHandState = exports.EEnvidoCommand = exports.EEnvidoAnswerCommand = exports.EAnswerCommand = exports.ETrucoCommand = exports.EFlorCommand = exports.ESayCommand = exports.EMatchTableState = exports.EChatSystem = void 0;
|
|
4
4
|
var EChatSystem;
|
|
5
5
|
(function (EChatSystem) {
|
|
6
6
|
EChatSystem[EChatSystem["TEAM_0"] = 0] = "TEAM_0";
|
|
@@ -16,17 +16,31 @@ var EMatchTableState;
|
|
|
16
16
|
})(EMatchTableState = exports.EMatchTableState || (exports.EMatchTableState = {}));
|
|
17
17
|
var ESayCommand;
|
|
18
18
|
(function (ESayCommand) {
|
|
19
|
-
ESayCommand["QUIERO"] = "QUIERO";
|
|
20
|
-
ESayCommand["NO_QUIERO"] = "NO_QUIERO";
|
|
21
|
-
ESayCommand["TRUCO"] = "TRUCO";
|
|
22
19
|
ESayCommand["MAZO"] = "MAZO";
|
|
23
|
-
ESayCommand["FLOR"] = "FLOR";
|
|
24
|
-
ESayCommand["CONTRAFLOR"] = "CONTRAFLOR";
|
|
25
20
|
})(ESayCommand = exports.ESayCommand || (exports.ESayCommand = {}));
|
|
21
|
+
var EFlorCommand;
|
|
22
|
+
(function (EFlorCommand) {
|
|
23
|
+
EFlorCommand["FLOR"] = "FLOR";
|
|
24
|
+
EFlorCommand["CONTRAFLOR"] = "CONTRAFLOR";
|
|
25
|
+
})(EFlorCommand = exports.EFlorCommand || (exports.EFlorCommand = {}));
|
|
26
|
+
var ETrucoCommand;
|
|
27
|
+
(function (ETrucoCommand) {
|
|
28
|
+
ETrucoCommand["TRUCO"] = "TRUCO";
|
|
29
|
+
ETrucoCommand["RE_TRUCO"] = "RE_TRUCO";
|
|
30
|
+
ETrucoCommand["VALE_CUATRO"] = "VALE_CUATRO";
|
|
31
|
+
})(ETrucoCommand = exports.ETrucoCommand || (exports.ETrucoCommand = {}));
|
|
32
|
+
var EAnswerCommand;
|
|
33
|
+
(function (EAnswerCommand) {
|
|
34
|
+
EAnswerCommand["QUIERO"] = "QUIERO";
|
|
35
|
+
EAnswerCommand["NO_QUIERO"] = "NO_QUIERO";
|
|
36
|
+
})(EAnswerCommand = exports.EAnswerCommand || (exports.EAnswerCommand = {}));
|
|
37
|
+
var EEnvidoAnswerCommand;
|
|
38
|
+
(function (EEnvidoAnswerCommand) {
|
|
39
|
+
EEnvidoAnswerCommand["SON_BUENAS"] = "SON_BUENAS";
|
|
40
|
+
})(EEnvidoAnswerCommand = exports.EEnvidoAnswerCommand || (exports.EEnvidoAnswerCommand = {}));
|
|
26
41
|
var EEnvidoCommand;
|
|
27
42
|
(function (EEnvidoCommand) {
|
|
28
43
|
EEnvidoCommand["ENVIDO"] = "ENVIDO";
|
|
29
|
-
EEnvidoCommand["ENVIDO_ENVIDO"] = "ENVIDO_ENVIDO";
|
|
30
44
|
EEnvidoCommand["REAL_ENVIDO"] = "REAL_ENVIDO";
|
|
31
45
|
EEnvidoCommand["FALTA_ENVIDO"] = "FALTA_ENVIDO";
|
|
32
46
|
})(EEnvidoCommand = exports.EEnvidoCommand || (exports.EEnvidoCommand = {}));
|
|
@@ -35,6 +49,7 @@ var EHandState;
|
|
|
35
49
|
EHandState["WAITING_PLAY"] = "WAITING_PLAY";
|
|
36
50
|
EHandState["WAITING_FOR_TRUCO_ANSWER"] = "WAITING_FOR_TRUCO_ANSWER";
|
|
37
51
|
EHandState["WAITING_ENVIDO_ANSWER"] = "WAITING_ENVIDO_ANSWER";
|
|
52
|
+
EHandState["WAITING_ENVIDO_POINTS_ANSWER"] = "WAITING_ENVIDO_POINTS_ANSWER";
|
|
38
53
|
EHandState["FINISHED"] = "FINISHED";
|
|
39
54
|
})(EHandState = exports.EHandState || (exports.EHandState = {}));
|
|
40
55
|
var GAME_ERROR;
|