trucoshi 0.3.3 → 0.3.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/LICENSE +674 -674
- package/README.md +60 -60
- package/dist/index.d.ts +2 -2
- package/dist/index.js +18 -18
- package/dist/lib/classes/Deck.d.ts +17 -17
- package/dist/lib/classes/Deck.js +41 -41
- package/dist/lib/classes/Envido.d.ts +34 -0
- package/dist/lib/classes/Envido.js +168 -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 +26 -23
- package/dist/lib/classes/GameLoop.js +106 -78
- package/dist/lib/classes/Hand.d.ts +43 -39
- package/dist/lib/classes/Hand.js +295 -197
- package/dist/lib/classes/Lobby.d.ts +27 -27
- package/dist/lib/classes/Lobby.js +113 -113
- package/dist/lib/classes/Match.d.ts +21 -20
- package/dist/lib/classes/Match.js +88 -87
- package/dist/lib/classes/Play.d.ts +22 -21
- package/dist/lib/classes/Play.js +44 -29
- package/dist/lib/classes/Player.d.ts +35 -30
- package/dist/lib/classes/Player.js +126 -74
- package/dist/lib/classes/Round.d.ts +17 -17
- package/dist/lib/classes/Round.js +33 -33
- package/dist/lib/classes/Table.d.ts +12 -12
- package/dist/lib/classes/Table.js +38 -30
- package/dist/lib/classes/Team.d.ts +20 -20
- package/dist/lib/classes/Team.js +59 -59
- package/dist/lib/classes/Truco.d.ts +30 -21
- package/dist/lib/classes/Truco.js +97 -131
- package/dist/lib/classes/index.d.ts +11 -11
- package/dist/lib/classes/index.js +27 -27
- package/dist/lib/constants.d.ts +43 -45
- package/dist/lib/constants.js +46 -84
- package/dist/lib/index.d.ts +2 -2
- package/dist/lib/index.js +18 -18
- package/dist/lib/types.d.ts +44 -36
- package/dist/lib/types.js +21 -18
- package/dist/lib/utils.d.ts +5 -5
- package/dist/lib/utils.js +58 -58
- package/dist/types.d.ts +193 -182
- package/dist/types.js +123 -106
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,60 +1,60 @@
|
|
|
1
|
-
# Trucoshi
|
|
2
|
-
|
|
3
|
-
### English
|
|
4
|
-
|
|
5
|
-
Work in progress
|
|
6
|
-
|
|
7
|
-
Pretends to be an Argentinian Truco game socket server that allows you to put Satoshis on the table ;)
|
|
8
|
-
|
|
9
|
-
Try current demo at [Trucoshi](https://trucoshi.com)
|
|
10
|
-
|
|
11
|
-
### Spanish
|
|
12
|
-
|
|
13
|
-
En construccion
|
|
14
|
-
|
|
15
|
-
Pretende ser un server basado en sockets del juego de Truco Argentino que te permita poner unos Satoshis en la mesa ;)
|
|
16
|
-
|
|
17
|
-
Proba la demo actual en [Trucoshi](https://trucoshi.com)
|
|
18
|
-
|
|
19
|
-
# Test
|
|
20
|
-
|
|
21
|
-
Right now there's only a local CLI way of playing as there is no socket server implementation and its just the game logic.
|
|
22
|
-
|
|
23
|
-
### Installation
|
|
24
|
-
|
|
25
|
-
`yarn`
|
|
26
|
-
|
|
27
|
-
### Build
|
|
28
|
-
|
|
29
|
-
`yarn build`
|
|
30
|
-
|
|
31
|
-
### Play
|
|
32
|
-
|
|
33
|
-
`yarn test:play`
|
|
34
|
-
|
|
35
|
-
### Autoplay
|
|
36
|
-
|
|
37
|
-
`yarn test:autoplay`
|
|
38
|
-
|
|
39
|
-
# Todo
|
|
40
|
-
|
|
41
|
-
[x] Logica de turnos, rondas y battalla de cartas
|
|
42
|
-
[x] Irse al mazo
|
|
43
|
-
[x] Cantar truco
|
|
44
|
-
[] Cantar envido
|
|
45
|
-
[] Cantar flor
|
|
46
|
-
[x] Socket server
|
|
47
|
-
[-] Unit tests
|
|
48
|
-
[] Bitcoin Lightning integration
|
|
49
|
-
|
|
50
|
-
# Donations
|
|
51
|
-
|
|
52
|
-
Donate Bitcoin at [jfrader.com](https://jfrader.com)
|
|
53
|
-
|
|
54
|
-
# License
|
|
55
|
-
|
|
56
|
-
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.
|
|
57
|
-
|
|
58
|
-
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.
|
|
59
|
-
|
|
60
|
-
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
|
+
|
|
5
|
+
Work in progress
|
|
6
|
+
|
|
7
|
+
Pretends to be an Argentinian Truco game socket server that allows you to put Satoshis on the table ;)
|
|
8
|
+
|
|
9
|
+
Try current demo at [Trucoshi](https://trucoshi.com)
|
|
10
|
+
|
|
11
|
+
### Spanish
|
|
12
|
+
|
|
13
|
+
En construccion
|
|
14
|
+
|
|
15
|
+
Pretende ser un server basado en sockets del juego de Truco Argentino que te permita poner unos Satoshis en la mesa ;)
|
|
16
|
+
|
|
17
|
+
Proba la demo actual en [Trucoshi](https://trucoshi.com)
|
|
18
|
+
|
|
19
|
+
# Test
|
|
20
|
+
|
|
21
|
+
Right now there's only a local CLI way of playing as there is no socket server implementation and its just the game logic.
|
|
22
|
+
|
|
23
|
+
### Installation
|
|
24
|
+
|
|
25
|
+
`yarn`
|
|
26
|
+
|
|
27
|
+
### Build
|
|
28
|
+
|
|
29
|
+
`yarn build`
|
|
30
|
+
|
|
31
|
+
### Play
|
|
32
|
+
|
|
33
|
+
`yarn test:play`
|
|
34
|
+
|
|
35
|
+
### Autoplay
|
|
36
|
+
|
|
37
|
+
`yarn test:autoplay`
|
|
38
|
+
|
|
39
|
+
# Todo
|
|
40
|
+
|
|
41
|
+
[x] Logica de turnos, rondas y battalla de cartas
|
|
42
|
+
[x] Irse al mazo
|
|
43
|
+
[x] Cantar truco
|
|
44
|
+
[] Cantar envido
|
|
45
|
+
[] Cantar flor
|
|
46
|
+
[x] Socket server
|
|
47
|
+
[-] Unit tests
|
|
48
|
+
[] Bitcoin Lightning integration
|
|
49
|
+
|
|
50
|
+
# Donations
|
|
51
|
+
|
|
52
|
+
Donate Bitcoin at [jfrader.com](https://jfrader.com)
|
|
53
|
+
|
|
54
|
+
# License
|
|
55
|
+
|
|
56
|
+
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.
|
|
57
|
+
|
|
58
|
+
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.
|
|
59
|
+
|
|
60
|
+
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
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from "./lib";
|
|
2
|
-
export * from "./types";
|
|
1
|
+
export * from "./lib";
|
|
2
|
+
export * from "./types";
|
package/dist/index.js
CHANGED
|
@@ -1,18 +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
|
+
"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,17 +1,17 @@
|
|
|
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
|
-
takeThree(): [ICard, ICard, ICard];
|
|
8
|
-
shuffle(): IDeck;
|
|
9
|
-
}
|
|
10
|
-
export type ICard = keyof typeof CARDS;
|
|
11
|
-
export interface IPlayedCard {
|
|
12
|
-
get key(): string;
|
|
13
|
-
player: IPlayer
|
|
14
|
-
card: ICard;
|
|
15
|
-
}
|
|
16
|
-
export declare function Deck(): IDeck;
|
|
17
|
-
export declare function PlayedCard(player: IPlayer, card: ICard): IPlayedCard;
|
|
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
|
+
takeThree(): [ICard, ICard, ICard];
|
|
8
|
+
shuffle(): IDeck;
|
|
9
|
+
}
|
|
10
|
+
export type ICard = keyof typeof CARDS;
|
|
11
|
+
export interface IPlayedCard {
|
|
12
|
+
get key(): string;
|
|
13
|
+
player: IPlayer | IPublicPlayer;
|
|
14
|
+
card: ICard;
|
|
15
|
+
}
|
|
16
|
+
export declare function Deck(): IDeck;
|
|
17
|
+
export declare function PlayedCard(player: IPlayer | IPublicPlayer, card: ICard): IPlayedCard;
|
package/dist/lib/classes/Deck.js
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PlayedCard = exports.Deck = void 0;
|
|
4
|
-
const constants_1 = require("../constants");
|
|
5
|
-
const utils_1 = require("../utils");
|
|
6
|
-
function Deck() {
|
|
7
|
-
const deck = {
|
|
8
|
-
cards: Object.keys(constants_1.CARDS),
|
|
9
|
-
usedCards: [],
|
|
10
|
-
takeCard() {
|
|
11
|
-
const card = deck.cards.shift();
|
|
12
|
-
deck.usedCards.push(card);
|
|
13
|
-
return card;
|
|
14
|
-
},
|
|
15
|
-
takeThree() {
|
|
16
|
-
return [deck.takeCard(), deck.takeCard(), deck.takeCard()];
|
|
17
|
-
},
|
|
18
|
-
shuffle() {
|
|
19
|
-
deck.cards = deck.cards.concat(deck.usedCards);
|
|
20
|
-
deck.usedCards = [];
|
|
21
|
-
deck.cards = (0, utils_1.shuffleArray)(deck.cards);
|
|
22
|
-
if (deck.cards.length !== 40) {
|
|
23
|
-
throw new Error("This is not good");
|
|
24
|
-
}
|
|
25
|
-
return deck;
|
|
26
|
-
},
|
|
27
|
-
};
|
|
28
|
-
return deck;
|
|
29
|
-
}
|
|
30
|
-
exports.Deck = Deck;
|
|
31
|
-
function PlayedCard(player, card) {
|
|
32
|
-
const pc = {
|
|
33
|
-
player,
|
|
34
|
-
card,
|
|
35
|
-
get key() {
|
|
36
|
-
return card + player.key;
|
|
37
|
-
},
|
|
38
|
-
};
|
|
39
|
-
return pc;
|
|
40
|
-
}
|
|
41
|
-
exports.PlayedCard = PlayedCard;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PlayedCard = exports.Deck = void 0;
|
|
4
|
+
const constants_1 = require("../constants");
|
|
5
|
+
const utils_1 = require("../utils");
|
|
6
|
+
function Deck() {
|
|
7
|
+
const deck = {
|
|
8
|
+
cards: Object.keys(constants_1.CARDS),
|
|
9
|
+
usedCards: [],
|
|
10
|
+
takeCard() {
|
|
11
|
+
const card = deck.cards.shift();
|
|
12
|
+
deck.usedCards.push(card);
|
|
13
|
+
return card;
|
|
14
|
+
},
|
|
15
|
+
takeThree() {
|
|
16
|
+
return [deck.takeCard(), deck.takeCard(), deck.takeCard()];
|
|
17
|
+
},
|
|
18
|
+
shuffle() {
|
|
19
|
+
deck.cards = deck.cards.concat(deck.usedCards);
|
|
20
|
+
deck.usedCards = [];
|
|
21
|
+
deck.cards = (0, utils_1.shuffleArray)(deck.cards);
|
|
22
|
+
if (deck.cards.length !== 40) {
|
|
23
|
+
throw new Error("This is not good");
|
|
24
|
+
}
|
|
25
|
+
return deck;
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
return deck;
|
|
29
|
+
}
|
|
30
|
+
exports.Deck = Deck;
|
|
31
|
+
function PlayedCard(player, card) {
|
|
32
|
+
const pc = {
|
|
33
|
+
player,
|
|
34
|
+
card,
|
|
35
|
+
get key() {
|
|
36
|
+
return card + player.key;
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
return pc;
|
|
40
|
+
}
|
|
41
|
+
exports.PlayedCard = PlayedCard;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { ECommand, EEnvidoCommand } from "../../types";
|
|
2
|
+
import { IEnvidoCalculator } from "../types";
|
|
3
|
+
import { IPlayer } from "./Player";
|
|
4
|
+
import { ITable } from "./Table";
|
|
5
|
+
import { ITeam } from "./Team";
|
|
6
|
+
export interface IEnvido {
|
|
7
|
+
started: boolean;
|
|
8
|
+
accepted: boolean;
|
|
9
|
+
answered: boolean;
|
|
10
|
+
finished: boolean;
|
|
11
|
+
possibleAnswerCommands: Array<ECommand>;
|
|
12
|
+
stake: number;
|
|
13
|
+
declineStake: number;
|
|
14
|
+
teamIdx: 0 | 1 | null;
|
|
15
|
+
answer: boolean | null;
|
|
16
|
+
pointAnswersCount: number;
|
|
17
|
+
winningPointsAnswer: number;
|
|
18
|
+
turn: number;
|
|
19
|
+
winningPlayer: IPlayer | null;
|
|
20
|
+
winner: ITeam | null;
|
|
21
|
+
teams: [ITeam, ITeam];
|
|
22
|
+
players: Array<IPlayer>;
|
|
23
|
+
currentPlayer: IPlayer | null;
|
|
24
|
+
generator: Generator<IEnvido, void, unknown>;
|
|
25
|
+
sayPoints(player: IPlayer, points: number): IEnvido;
|
|
26
|
+
sayEnvido(command: EEnvidoCommand, player: IPlayer): IEnvido;
|
|
27
|
+
sayAnswer(player: IPlayer, answer: boolean | null): IEnvido;
|
|
28
|
+
setTurn(turn: number): number;
|
|
29
|
+
setTeam(idx: 0 | 1): 0 | 1;
|
|
30
|
+
setCurrentPlayer(player: IPlayer | null): IPlayer | null;
|
|
31
|
+
getNextPlayer(): IteratorResult<IEnvido, IEnvido | void>;
|
|
32
|
+
}
|
|
33
|
+
export declare const EnvidoCalculator: IEnvidoCalculator;
|
|
34
|
+
export declare function Envido(teams: [ITeam, ITeam], matchPoint: number, table: ITable): IEnvido;
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Envido = exports.EnvidoCalculator = void 0;
|
|
4
|
+
const types_1 = require("../../types");
|
|
5
|
+
const types_2 = require("../types");
|
|
6
|
+
const utils_1 = require("../utils");
|
|
7
|
+
const EMPTY_ENVIDO = {
|
|
8
|
+
turn: 0,
|
|
9
|
+
teamIdx: null,
|
|
10
|
+
answer: null,
|
|
11
|
+
winningPlayer: null,
|
|
12
|
+
currentPlayer: null,
|
|
13
|
+
players: [],
|
|
14
|
+
};
|
|
15
|
+
exports.EnvidoCalculator = {
|
|
16
|
+
[types_1.EEnvidoCommand.ENVIDO]: (args) => {
|
|
17
|
+
if (!args || args.stake === undefined || args.declineStake === undefined) {
|
|
18
|
+
throw new Error("Envido calculator arguments are undefined");
|
|
19
|
+
}
|
|
20
|
+
const next = [
|
|
21
|
+
types_1.EEnvidoCommand.REAL_ENVIDO,
|
|
22
|
+
types_1.EEnvidoCommand.FALTA_ENVIDO,
|
|
23
|
+
types_1.EAnswerCommand.QUIERO,
|
|
24
|
+
types_1.EAnswerCommand.NO_QUIERO,
|
|
25
|
+
];
|
|
26
|
+
return {
|
|
27
|
+
accept: 2,
|
|
28
|
+
decline: 1,
|
|
29
|
+
next: args.stake < 2 ? [types_1.EEnvidoCommand.ENVIDO, ...next] : next,
|
|
30
|
+
};
|
|
31
|
+
},
|
|
32
|
+
[types_1.EEnvidoCommand.REAL_ENVIDO]: () => ({
|
|
33
|
+
accept: 3,
|
|
34
|
+
decline: 1,
|
|
35
|
+
next: [types_1.EEnvidoCommand.FALTA_ENVIDO, types_1.EAnswerCommand.QUIERO, types_1.EAnswerCommand.NO_QUIERO],
|
|
36
|
+
}),
|
|
37
|
+
[types_1.EEnvidoCommand.FALTA_ENVIDO]: (args) => {
|
|
38
|
+
if (!args || !args.teams || !args.matchPoint) {
|
|
39
|
+
throw new Error("Envido calculator arguments are undefined");
|
|
40
|
+
}
|
|
41
|
+
const { teams, matchPoint } = args;
|
|
42
|
+
const totals = teams.map((team) => team.points.malas + team.points.buenas);
|
|
43
|
+
const higher = (0, utils_1.getMaxNumberIndex)(totals);
|
|
44
|
+
const points = teams[higher].points;
|
|
45
|
+
const accept = points.buenas > 0 ? matchPoint - points.buenas : matchPoint - points.malas;
|
|
46
|
+
return {
|
|
47
|
+
accept: 0,
|
|
48
|
+
decline: 2,
|
|
49
|
+
replace: accept,
|
|
50
|
+
next: [types_1.EAnswerCommand.QUIERO, types_1.EAnswerCommand.NO_QUIERO],
|
|
51
|
+
};
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
function Envido(teams, matchPoint, table) {
|
|
55
|
+
function* envidoAnswerGeneratorSequence() {
|
|
56
|
+
let i = 0;
|
|
57
|
+
while (i < envido.players.length && (envido.answer === null || envido.winner === null)) {
|
|
58
|
+
const player = envido.players[envido.turn];
|
|
59
|
+
envido.setCurrentPlayer(player);
|
|
60
|
+
if (player.disabled || !player.ready) {
|
|
61
|
+
envido.setCurrentPlayer(null);
|
|
62
|
+
}
|
|
63
|
+
if (envido.turn >= envido.players.length - 1) {
|
|
64
|
+
envido.setTurn(0);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
envido.setTurn(envido.turn + 1);
|
|
68
|
+
}
|
|
69
|
+
i++;
|
|
70
|
+
yield envido;
|
|
71
|
+
}
|
|
72
|
+
envido.setCurrentPlayer(null);
|
|
73
|
+
yield envido;
|
|
74
|
+
}
|
|
75
|
+
const envido = Object.assign(Object.assign({}, EMPTY_ENVIDO), { started: false, finished: false, answered: false, accepted: false, possibleAnswerCommands: Object.values(types_1.EEnvidoCommand), declineStake: 0, winningPointsAnswer: 0, pointAnswersCount: 0, winner: null, stake: 0, teams, generator: envidoAnswerGeneratorSequence(), sayEnvido(command, player) {
|
|
76
|
+
const playerTeamIdx = player.teamIdx;
|
|
77
|
+
if (envido.teamIdx !== playerTeamIdx && envido.possibleAnswerCommands.includes(command)) {
|
|
78
|
+
const opponentIdx = Number(!playerTeamIdx);
|
|
79
|
+
const { accept, decline, replace, next } = exports.EnvidoCalculator[command]({
|
|
80
|
+
stake: envido.stake,
|
|
81
|
+
declineStake: envido.declineStake,
|
|
82
|
+
teams,
|
|
83
|
+
matchPoint,
|
|
84
|
+
});
|
|
85
|
+
envido.teamIdx = playerTeamIdx;
|
|
86
|
+
envido.stake += accept;
|
|
87
|
+
envido.declineStake += decline;
|
|
88
|
+
envido.generator = envidoAnswerGeneratorSequence();
|
|
89
|
+
envido.players = teams[opponentIdx].players;
|
|
90
|
+
envido.started = true;
|
|
91
|
+
envido.answered = false;
|
|
92
|
+
if (replace) {
|
|
93
|
+
envido.stake = replace;
|
|
94
|
+
}
|
|
95
|
+
envido.possibleAnswerCommands = next;
|
|
96
|
+
}
|
|
97
|
+
return envido;
|
|
98
|
+
},
|
|
99
|
+
sayPoints(player, points) {
|
|
100
|
+
if (!envido.accepted) {
|
|
101
|
+
throw new Error(types_2.GAME_ERROR.ENVIDO_NOT_ACCEPTED);
|
|
102
|
+
}
|
|
103
|
+
if (!envido.winningPlayer || !envido.winningPointsAnswer) {
|
|
104
|
+
envido.winningPlayer = player;
|
|
105
|
+
envido.winningPointsAnswer = points;
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
if (points > envido.winningPointsAnswer) {
|
|
109
|
+
envido.winningPlayer = player;
|
|
110
|
+
envido.winningPointsAnswer = points;
|
|
111
|
+
}
|
|
112
|
+
if (points === envido.winningPointsAnswer) {
|
|
113
|
+
const forehandWinner = table.getPlayerPosition(player.key, true) <
|
|
114
|
+
table.getPlayerPosition(envido.winningPlayer.key, true)
|
|
115
|
+
? player
|
|
116
|
+
: envido.winningPlayer;
|
|
117
|
+
envido.winningPlayer = forehandWinner;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
envido.pointAnswersCount++;
|
|
121
|
+
if (envido.pointAnswersCount >= envido.players.length) {
|
|
122
|
+
envido.finished = true;
|
|
123
|
+
envido.winner = teams[envido.winningPlayer.teamIdx];
|
|
124
|
+
}
|
|
125
|
+
return envido;
|
|
126
|
+
},
|
|
127
|
+
sayAnswer(player, answer) {
|
|
128
|
+
const opponentIdx = Number(!player.teamIdx);
|
|
129
|
+
if (answer === null || player.teamIdx === envido.teamIdx) {
|
|
130
|
+
return envido;
|
|
131
|
+
}
|
|
132
|
+
if (answer) {
|
|
133
|
+
envido.accepted = true;
|
|
134
|
+
envido.generator = envidoAnswerGeneratorSequence();
|
|
135
|
+
envido.turn = 0;
|
|
136
|
+
table.players.forEach((player) => player.calculateEnvido());
|
|
137
|
+
envido.players = table.getPlayersForehandFirst();
|
|
138
|
+
}
|
|
139
|
+
if (answer === false) {
|
|
140
|
+
envido.finished = true;
|
|
141
|
+
const opponentTeam = teams[opponentIdx];
|
|
142
|
+
opponentTeam.addPoints(matchPoint, envido.declineStake);
|
|
143
|
+
envido.winner = opponentTeam;
|
|
144
|
+
}
|
|
145
|
+
envido.answered = true;
|
|
146
|
+
envido.teamIdx = opponentIdx;
|
|
147
|
+
envido.answer = answer;
|
|
148
|
+
envido.turn = 0;
|
|
149
|
+
return envido;
|
|
150
|
+
},
|
|
151
|
+
setTeam(idx) {
|
|
152
|
+
envido.teamIdx = idx;
|
|
153
|
+
return envido.teamIdx;
|
|
154
|
+
},
|
|
155
|
+
setTurn(turn) {
|
|
156
|
+
envido.turn = turn;
|
|
157
|
+
return envido.turn;
|
|
158
|
+
},
|
|
159
|
+
setCurrentPlayer(player) {
|
|
160
|
+
envido.currentPlayer = player;
|
|
161
|
+
return envido.currentPlayer;
|
|
162
|
+
},
|
|
163
|
+
getNextPlayer() {
|
|
164
|
+
return envido.generator.next();
|
|
165
|
+
} });
|
|
166
|
+
return envido;
|
|
167
|
+
}
|
|
168
|
+
exports.Envido = Envido;
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -1,23 +1,26 @@
|
|
|
1
|
-
import { IHand } from "./Hand";
|
|
2
|
-
import { IMatch } from "./Match";
|
|
3
|
-
import { IPlayInstance } from "./Play";
|
|
4
|
-
import { IPlayer } from "./Player";
|
|
5
|
-
import { ITeam } from "./Team";
|
|
6
|
-
export type IWinnerCallback = (winner: ITeam, teams: [ITeam, ITeam]) => Promise<void>;
|
|
7
|
-
export type ITurnCallback = (play: IPlayInstance, newHandJustStarted: boolean) => Promise<void>;
|
|
8
|
-
export type ITrucoCallback = (play: IPlayInstance) => Promise<void>;
|
|
9
|
-
export
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
1
|
+
import { IHand } from "./Hand";
|
|
2
|
+
import { IMatch } from "./Match";
|
|
3
|
+
import { IPlayInstance } from "./Play";
|
|
4
|
+
import { IPlayer } from "./Player";
|
|
5
|
+
import { ITeam } from "./Team";
|
|
6
|
+
export type IWinnerCallback = (winner: ITeam, teams: [ITeam, ITeam]) => Promise<void>;
|
|
7
|
+
export type ITurnCallback = (play: IPlayInstance, newHandJustStarted: boolean) => Promise<void>;
|
|
8
|
+
export type ITrucoCallback = (play: IPlayInstance) => Promise<void>;
|
|
9
|
+
export type IEnvidoCallback = (play: IPlayInstance, pointsRound: boolean) => Promise<void>;
|
|
10
|
+
export interface IGameLoop {
|
|
11
|
+
_onTruco: ITrucoCallback;
|
|
12
|
+
_onTurn: ITurnCallback;
|
|
13
|
+
_onWinner: IWinnerCallback;
|
|
14
|
+
_onEnvido: IEnvidoCallback;
|
|
15
|
+
currentPlayer: IPlayer | null;
|
|
16
|
+
currentHand: IHand | null;
|
|
17
|
+
lastCheckedHand: number | null;
|
|
18
|
+
teams: Array<ITeam>;
|
|
19
|
+
winner: ITeam | null;
|
|
20
|
+
onTurn: (callback: ITurnCallback) => IGameLoop;
|
|
21
|
+
onWinner: (callback: IWinnerCallback) => IGameLoop;
|
|
22
|
+
onTruco: (callback: ITrucoCallback) => IGameLoop;
|
|
23
|
+
onEnvido: (callback: IEnvidoCallback) => IGameLoop;
|
|
24
|
+
begin: () => Promise<void>;
|
|
25
|
+
}
|
|
26
|
+
export declare const GameLoop: (match: IMatch) => IGameLoop;
|