trucoshi 0.0.21 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/LICENSE +674 -674
  2. package/README.md +37 -37
  3. package/dist/index.d.ts +2 -0
  4. package/dist/index.js +18 -0
  5. package/dist/lib/classes/Deck.d.ts +16 -3
  6. package/dist/lib/classes/Deck.js +38 -38
  7. package/dist/lib/classes/GameLoop.d.ts +20 -0
  8. package/dist/lib/classes/GameLoop.js +103 -0
  9. package/dist/lib/classes/Hand.d.ts +38 -2
  10. package/dist/lib/classes/Hand.js +233 -233
  11. package/dist/lib/classes/Lobby.d.ts +27 -0
  12. package/dist/lib/classes/Lobby.js +114 -0
  13. package/dist/lib/classes/Match.d.ts +18 -2
  14. package/dist/lib/classes/Match.js +115 -115
  15. package/dist/lib/classes/Play.d.ts +21 -2
  16. package/dist/lib/classes/Play.js +39 -39
  17. package/dist/lib/classes/Player.d.ts +24 -3
  18. package/dist/lib/classes/Player.js +71 -67
  19. package/dist/lib/classes/Round.d.ts +17 -2
  20. package/dist/lib/classes/Round.js +34 -34
  21. package/dist/lib/classes/Table.d.ts +12 -2
  22. package/dist/lib/classes/Table.js +30 -30
  23. package/dist/lib/classes/Team.d.ts +17 -3
  24. package/dist/lib/classes/Team.js +58 -58
  25. package/dist/lib/classes/Truco.d.ts +18 -2
  26. package/dist/lib/classes/Truco.js +110 -110
  27. package/dist/lib/classes/index.d.ts +11 -0
  28. package/dist/lib/classes/index.js +27 -0
  29. package/dist/lib/constants.d.ts +45 -52
  30. package/dist/lib/constants.js +85 -93
  31. package/dist/lib/index.d.ts +2 -17
  32. package/dist/lib/index.js +18 -209
  33. package/dist/lib/types.d.ts +50 -204
  34. package/dist/lib/types.js +34 -26
  35. package/dist/lib/utils.d.ts +5 -5
  36. package/dist/lib/utils.js +59 -59
  37. package/dist/server/classes/MatchTable.d.ts +32 -30
  38. package/dist/server/classes/MatchTable.js +77 -77
  39. package/dist/server/classes/User.d.ts +5 -5
  40. package/dist/server/classes/User.js +11 -11
  41. package/dist/server/{match.d.ts → classes/index.d.ts} +0 -0
  42. package/dist/server/{match.js → classes/index.js} +1 -1
  43. package/dist/server/index.d.ts +1 -1
  44. package/dist/server/index.js +379 -391
  45. package/dist/server/types.d.ts +36 -35
  46. package/dist/server/types.js +26 -26
  47. package/dist/test/autoplay.d.ts +1 -1
  48. package/dist/test/autoplay.js +94 -94
  49. package/dist/test/play.d.ts +1 -1
  50. package/dist/test/play.js +214 -214
  51. package/dist/types.d.ts +83 -0
  52. package/dist/types.js +57 -0
  53. package/package.json +2 -2
