trucoshi 0.0.22 → 0.1.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 +37 -37
- package/dist/index.d.ts +2 -0
- package/dist/index.js +18 -0
- package/dist/lib/classes/Deck.d.ts +16 -3
- package/dist/lib/classes/Deck.js +38 -38
- package/dist/lib/classes/GameLoop.d.ts +20 -0
- package/dist/lib/classes/GameLoop.js +103 -0
- package/dist/lib/classes/Hand.d.ts +38 -2
- package/dist/lib/classes/Hand.js +233 -233
- package/dist/lib/classes/Lobby.d.ts +27 -0
- package/dist/lib/classes/Lobby.js +114 -0
- package/dist/lib/classes/Match.d.ts +18 -2
- package/dist/lib/classes/Match.js +115 -115
- package/dist/lib/classes/Play.d.ts +21 -2
- package/dist/lib/classes/Play.js +39 -39
- package/dist/lib/classes/Player.d.ts +24 -3
- package/dist/lib/classes/Player.js +71 -71
- package/dist/lib/classes/Round.d.ts +17 -2
- package/dist/lib/classes/Round.js +34 -34
- package/dist/lib/classes/Table.d.ts +12 -2
- package/dist/lib/classes/Table.js +30 -30
- package/dist/lib/classes/Team.d.ts +17 -3
- package/dist/lib/classes/Team.js +58 -58
- package/dist/lib/classes/Truco.d.ts +18 -2
- package/dist/lib/classes/Truco.js +110 -110
- package/dist/lib/classes/index.d.ts +11 -0
- package/dist/lib/classes/index.js +27 -0
- package/dist/lib/constants.d.ts +45 -52
- package/dist/lib/constants.js +85 -93
- package/dist/lib/index.d.ts +2 -17
- package/dist/lib/index.js +18 -211
- package/dist/lib/types.d.ts +50 -206
- package/dist/lib/types.js +34 -26
- package/dist/lib/utils.d.ts +5 -5
- package/dist/lib/utils.js +59 -59
- package/dist/server/classes/MatchTable.d.ts +32 -30
- package/dist/server/classes/MatchTable.js +77 -77
- package/dist/server/classes/User.d.ts +5 -5
- package/dist/server/classes/User.js +11 -11
- package/dist/server/{match.d.ts → classes/index.d.ts} +0 -0
- package/dist/server/{match.js → classes/index.js} +1 -1
- package/dist/server/index.d.ts +1 -1
- package/dist/server/index.js +379 -391
- package/dist/server/types.d.ts +36 -35
- package/dist/server/types.js +26 -26
- package/dist/test/autoplay.d.ts +1 -1
- package/dist/test/autoplay.js +94 -94
- package/dist/test/play.d.ts +1 -1
- package/dist/test/play.js +214 -214
- package/dist/types.d.ts +83 -0
- package/dist/types.js +57 -0
- package/package.json +5 -2
package/README.md
CHANGED
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
# Trucoshi
|
|
2
|
-
|
|
3
|
-
### English
|
|
4
|
-
Pretends to be an Argentinian Truco game socket server that allows you to put Satoshis on the table ;)
|
|
5
|
-
|
|
6
|
-
### Spanish
|
|
7
|
-
Pretende ser un server basado en sockets del juego de Truco Argentino que te permita poner unos Satoshis en la mesa ;)
|
|
8
|
-
|
|
9
|
-
# Test
|
|
10
|
-
Right now there's only a local CLI way of playing as there is no socket server implementation and its just the game logic.
|
|
11
|
-
|
|
12
|
-
### Installation
|
|
13
|
-
`yarn`
|
|
14
|
-
|
|
15
|
-
### Play
|
|
16
|
-
`yarn test:play`
|
|
17
|
-
|
|
18
|
-
### Autoplay
|
|
19
|
-
`yarn test:autoplay`
|
|
20
|
-
|
|
21
|
-
# Todo
|
|
22
|
-
[x] Logica de turnos, rondas y battalla de cartas
|
|
23
|
-
[x] Irse al mazo
|
|
24
|
-
[] Cantar truco
|
|
25
|
-
[] Cantar envido
|
|
26
|
-
[] Cantar flor
|
|
27
|
-
[] Socket server
|
|
28
|
-
[] Bitcoin Lightning integration
|
|
29
|
-
[] Unit tests
|
|
30
|
-
|
|
31
|
-
# License
|
|
32
|
-
|
|
33
|
-
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
|
34
|
-
|
|
35
|
-
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
36
|
-
|
|
37
|
-
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
1
|
+
# Trucoshi
|
|
2
|
+
|
|
3
|
+
### English
|
|
4
|
+
Pretends to be an Argentinian Truco game socket server that allows you to put Satoshis on the table ;)
|
|
5
|
+
|
|
6
|
+
### Spanish
|
|
7
|
+
Pretende ser un server basado en sockets del juego de Truco Argentino que te permita poner unos Satoshis en la mesa ;)
|
|
8
|
+
|
|
9
|
+
# Test
|
|
10
|
+
Right now there's only a local CLI way of playing as there is no socket server implementation and its just the game logic.
|
|
11
|
+
|
|
12
|
+
### Installation
|
|
13
|
+
`yarn`
|
|
14
|
+
|
|
15
|
+
### Play
|
|
16
|
+
`yarn test:play`
|
|
17
|
+
|
|
18
|
+
### Autoplay
|
|
19
|
+
`yarn test:autoplay`
|
|
20
|
+
|
|
21
|
+
# Todo
|
|
22
|
+
[x] Logica de turnos, rondas y battalla de cartas
|
|
23
|
+
[x] Irse al mazo
|
|
24
|
+
[] Cantar truco
|
|
25
|
+
[] Cantar envido
|
|
26
|
+
[] Cantar flor
|
|
27
|
+
[] Socket server
|
|
28
|
+
[] Bitcoin Lightning integration
|
|
29
|
+
[] Unit tests
|
|
30
|
+
|
|
31
|
+
# License
|
|
32
|
+
|
|
33
|
+
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
|
34
|
+
|
|
35
|
+
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
36
|
+
|
|
37
|
+
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +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("./lib"), exports);
|
|
18
|
+
__exportStar(require("./types"), exports);
|
|
@@ -1,3 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export
|
|
1
|
+
import { CARDS } from "../constants";
|
|
2
|
+
import { IPlayer, IPublicPlayer } from "./Player";
|
|
3
|
+
export interface IDeck {
|
|
4
|
+
cards: Array<ICard>;
|
|
5
|
+
usedCards: Array<ICard>;
|
|
6
|
+
takeCard(): ICard;
|
|
7
|
+
shuffle(): IDeck;
|
|
8
|
+
}
|
|
9
|
+
export type ICard = keyof typeof CARDS;
|
|
10
|
+
export interface IPlayedCard {
|
|
11
|
+
get key(): string;
|
|
12
|
+
player: IPlayer & IPublicPlayer;
|
|
13
|
+
card: ICard;
|
|
14
|
+
}
|
|
15
|
+
export declare function Deck(): IDeck;
|
|
16
|
+
export declare function PlayedCard(player: IPlayer, card: ICard): IPlayedCard;
|
package/dist/lib/classes/Deck.js
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PlayedCard = exports.Deck = void 0;
|
|
4
|
-
var constants_1 = require("../constants");
|
|
5
|
-
var utils_1 = require("../utils");
|
|
6
|
-
function Deck() {
|
|
7
|
-
var deck = {
|
|
8
|
-
cards: Object.keys(constants_1.CARDS),
|
|
9
|
-
usedCards: [],
|
|
10
|
-
takeCard: function () {
|
|
11
|
-
var card = deck.cards.shift();
|
|
12
|
-
deck.usedCards.push(card);
|
|
13
|
-
return card;
|
|
14
|
-
},
|
|
15
|
-
shuffle: function () {
|
|
16
|
-
deck.cards = deck.cards.concat(deck.usedCards);
|
|
17
|
-
deck.usedCards = [];
|
|
18
|
-
deck.cards = (0, utils_1.shuffleArray)(deck.cards);
|
|
19
|
-
if (deck.cards.length !== 40) {
|
|
20
|
-
throw new Error("This is not good");
|
|
21
|
-
}
|
|
22
|
-
return deck;
|
|
23
|
-
},
|
|
24
|
-
};
|
|
25
|
-
return deck;
|
|
26
|
-
}
|
|
27
|
-
exports.Deck = Deck;
|
|
28
|
-
function PlayedCard(player, card) {
|
|
29
|
-
var pc = {
|
|
30
|
-
player: player,
|
|
31
|
-
card: card,
|
|
32
|
-
get key() {
|
|
33
|
-
return card + player.session;
|
|
34
|
-
},
|
|
35
|
-
};
|
|
36
|
-
return pc;
|
|
37
|
-
}
|
|
38
|
-
exports.PlayedCard = PlayedCard;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PlayedCard = exports.Deck = void 0;
|
|
4
|
+
var constants_1 = require("../constants");
|
|
5
|
+
var utils_1 = require("../utils");
|
|
6
|
+
function Deck() {
|
|
7
|
+
var deck = {
|
|
8
|
+
cards: Object.keys(constants_1.CARDS),
|
|
9
|
+
usedCards: [],
|
|
10
|
+
takeCard: function () {
|
|
11
|
+
var card = deck.cards.shift();
|
|
12
|
+
deck.usedCards.push(card);
|
|
13
|
+
return card;
|
|
14
|
+
},
|
|
15
|
+
shuffle: function () {
|
|
16
|
+
deck.cards = deck.cards.concat(deck.usedCards);
|
|
17
|
+
deck.usedCards = [];
|
|
18
|
+
deck.cards = (0, utils_1.shuffleArray)(deck.cards);
|
|
19
|
+
if (deck.cards.length !== 40) {
|
|
20
|
+
throw new Error("This is not good");
|
|
21
|
+
}
|
|
22
|
+
return deck;
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
return deck;
|
|
26
|
+
}
|
|
27
|
+
exports.Deck = Deck;
|
|
28
|
+
function PlayedCard(player, card) {
|
|
29
|
+
var pc = {
|
|
30
|
+
player: player,
|
|
31
|
+
card: card,
|
|
32
|
+
get key() {
|
|
33
|
+
return card + player.session;
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
return pc;
|
|
37
|
+
}
|
|
38
|
+
exports.PlayedCard = PlayedCard;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { IHand } from "./Hand";
|
|
2
|
+
import { IMatch } from "./Match";
|
|
3
|
+
import { IPlayInstance } from "./Play";
|
|
4
|
+
import { ITeam } from "./Team";
|
|
5
|
+
export type IWinnerCallback = (winner: ITeam, teams: [ITeam, ITeam]) => Promise<void>;
|
|
6
|
+
export type ITurnCallback = (play: IPlayInstance) => Promise<void>;
|
|
7
|
+
export type ITrucoCallback = (play: IPlayInstance) => Promise<void>;
|
|
8
|
+
export interface IGameLoop {
|
|
9
|
+
_onTruco: ITrucoCallback;
|
|
10
|
+
_onTurn: ITurnCallback;
|
|
11
|
+
_onWinner: IWinnerCallback;
|
|
12
|
+
teams: Array<ITeam>;
|
|
13
|
+
hands: Array<IHand>;
|
|
14
|
+
winner: ITeam | null;
|
|
15
|
+
onTurn: (callback: ITurnCallback) => IGameLoop;
|
|
16
|
+
onWinner: (callback: IWinnerCallback) => IGameLoop;
|
|
17
|
+
onTruco: (callback: ITrucoCallback) => IGameLoop;
|
|
18
|
+
begin: () => Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
export declare const GameLoop: (match: IMatch) => IGameLoop;
|
|
@@ -0,0 +1,103 @@
|
|
|
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
|
+
exports.GameLoop = void 0;
|
|
40
|
+
var types_1 = require("../../types");
|
|
41
|
+
var GameLoop = function (match) {
|
|
42
|
+
var gameloop = {
|
|
43
|
+
_onTruco: function () { return Promise.resolve(); },
|
|
44
|
+
_onTurn: function () { return Promise.resolve(); },
|
|
45
|
+
_onWinner: function () { return Promise.resolve(); },
|
|
46
|
+
teams: [],
|
|
47
|
+
winner: null,
|
|
48
|
+
hands: [],
|
|
49
|
+
onTruco: function (callback) {
|
|
50
|
+
gameloop._onTruco = callback;
|
|
51
|
+
return gameloop;
|
|
52
|
+
},
|
|
53
|
+
onTurn: function (callback) {
|
|
54
|
+
gameloop._onTurn = callback;
|
|
55
|
+
return gameloop;
|
|
56
|
+
},
|
|
57
|
+
onWinner: function (callback) {
|
|
58
|
+
gameloop._onWinner = callback;
|
|
59
|
+
return gameloop;
|
|
60
|
+
},
|
|
61
|
+
begin: function () {
|
|
62
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
63
|
+
var play;
|
|
64
|
+
return __generator(this, function (_a) {
|
|
65
|
+
switch (_a.label) {
|
|
66
|
+
case 0:
|
|
67
|
+
gameloop.teams = match.teams;
|
|
68
|
+
_a.label = 1;
|
|
69
|
+
case 1:
|
|
70
|
+
if (!!match.winner) return [3 /*break*/, 6];
|
|
71
|
+
play = match.play();
|
|
72
|
+
gameloop.hands = match.hands;
|
|
73
|
+
if (!play || !play.player) {
|
|
74
|
+
return [3 /*break*/, 1];
|
|
75
|
+
}
|
|
76
|
+
if (!(play.state === types_1.EHandState.WAITING_FOR_TRUCO_ANSWER)) return [3 /*break*/, 3];
|
|
77
|
+
return [4 /*yield*/, gameloop._onTruco(play)];
|
|
78
|
+
case 2:
|
|
79
|
+
_a.sent();
|
|
80
|
+
return [3 /*break*/, 1];
|
|
81
|
+
case 3:
|
|
82
|
+
if (!(play.state === types_1.EHandState.WAITING_PLAY)) return [3 /*break*/, 5];
|
|
83
|
+
play.player.setTurn(true);
|
|
84
|
+
return [4 /*yield*/, gameloop._onTurn(play)];
|
|
85
|
+
case 4:
|
|
86
|
+
_a.sent();
|
|
87
|
+
play.player.setTurn(false);
|
|
88
|
+
return [3 /*break*/, 1];
|
|
89
|
+
case 5: return [3 /*break*/, 1];
|
|
90
|
+
case 6:
|
|
91
|
+
gameloop.winner = match.winner;
|
|
92
|
+
return [4 /*yield*/, gameloop._onWinner(match.winner, match.teams)];
|
|
93
|
+
case 7:
|
|
94
|
+
_a.sent();
|
|
95
|
+
return [2 /*return*/];
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
return gameloop;
|
|
102
|
+
};
|
|
103
|
+
exports.GameLoop = GameLoop;
|
|
@@ -1,2 +1,38 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { EHandState, EnvidoState, IHandCommands } from "../../types";
|
|
2
|
+
import { ICard, IDeck } from "./Deck";
|
|
3
|
+
import { IMatch } from "./Match";
|
|
4
|
+
import { IPlayInstance } from "./Play";
|
|
5
|
+
import { IPlayer } from "./Player";
|
|
6
|
+
import { IRound } from "./Round";
|
|
7
|
+
import { ITruco } from "./Truco";
|
|
8
|
+
export interface IHandPoints {
|
|
9
|
+
0: number;
|
|
10
|
+
1: number;
|
|
11
|
+
}
|
|
12
|
+
export interface IHand {
|
|
13
|
+
idx: number;
|
|
14
|
+
state: EHandState;
|
|
15
|
+
turn: number;
|
|
16
|
+
points: IHandPoints;
|
|
17
|
+
truco: ITruco;
|
|
18
|
+
envido: EnvidoState;
|
|
19
|
+
rounds: Array<IRound>;
|
|
20
|
+
_currentPlayer: IPlayer | null;
|
|
21
|
+
get currentPlayer(): IPlayer | null;
|
|
22
|
+
set currentPlayer(player: IPlayer | null);
|
|
23
|
+
currentRound: IRound | null;
|
|
24
|
+
commands: IHandCommands;
|
|
25
|
+
finished: () => boolean;
|
|
26
|
+
play(): IPlayInstance | null;
|
|
27
|
+
nextTurn(): void;
|
|
28
|
+
use(idx: number, card: ICard): ICard | null;
|
|
29
|
+
pushRound(round: IRound): IRound;
|
|
30
|
+
setTurn(turn: number): IPlayer;
|
|
31
|
+
addPoints(team: 0 | 1, points: number): void;
|
|
32
|
+
disablePlayer(player: IPlayer): void;
|
|
33
|
+
setCurrentRound(round: IRound | null): IRound | null;
|
|
34
|
+
setCurrentPlayer(player: IPlayer | null): IPlayer | null;
|
|
35
|
+
setState(state: EHandState): EHandState;
|
|
36
|
+
getNextPlayer(): IteratorResult<IHand, IHand | void>;
|
|
37
|
+
}
|
|
38
|
+
export declare function Hand(match: IMatch, deck: IDeck, idx: number): IHand;
|