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.
Files changed (61) hide show
  1. package/.prettierrc.json +4 -0
  2. package/LICENSE +674 -0
  3. package/README.md +37 -0
  4. package/build/lib/classes/Deck.d.ts +2 -0
  5. package/build/lib/classes/Deck.js +27 -0
  6. package/build/lib/classes/Hand.d.ts +2 -0
  7. package/build/lib/classes/Hand.js +233 -0
  8. package/build/lib/classes/Match.d.ts +2 -0
  9. package/build/lib/classes/Match.js +115 -0
  10. package/build/lib/classes/Play.d.ts +2 -0
  11. package/build/lib/classes/Play.js +39 -0
  12. package/build/lib/classes/Player.d.ts +2 -0
  13. package/build/lib/classes/Player.js +38 -0
  14. package/build/lib/classes/Round.d.ts +2 -0
  15. package/build/lib/classes/Round.js +33 -0
  16. package/build/lib/classes/Table.d.ts +2 -0
  17. package/build/lib/classes/Table.js +30 -0
  18. package/build/lib/classes/Team.d.ts +2 -0
  19. package/build/lib/classes/Team.js +42 -0
  20. package/build/lib/classes/Truco.d.ts +2 -0
  21. package/build/lib/classes/Truco.js +110 -0
  22. package/build/lib/constants.d.ts +36 -28
  23. package/build/lib/constants.js +97 -12
  24. package/build/lib/index.d.ts +18 -0
  25. package/build/lib/index.js +161 -0
  26. package/build/lib/types.d.ts +121 -30
  27. package/build/lib/types.js +24 -12
  28. package/build/lib/utils.d.ts +3 -3
  29. package/build/lib/utils.js +11 -18
  30. package/build/server/index.js +13 -5
  31. package/build/server/match.d.ts +0 -0
  32. package/build/server/match.js +1 -0
  33. package/build/server/types.d.ts +11 -0
  34. package/build/server/types.js +15 -0
  35. package/build/test/autoplay.js +52 -31
  36. package/build/test/play.js +146 -81
  37. package/package.json +5 -4
  38. package/src/lib/classes/Deck.ts +25 -0
  39. package/src/lib/classes/Hand.ts +207 -0
  40. package/src/lib/classes/Match.ts +79 -0
  41. package/src/lib/classes/Play.ts +40 -0
  42. package/src/lib/classes/Player.ts +37 -0
  43. package/src/lib/classes/Round.ts +30 -0
  44. package/src/lib/classes/Table.ts +32 -0
  45. package/src/lib/classes/Team.ts +41 -0
  46. package/src/lib/classes/Truco.ts +72 -0
  47. package/src/lib/constants.ts +105 -11
  48. package/src/lib/index.ts +135 -0
  49. package/src/lib/types.ts +186 -80
  50. package/src/lib/utils.ts +50 -53
  51. package/src/server/index.ts +34 -22
  52. package/src/server/match.ts +0 -0
  53. package/src/server/types.ts +12 -0
  54. package/src/test/autoplay.ts +57 -41
  55. package/src/test/play.ts +122 -70
  56. package/build/lib/trucoshi.d.ts +0 -10
  57. package/build/lib/trucoshi.js +0 -363
  58. package/build/test/legacy.d.ts +0 -1
  59. package/build/test/legacy.js +0 -146
  60. package/src/lib/trucoshi.ts +0 -342
  61. package/src/test/legacy.ts +0 -68
