trucoshi 0.0.2 → 0.0.5
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/.prettierrc.json +4 -0
- package/LICENSE +674 -0
- package/README.md +37 -0
- package/build/lib/classes/Deck.d.ts +2 -0
- package/build/lib/classes/Deck.js +27 -0
- package/build/lib/classes/Hand.d.ts +2 -0
- package/build/lib/classes/Hand.js +233 -0
- package/build/lib/classes/Match.d.ts +2 -0
- package/build/lib/classes/Match.js +115 -0
- package/build/lib/classes/Play.d.ts +2 -0
- package/build/lib/classes/Play.js +39 -0
- package/build/lib/classes/Player.d.ts +2 -0
- package/build/lib/classes/Player.js +38 -0
- package/build/lib/classes/Round.d.ts +2 -0
- package/build/lib/classes/Round.js +33 -0
- package/build/lib/classes/Table.d.ts +2 -0
- package/build/lib/classes/Table.js +30 -0
- package/build/lib/classes/Team.d.ts +2 -0
- package/build/lib/classes/Team.js +42 -0
- package/build/lib/classes/Truco.d.ts +2 -0
- package/build/lib/classes/Truco.js +110 -0
- package/build/lib/constants.d.ts +36 -28
- package/build/lib/constants.js +97 -12
- package/build/lib/index.d.ts +18 -0
- package/build/lib/index.js +161 -0
- package/build/lib/types.d.ts +121 -30
- package/build/lib/types.js +24 -12
- package/build/lib/utils.d.ts +3 -3
- package/build/lib/utils.js +11 -18
- package/build/server/index.js +13 -5
- package/build/server/match.d.ts +0 -0
- package/build/server/match.js +1 -0
- package/build/server/types.d.ts +11 -0
- package/build/server/types.js +15 -0
- package/build/test/autoplay.js +52 -31
- package/build/test/play.js +146 -81
- package/package.json +5 -4
- package/src/lib/classes/Deck.ts +25 -0
- package/src/lib/classes/Hand.ts +207 -0
- package/src/lib/classes/Match.ts +79 -0
- package/src/lib/classes/Play.ts +40 -0
- package/src/lib/classes/Player.ts +37 -0
- package/src/lib/classes/Round.ts +30 -0
- package/src/lib/classes/Table.ts +32 -0
- package/src/lib/classes/Team.ts +41 -0
- package/src/lib/classes/Truco.ts +72 -0
- package/src/lib/constants.ts +105 -11
- package/src/lib/index.ts +135 -0
- package/src/lib/types.ts +186 -80
- package/src/lib/utils.ts +50 -53
- package/src/server/index.ts +34 -22
- package/src/server/match.ts +0 -0
- package/src/server/types.ts +12 -0
- package/src/test/autoplay.ts +57 -41
- package/src/test/play.ts +122 -70
- package/build/lib/trucoshi.d.ts +0 -10
- package/build/lib/trucoshi.js +0 -363
- package/build/test/legacy.d.ts +0 -1
- package/build/test/legacy.js +0 -146
- package/src/lib/trucoshi.ts +0 -342
- package/src/test/legacy.ts +0 -68
package/build/lib/types.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { IGameLoop } from ".";
|
|
1
2
|
import { CARDS } from "./constants";
|
|
2
3
|
export type ICard = keyof typeof CARDS;
|
|
3
4
|
export interface IDeck {
|
|
@@ -14,16 +15,23 @@ export interface IPlayer {
|
|
|
14
15
|
teamIdx: number;
|
|
15
16
|
id: string;
|
|
16
17
|
hand: Array<ICard>;
|
|
18
|
+
commands: Array<ECommand>;
|
|
17
19
|
usedHand: Array<ICard>;
|
|
20
|
+
disabled: boolean;
|
|
21
|
+
ready: boolean;
|
|
22
|
+
enable(): void;
|
|
23
|
+
disable(): void;
|
|
24
|
+
setReady(ready: boolean): void;
|
|
18
25
|
setHand(hand: Array<ICard>): Array<ICard>;
|
|
19
26
|
useCard(idx: number): ICard | null;
|
|
20
27
|
}
|
|
21
28
|
export interface ITeam {
|
|
22
|
-
color: string;
|
|
23
29
|
_players: Map<string, IPlayer>;
|
|
24
30
|
players: Array<IPlayer>;
|
|
25
|
-
points:
|
|
26
|
-
|
|
31
|
+
points: TeamPoints;
|
|
32
|
+
isTeamDisabled(): boolean;
|
|
33
|
+
disable(player: IPlayer): boolean;
|
|
34
|
+
addPoints(matchPoint: number, points: number): TeamPoints;
|
|
27
35
|
}
|
|
28
36
|
export interface IMatch {
|
|
29
37
|
teams: [ITeam, ITeam];
|
|
@@ -31,59 +39,128 @@ export interface IMatch {
|
|
|
31
39
|
winner: ITeam | null;
|
|
32
40
|
currentHand: IHand | null;
|
|
33
41
|
table: ITable;
|
|
34
|
-
play(): IPlayInstance |
|
|
35
|
-
addPoints(points:
|
|
42
|
+
play(): IPlayInstance | null;
|
|
43
|
+
addPoints(points: HandPoints): [ITeam, ITeam];
|
|
36
44
|
pushHand(hand: IHand): void;
|
|
37
45
|
setCurrentHand(hand: IHand | null): IHand | null;
|
|
38
46
|
setWinner(winner: ITeam): void;
|
|
39
47
|
getNextTurn(): IteratorResult<IMatch | null, IMatch | null | void>;
|
|
40
48
|
}
|
|
41
|
-
export
|
|
49
|
+
export interface TeamPoints {
|
|
50
|
+
buenas: number;
|
|
51
|
+
malas: number;
|
|
52
|
+
winner: boolean;
|
|
53
|
+
}
|
|
54
|
+
export interface HandPoints {
|
|
42
55
|
0: number;
|
|
43
56
|
1: number;
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
}
|
|
58
|
+
export interface RoundPoints {
|
|
59
|
+
0: number;
|
|
60
|
+
1: number;
|
|
61
|
+
ties: number;
|
|
62
|
+
}
|
|
63
|
+
export declare enum ESayCommand {
|
|
64
|
+
QUIERO = "QUIERO",
|
|
65
|
+
NO_QUIERO = "NO_QUIERO",
|
|
66
|
+
TRUCO = "TRUCO",
|
|
67
|
+
MAZO = "MAZO",
|
|
68
|
+
FLOR = "FLOR",
|
|
69
|
+
CONTRAFLOR = "CONTRAFLOR"
|
|
70
|
+
}
|
|
71
|
+
export declare enum EEnvidoCommand {
|
|
72
|
+
ENVIDO = "ENVIDO",
|
|
73
|
+
ENVIDO_ENVIDO = "ENVIDO_ENVIDO",
|
|
74
|
+
REAL_ENVIDO = "REAL_ENVIDO",
|
|
75
|
+
FALTA_ENVIDO = "FALTA_ENVIDO"
|
|
76
|
+
}
|
|
77
|
+
export type ECommand = ESayCommand | EEnvidoCommand;
|
|
78
|
+
export interface ITruco {
|
|
79
|
+
state: 1 | 2 | 3 | 4;
|
|
80
|
+
teamIdx: 0 | 1 | null;
|
|
81
|
+
answer: boolean | null;
|
|
82
|
+
turn: number;
|
|
83
|
+
players: Array<IPlayer>;
|
|
84
|
+
currentPlayer: IPlayer | null;
|
|
85
|
+
generator: Generator<ITruco, void, unknown>;
|
|
86
|
+
sayTruco(teamIdx: 0 | 1, players: Array<IPlayer>): ITruco;
|
|
87
|
+
setPlayers(players: Array<IPlayer>): void;
|
|
88
|
+
setAnswer(answer: boolean | null): ITruco;
|
|
89
|
+
setTurn(turn: number): number;
|
|
90
|
+
setTeam(idx: 0 | 1): 0 | 1;
|
|
91
|
+
setCurrentPlayer(player: IPlayer | null): IPlayer | null;
|
|
92
|
+
getNextPlayer(): IteratorResult<ITruco, ITruco | void>;
|
|
93
|
+
}
|
|
94
|
+
export interface EnvidoState {
|
|
95
|
+
accept: number;
|
|
96
|
+
decline: number;
|
|
97
|
+
teamIdx: 0 | 1 | null;
|
|
60
98
|
}
|
|
61
99
|
export interface IPlayInstance {
|
|
100
|
+
teams: [ITeam, ITeam];
|
|
62
101
|
handIdx: number;
|
|
63
102
|
roundIdx: number;
|
|
103
|
+
state: EHandState;
|
|
104
|
+
truco: ITruco;
|
|
105
|
+
envido: EnvidoState;
|
|
64
106
|
player: IPlayer | null;
|
|
65
|
-
commands: Array<
|
|
107
|
+
commands: Array<ECommand> | null;
|
|
66
108
|
rounds: Array<IRound> | null;
|
|
67
109
|
use(idx: number): ICard | null;
|
|
68
|
-
say(command:
|
|
110
|
+
say(command: ECommand): ECommand | null;
|
|
111
|
+
}
|
|
112
|
+
export declare enum EHandState {
|
|
113
|
+
WAITING_PLAY = "WAITING_PLAY",
|
|
114
|
+
WAITING_FOR_TRUCO_ANSWER = "WAITING_FOR_TRUCO_ANSWER",
|
|
115
|
+
WAITING_ENVIDO_ANSWER = "WAITING_ENVIDO_ANSWER",
|
|
116
|
+
FINISHED = "FINISHED"
|
|
69
117
|
}
|
|
118
|
+
export type IHandCommands = {
|
|
119
|
+
[key in ECommand]: (player: IPlayer) => void;
|
|
120
|
+
};
|
|
70
121
|
export interface IHand {
|
|
71
122
|
idx: number;
|
|
123
|
+
state: EHandState;
|
|
72
124
|
turn: number;
|
|
73
|
-
|
|
74
|
-
|
|
125
|
+
points: HandPoints;
|
|
126
|
+
truco: ITruco;
|
|
127
|
+
envido: EnvidoState;
|
|
75
128
|
rounds: Array<IRound>;
|
|
76
|
-
|
|
129
|
+
_currentPlayer: IPlayer | null;
|
|
130
|
+
get currentPlayer(): IPlayer | null;
|
|
131
|
+
set currentPlayer(player: IPlayer | null);
|
|
77
132
|
currentRound: IRound | null;
|
|
78
|
-
|
|
133
|
+
commands: IHandCommands;
|
|
134
|
+
finished: () => boolean;
|
|
135
|
+
play(): IPlayInstance | null;
|
|
136
|
+
nextTurn(): void;
|
|
137
|
+
use(idx: number): ICard | null;
|
|
79
138
|
pushRound(round: IRound): IRound;
|
|
80
139
|
setTurn(turn: number): IPlayer;
|
|
81
140
|
addPoints(team: 0 | 1, points: number): void;
|
|
141
|
+
disablePlayer(player: IPlayer): void;
|
|
82
142
|
setCurrentRound(round: IRound | null): IRound | null;
|
|
83
143
|
setCurrentPlayer(player: IPlayer | null): IPlayer | null;
|
|
84
|
-
|
|
144
|
+
setState(state: EHandState): EHandState;
|
|
85
145
|
getNextPlayer(): IteratorResult<IHand, IHand | void>;
|
|
86
146
|
}
|
|
147
|
+
export interface IPrivateTrucoshi {
|
|
148
|
+
lastTeamIdx: 0 | 1;
|
|
149
|
+
_players: Map<string, IPlayer>;
|
|
150
|
+
get players(): Array<IPlayer>;
|
|
151
|
+
teams: Array<ITeam>;
|
|
152
|
+
maxPlayers: number;
|
|
153
|
+
table: ITable | null;
|
|
154
|
+
ready: boolean;
|
|
155
|
+
full: boolean;
|
|
156
|
+
addPlayer(id: string, teamIdx?: 0 | 1): IPlayer;
|
|
157
|
+
removePlayer(id: string): ITrucoshi;
|
|
158
|
+
calculateReady(): boolean;
|
|
159
|
+
calculateFull(): boolean;
|
|
160
|
+
startMatch(matchPoint?: 9 | 12 | 15): IGameLoop;
|
|
161
|
+
}
|
|
162
|
+
export interface ITrucoshi extends Pick<IPrivateTrucoshi, 'addPlayer' | 'removePlayer' | 'startMatch'> {
|
|
163
|
+
}
|
|
87
164
|
export interface ITable {
|
|
88
165
|
forehandIdx: number;
|
|
89
166
|
cards: Array<Array<IPlayedCard>>;
|
|
@@ -97,5 +174,19 @@ export interface IRound {
|
|
|
97
174
|
winner: IPlayer | null;
|
|
98
175
|
highest: number;
|
|
99
176
|
cards: Array<IPlayedCard>;
|
|
100
|
-
|
|
177
|
+
turn: number;
|
|
178
|
+
nextTurn(): void;
|
|
179
|
+
use(playedCard: IPlayedCard): ICard;
|
|
101
180
|
}
|
|
181
|
+
export type IEnvidoCalculatorResult = {
|
|
182
|
+
accept: number;
|
|
183
|
+
decline: number;
|
|
184
|
+
next: Array<ECommand>;
|
|
185
|
+
};
|
|
186
|
+
export type IEnvidoCalculatorArgs = {
|
|
187
|
+
teams: [ITeam, ITeam];
|
|
188
|
+
matchPoint: number;
|
|
189
|
+
};
|
|
190
|
+
export type IEnvidoCalculator = {
|
|
191
|
+
[key in EEnvidoCommand]: (args?: IEnvidoCalculatorArgs) => IEnvidoCalculatorResult;
|
|
192
|
+
};
|
package/build/lib/types.js
CHANGED
|
@@ -1,14 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
var
|
|
5
|
-
(function (
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
3
|
+
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 = {}));
|
package/build/lib/utils.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ICard, IRound
|
|
1
|
+
import { ICard, IRound } from "./types";
|
|
2
|
+
export declare function getMaxNumberIndex<T = number>(array: Array<T>): number;
|
|
2
3
|
export declare function getCardValue(card: ICard): number;
|
|
3
|
-
export declare function shuffleArray<T =
|
|
4
|
+
export declare function shuffleArray<T = unknown>(array: Array<T>): T[];
|
|
4
5
|
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;
|
package/build/lib/utils.js
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.checkHandWinner = exports.shuffleArray = exports.getCardValue = exports.getMaxNumberIndex = void 0;
|
|
4
4
|
var constants_1 = require("./constants");
|
|
5
|
+
function getMaxNumberIndex(array) {
|
|
6
|
+
return array.reduce(function (accumulator, current, index) {
|
|
7
|
+
return current > array[accumulator] ? index : accumulator;
|
|
8
|
+
}, 0);
|
|
9
|
+
}
|
|
10
|
+
exports.getMaxNumberIndex = getMaxNumberIndex;
|
|
5
11
|
function getCardValue(card) {
|
|
6
12
|
return constants_1.CARDS[card] || -1;
|
|
7
13
|
}
|
|
@@ -12,9 +18,7 @@ function shuffleArray(array) {
|
|
|
12
18
|
while (currentIndex != 0) {
|
|
13
19
|
randomIndex = Math.floor(Math.random() * currentIndex);
|
|
14
20
|
currentIndex--;
|
|
15
|
-
_a = [
|
|
16
|
-
array[randomIndex], array[currentIndex]
|
|
17
|
-
], array[currentIndex] = _a[0], array[randomIndex] = _a[1];
|
|
21
|
+
_a = [array[randomIndex], array[currentIndex]], array[currentIndex] = _a[0], array[randomIndex] = _a[1];
|
|
18
22
|
}
|
|
19
23
|
return array;
|
|
20
24
|
}
|
|
@@ -24,14 +28,14 @@ function checkHandWinner(rounds, forehandTeamIdx) {
|
|
|
24
28
|
var roundsWon = {
|
|
25
29
|
0: 0,
|
|
26
30
|
1: 0,
|
|
27
|
-
|
|
31
|
+
ties: 0,
|
|
28
32
|
};
|
|
29
33
|
for (var i = 0; i < rounds.length; i++) {
|
|
30
34
|
var round = rounds[i];
|
|
31
35
|
if (round.tie) {
|
|
32
36
|
roundsWon[0] += 1;
|
|
33
37
|
roundsWon[1] += 1;
|
|
34
|
-
roundsWon
|
|
38
|
+
roundsWon.ties = roundsWon.ties + 1;
|
|
35
39
|
continue;
|
|
36
40
|
}
|
|
37
41
|
if (((_a = round.winner) === null || _a === void 0 ? void 0 : _a.teamIdx) === 0) {
|
|
@@ -41,8 +45,7 @@ function checkHandWinner(rounds, forehandTeamIdx) {
|
|
|
41
45
|
roundsWon[1] += 1;
|
|
42
46
|
}
|
|
43
47
|
}
|
|
44
|
-
|
|
45
|
-
if ((roundsWon[0] > 2 && roundsWon[1] > 2) || (rounds.length > 2 && ties > 0)) {
|
|
48
|
+
if ((roundsWon[0] > 2 && roundsWon[1] > 2) || (rounds.length > 2 && roundsWon.ties > 0)) {
|
|
46
49
|
return forehandTeamIdx;
|
|
47
50
|
}
|
|
48
51
|
if (roundsWon[0] >= 2 && roundsWon[1] < 2) {
|
|
@@ -54,13 +57,3 @@ function checkHandWinner(rounds, forehandTeamIdx) {
|
|
|
54
57
|
return null;
|
|
55
58
|
}
|
|
56
59
|
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;
|
package/build/server/index.js
CHANGED
|
@@ -2,18 +2,26 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
var http_1 = require("http");
|
|
4
4
|
var socket_io_1 = require("socket.io");
|
|
5
|
+
var types_1 = require("./types");
|
|
5
6
|
var PORT = 4001;
|
|
6
7
|
var httpServer = (0, http_1.createServer)();
|
|
7
8
|
var io = new socket_io_1.Server(httpServer, {
|
|
8
9
|
cors: {
|
|
9
10
|
origin: "http://localhost:3000",
|
|
10
|
-
methods: ["GET", "POST"]
|
|
11
|
-
}
|
|
11
|
+
methods: ["GET", "POST"],
|
|
12
|
+
},
|
|
12
13
|
});
|
|
14
|
+
var sessions = new Map();
|
|
13
15
|
io.on("connection", function (socket) {
|
|
14
|
-
socket.on(
|
|
15
|
-
io.emit(
|
|
16
|
+
socket.on(types_1.EClientEvent.PING, function (msg) {
|
|
17
|
+
io.emit(types_1.EServerEvent.PONG, msg);
|
|
18
|
+
});
|
|
19
|
+
socket.on(types_1.EClientEvent.CREATE_MATCH, function (msg) {
|
|
20
|
+
});
|
|
21
|
+
socket.on(types_1.EClientEvent.SET_PLAYER_ID, function (msg) {
|
|
22
|
+
if (typeof msg === 'string' && msg.length < 32) {
|
|
23
|
+
}
|
|
16
24
|
});
|
|
17
25
|
});
|
|
18
26
|
httpServer.listen(PORT);
|
|
19
|
-
console.log(
|
|
27
|
+
console.log("Listening on port", PORT);
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
package/build/server/types.d.ts
CHANGED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare enum EClientEvent {
|
|
2
|
+
PING = "PING",
|
|
3
|
+
CREATE_MATCH = "CREATE_MATCH",
|
|
4
|
+
JOIN_MATCH = "JOIN_MATCH",
|
|
5
|
+
START_MATCH = "START_MATCH",
|
|
6
|
+
SET_PLAYER_ID = "SET_PLAYER_ID"
|
|
7
|
+
}
|
|
8
|
+
export declare enum EServerEvent {
|
|
9
|
+
SET_SESSION_ID = "SET_SESSION_ID",
|
|
10
|
+
PONG = "PONG"
|
|
11
|
+
}
|
package/build/server/types.js
CHANGED
|
@@ -1 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EServerEvent = exports.EClientEvent = void 0;
|
|
4
|
+
var EClientEvent;
|
|
5
|
+
(function (EClientEvent) {
|
|
6
|
+
EClientEvent["PING"] = "PING";
|
|
7
|
+
EClientEvent["CREATE_MATCH"] = "CREATE_MATCH";
|
|
8
|
+
EClientEvent["JOIN_MATCH"] = "JOIN_MATCH";
|
|
9
|
+
EClientEvent["START_MATCH"] = "START_MATCH";
|
|
10
|
+
EClientEvent["SET_PLAYER_ID"] = "SET_PLAYER_ID";
|
|
11
|
+
})(EClientEvent = exports.EClientEvent || (exports.EClientEvent = {}));
|
|
12
|
+
var EServerEvent;
|
|
13
|
+
(function (EServerEvent) {
|
|
14
|
+
EServerEvent["SET_SESSION_ID"] = "SET_SESSION_ID";
|
|
15
|
+
EServerEvent["PONG"] = "PONG";
|
|
16
|
+
})(EServerEvent = exports.EServerEvent || (exports.EServerEvent = {}));
|
package/build/test/autoplay.js
CHANGED
|
@@ -36,38 +36,59 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
var
|
|
40
|
-
var trucoshi_1 = require("../lib/trucoshi");
|
|
39
|
+
var lib_1 = require("../lib");
|
|
41
40
|
(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
42
|
-
var
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
41
|
+
var trucoshi;
|
|
42
|
+
return __generator(this, function (_a) {
|
|
43
|
+
trucoshi = (0, lib_1.Trucoshi)();
|
|
44
|
+
trucoshi.addPlayer("lukini").setReady(true);
|
|
45
|
+
trucoshi.addPlayer("denoph").setReady(true);
|
|
46
|
+
trucoshi.addPlayer("guada").setReady(true);
|
|
47
|
+
trucoshi.addPlayer("juli").setReady(true);
|
|
48
|
+
trucoshi.addPlayer("day").setReady(true);
|
|
49
|
+
trucoshi.addPlayer("fran").setReady(true);
|
|
50
|
+
trucoshi
|
|
51
|
+
.startMatch()
|
|
52
|
+
.onTurn(function (play) { return __awaiter(void 0, void 0, void 0, function () {
|
|
53
|
+
var name, randomIdx, handString, card;
|
|
54
|
+
var _a;
|
|
55
|
+
return __generator(this, function (_b) {
|
|
56
|
+
if (!play.player) {
|
|
57
|
+
return [2 /*return*/];
|
|
58
|
+
}
|
|
59
|
+
name = (_a = play.player) === null || _a === void 0 ? void 0 : _a.id.toUpperCase();
|
|
60
|
+
console.log("=== Mano ".concat(play.handIdx, " === Ronda ").concat(play.roundIdx, " === Turno de ").concat(name, " ==="));
|
|
61
|
+
play.teams.map(function (team, id) {
|
|
62
|
+
return console.log("=== Team ".concat(id, " = ").concat(team.points.malas, " malas ").concat(team.points.buenas, " buenas ==="));
|
|
63
|
+
});
|
|
64
|
+
console.log(play.rounds && play.rounds.length
|
|
65
|
+
? play.rounds.map(function (round) {
|
|
66
|
+
return round.cards.length ? round.cards.map(function (c) { return [c.player.id, c.card]; }) : "";
|
|
67
|
+
})
|
|
68
|
+
: "");
|
|
69
|
+
randomIdx = Math.round(Math.random() * (play.player.hand.length - 1));
|
|
70
|
+
handString = JSON.stringify(play.player.hand);
|
|
71
|
+
card = play.use(randomIdx);
|
|
72
|
+
console.log("\n".concat(handString, "\nUsing ").concat(card));
|
|
73
|
+
console.log(play.rounds && play.rounds.length
|
|
74
|
+
? play.rounds.map(function (round) {
|
|
75
|
+
return round.cards.length ? round.cards.map(function (c) { return [c.player.id, c.card]; }) : "";
|
|
76
|
+
})
|
|
77
|
+
: "");
|
|
78
|
+
return [2 /*return*/];
|
|
79
|
+
});
|
|
80
|
+
}); })
|
|
81
|
+
.onWinner(function (winner, teams) { return __awaiter(void 0, void 0, void 0, function () {
|
|
82
|
+
return __generator(this, function (_a) {
|
|
83
|
+
console.log("\n");
|
|
84
|
+
teams.map(function (t, i) {
|
|
85
|
+
return console.log("Equipo ".concat(i, ": ").concat(t.players.map(function (p) { return " ".concat(p.id); }), " === ").concat(t.points.malas, " malas ").concat(t.points.buenas, " buenas"));
|
|
86
|
+
});
|
|
87
|
+
console.log("\nEquipo Ganador:".concat(winner.players.map(function (p) { return " ".concat(p.id); })));
|
|
88
|
+
return [2 /*return*/];
|
|
89
|
+
});
|
|
90
|
+
}); })
|
|
91
|
+
.begin();
|
|
71
92
|
return [2 /*return*/];
|
|
72
93
|
});
|
|
73
94
|
}); })();
|