@@ -1,35 +1,36 @@
1
- import { Socket } from "socket.io";
2
- import { ECommand, ICard } from "../lib/types";
3
- export declare enum EClientEvent {
4
- PING = "PING",
5
- PLAY = "PLAY",
6
- CREATE_MATCH = "CREATE_MATCH",
7
- GET_MATCH = "GET_MATCH",
8
- JOIN_MATCH = "JOIN_MATCH",
9
- START_MATCH = "START_MATCH",
10
- SET_PLAYER_READY = "SET_PLAYER_READY",
11
- SET_SESSION = "SET_SESSION"
12
- }
13
- export declare enum EServerEvent {
14
- PONG = "PONG",
15
- UPDATE_MATCH = "UPDATE_MATCH",
16
- WAITING_PLAY = "WAITING_PLAY"
17
- }
18
- export interface TrucoshiSocket extends Socket {
19
- session?: string;
20
- }
21
- export declare enum ETrucoshiMatchState {
22
- UNREADY = 0,
23
- STARTED = 1,
24
- FINISHED = 2
25
- }
26
- export type IWaitingPlayData = {
27
- cardIdx: number;
28
- card: ICard;
29
- command?: undefined;
30
- } | {
31
- cardIdx?: undefined;
32
- card?: undefined;
33
- command: ECommand;
34
- };
35
- export type IWaitingPlayCallback = (data: IWaitingPlayData) => void | null;
1
+ import { Socket } from "socket.io";
2
+ import { ICard } from "../lib";
3
+ import { ECommand } from "../lib/types";
4
+ export declare enum EClientEvent {
5
+ PING = "PING",
6
+ PLAY = "PLAY",
7
+ CREATE_MATCH = "CREATE_MATCH",
8
+ GET_MATCH = "GET_MATCH",
9
+ JOIN_MATCH = "JOIN_MATCH",
10
+ START_MATCH = "START_MATCH",
11
+ SET_PLAYER_READY = "SET_PLAYER_READY",
12
+ SET_SESSION = "SET_SESSION"
13
+ }
14
+ export declare enum EServerEvent {
15
+ PONG = "PONG",
16
+ UPDATE_MATCH = "UPDATE_MATCH",
17
+ WAITING_PLAY = "WAITING_PLAY"
18
+ }
19
+ export interface TrucoshiSocket extends Socket {
20
+ session?: string;
21
+ }
22
+ export declare enum ETrucoshiMatchState {
23
+ UNREADY = 0,
24
+ STARTED = 1,
25
+ FINISHED = 2
26
+ }
27
+ export type IWaitingPlayData = {
28
+ cardIdx: number;
29
+ card: ICard;
30
+ command?: undefined;
31
+ } | {
32
+ cardIdx?: undefined;
33
+ card?: undefined;
34
+ command: ECommand;
35
+ };
36
+ export type IWaitingPlayCallback = (data: IWaitingPlayData) => void | null;
@@ -1,26 +1,26 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ETrucoshiMatchState = exports.EServerEvent = exports.EClientEvent = void 0;
4
- var EClientEvent;
5
- (function (EClientEvent) {
6
- EClientEvent["PING"] = "PING";
7
- EClientEvent["PLAY"] = "PLAY";
8
- EClientEvent["CREATE_MATCH"] = "CREATE_MATCH";
9
- EClientEvent["GET_MATCH"] = "GET_MATCH";
10
- EClientEvent["JOIN_MATCH"] = "JOIN_MATCH";
11
- EClientEvent["START_MATCH"] = "START_MATCH";
12
- EClientEvent["SET_PLAYER_READY"] = "SET_PLAYER_READY";
13
- EClientEvent["SET_SESSION"] = "SET_SESSION";
14
- })(EClientEvent = exports.EClientEvent || (exports.EClientEvent = {}));
15
- var EServerEvent;
16
- (function (EServerEvent) {
17
- EServerEvent["PONG"] = "PONG";
18
- EServerEvent["UPDATE_MATCH"] = "UPDATE_MATCH";
19
- EServerEvent["WAITING_PLAY"] = "WAITING_PLAY";
20
- })(EServerEvent = exports.EServerEvent || (exports.EServerEvent = {}));
21
- var ETrucoshiMatchState;
22
- (function (ETrucoshiMatchState) {
23
- ETrucoshiMatchState[ETrucoshiMatchState["UNREADY"] = 0] = "UNREADY";
24
- ETrucoshiMatchState[ETrucoshiMatchState["STARTED"] = 1] = "STARTED";
25
- ETrucoshiMatchState[ETrucoshiMatchState["FINISHED"] = 2] = "FINISHED";
26
- })(ETrucoshiMatchState = exports.ETrucoshiMatchState || (exports.ETrucoshiMatchState = {}));
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ETrucoshiMatchState = exports.EServerEvent = exports.EClientEvent = void 0;
4
+ var EClientEvent;
5
+ (function (EClientEvent) {
6
+ EClientEvent["PING"] = "PING";
7
+ EClientEvent["PLAY"] = "PLAY";
8
+ EClientEvent["CREATE_MATCH"] = "CREATE_MATCH";
9
+ EClientEvent["GET_MATCH"] = "GET_MATCH";
10
+ EClientEvent["JOIN_MATCH"] = "JOIN_MATCH";
11
+ EClientEvent["START_MATCH"] = "START_MATCH";
12
+ EClientEvent["SET_PLAYER_READY"] = "SET_PLAYER_READY";
13
+ EClientEvent["SET_SESSION"] = "SET_SESSION";
14
+ })(EClientEvent = exports.EClientEvent || (exports.EClientEvent = {}));
15
+ var EServerEvent;
16
+ (function (EServerEvent) {
17
+ EServerEvent["PONG"] = "PONG";
18
+ EServerEvent["UPDATE_MATCH"] = "UPDATE_MATCH";
19
+ EServerEvent["WAITING_PLAY"] = "WAITING_PLAY";
20
+ })(EServerEvent = exports.EServerEvent || (exports.EServerEvent = {}));
21
+ var ETrucoshiMatchState;
22
+ (function (ETrucoshiMatchState) {
23
+ ETrucoshiMatchState[ETrucoshiMatchState["UNREADY"] = 0] = "UNREADY";
24
+ ETrucoshiMatchState[ETrucoshiMatchState["STARTED"] = 1] = "STARTED";
25
+ ETrucoshiMatchState[ETrucoshiMatchState["FINISHED"] = 2] = "FINISHED";
26
+ })(ETrucoshiMatchState = exports.ETrucoshiMatchState || (exports.ETrucoshiMatchState = {}));
@@ -1 +1 @@
1
- export {};
1
+ export {};
@@ -1,94 +1,94 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- var lib_1 = require("../lib");
40
- (function () { return __awaiter(void 0, void 0, void 0, function () {
41
- var trucoshi;
42
- return __generator(this, function (_a) {
43
- trucoshi = (0, lib_1.Lobby)();
44
- trucoshi.addPlayer("lukini", "lukini").setReady(true);
45
- trucoshi.addPlayer("denoph", "denoph").setReady(true);
46
- trucoshi.addPlayer("guada", "guada").setReady(true);
47
- trucoshi.addPlayer("juli", "juli").setReady(true);
48
- trucoshi.addPlayer("day", "day").setReady(true);
49
- trucoshi.addPlayer("fran", "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, play.player.hand[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();
92
- return [2 /*return*/];
93
- });
94
- }); })();
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ var lib_1 = require("../lib");
40
+ (function () { return __awaiter(void 0, void 0, void 0, function () {
41
+ var trucoshi;
42
+ return __generator(this, function (_a) {
43
+ trucoshi = (0, lib_1.Lobby)();
44
+ trucoshi.addPlayer("lukini", "lukini").setReady(true);
45
+ trucoshi.addPlayer("denoph", "denoph").setReady(true);
46
+ trucoshi.addPlayer("guada", "guada").setReady(true);
47
+ trucoshi.addPlayer("juli", "juli").setReady(true);
48
+ trucoshi.addPlayer("day", "day").setReady(true);
49
+ trucoshi.addPlayer("fran", "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, play.player.hand[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();
92
+ return [2 /*return*/];
93
+ });
94
+ }); })();
@@ -1 +1 @@
1
- export {};
1
+ export {};