@@ -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: number;
26
- addPoints(points: number): number;
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 | undefined;
35
- addPoints(points: IPoints): void;
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 type IPoints = {
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
- 2?: number;
45
- };
46
- export type IGetNextPlayerResult = {
47
- currentPlayer?: IPlayer;
48
- currentRound?: IRound;
49
- points?: IPoints;
50
- };
51
- export declare enum EHandPlayCommand {
52
- TRUCO = 0,
53
- ENVIDO = 1,
54
- ENVIDO_ENVIDO = 2,
55
- REAL_ENVIDO = 3,
56
- FALTA_ENVIDO = 4,
57
- MAZO = 5,
58
- FLOR = 6,
59
- CONTRAFLOR = 7
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<EHandPlayCommand> | null;
107
+ commands: Array<ECommand> | null;
66
108
  rounds: Array<IRound> | null;
67
109
  use(idx: number): ICard | null;
68
- say(command: EHandPlayCommand): IHand | null;
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
- finished: boolean;
74
- points: IPoints;
125
+ points: HandPoints;
126
+ truco: ITruco;
127
+ envido: EnvidoState;
75
128
  rounds: Array<IRound>;
76
- currentPlayer: IPlayer | null;
129
+ _currentPlayer: IPlayer | null;
130
+ get currentPlayer(): IPlayer | null;
131
+ set currentPlayer(player: IPlayer | null);
77
132
  currentRound: IRound | null;
78
- play(): IPlayInstance;
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
- setFinished(finshed: boolean): boolean;
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
- play(playedCard: IPlayedCard): ICard;
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
+ };
@@ -1,14 +1,26 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EHandPlayCommand = void 0;
4
- var EHandPlayCommand;
5
- (function (EHandPlayCommand) {
6
- EHandPlayCommand[EHandPlayCommand["TRUCO"] = 0] = "TRUCO";
7
- EHandPlayCommand[EHandPlayCommand["ENVIDO"] = 1] = "ENVIDO";
8
- EHandPlayCommand[EHandPlayCommand["ENVIDO_ENVIDO"] = 2] = "ENVIDO_ENVIDO";
9
- EHandPlayCommand[EHandPlayCommand["REAL_ENVIDO"] = 3] = "REAL_ENVIDO";
10
- EHandPlayCommand[EHandPlayCommand["FALTA_ENVIDO"] = 4] = "FALTA_ENVIDO";
11
- EHandPlayCommand[EHandPlayCommand["MAZO"] = 5] = "MAZO";
12
- EHandPlayCommand[EHandPlayCommand["FLOR"] = 6] = "FLOR";
13
- EHandPlayCommand[EHandPlayCommand["CONTRAFLOR"] = 7] = "CONTRAFLOR";
14
- })(EHandPlayCommand = exports.EHandPlayCommand || (exports.EHandPlayCommand = {}));
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 = {}));
@@ -1,5 +1,5 @@
1
- import { ICard, IRound, ITeam } from "./types";
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 = never>(array: Array<T>): 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;
@@ -1,7 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.checkMatchWinner = exports.checkHandWinner = exports.shuffleArray = exports.getCardValue = void 0;
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
- 2: 0 // tied rounds
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[2] = (roundsWon[2] || 0) + 1;
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
- var ties = roundsWon[2] || 0;
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;
@@ -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('ping', function (msg) {
15
- io.emit('pong', msg);
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('Listening on port', PORT);
27
+ console.log("Listening on port", PORT);
File without changes
@@ -0,0 +1 @@
1
+ "use strict";
@@ -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
+ }
@@ -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 = {}));
@@ -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 constants_1 = require("../lib/constants");
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 player1, player2, player3, player4, player5, player6, team1, team2, match, play, name, randomIdx, card;
43
- var _a;
44
- return __generator(this, function (_b) {
45
- player1 = (0, trucoshi_1.Player)('lukini', 0);
46
- player2 = (0, trucoshi_1.Player)('guada', 0);
47
- player3 = (0, trucoshi_1.Player)('denoph', 1);
48
- player4 = (0, trucoshi_1.Player)('juli', 1);
49
- player5 = (0, trucoshi_1.Player)('fran', 1);
50
- player6 = (0, trucoshi_1.Player)('day', 0);
51
- team1 = (0, trucoshi_1.Team)(constants_1.COLORS[0], [player1, player2, player6]);
52
- team2 = (0, trucoshi_1.Team)(constants_1.COLORS[1], [player3, player4, player5]);
53
- match = (0, trucoshi_1.Match)([team1, team2], 9);
54
- while (!match.winner) {
55
- play = match.play();
56
- if (!play || !play.player) {
57
- break;
58
- }
59
- name = play.player.id.toUpperCase();
60
- console.log("=== Mano ".concat(play.handIdx, " === Ronda ").concat(play.roundIdx, " === Turno de ").concat(name, " ==="));
61
- match.teams.map(function (team, id) { return console.log("=== Team ".concat(id, " = ").concat(team.points, " Puntos ===")); });
62
- console.log(play.rounds && play.rounds.length ? (play.rounds.map(function (round) { return round.cards.length ? round.cards.map(function (c) { return [c.player.id, c.card]; }) : ''; })) : '');
63
- randomIdx = Math.round(Math.random() * (play.player.hand.length - 1));
64
- card = play.use(randomIdx);
65
- console.log("\n".concat(JSON.stringify(play.player.hand), "\nUsing ").concat(card));
66
- console.log(play.rounds && play.rounds.length ? (play.rounds.map(function (round) { return round.cards.length ? round.cards.map(function (c) { return [c.player.id, c.card]; }) : ''; })) : '');
67
- }
68
- console.log('\n');
69
- match.teams.map(function (t, i) { return console.log("Equipo ".concat(i, ": ").concat(t.players.map(function (p) { return " ".concat(p.id); }), " === ").concat(t.points, " puntos")); });
70
- console.log("\nEquipo Ganador:".concat((_a = match.winner) === null || _a === void 0 ? void 0 : _a.players.map(function (p) { return " ".concat(p.id); })));
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
  }); })();