trucoshi 6.0.0 → 7.0.0-alpha

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.
@@ -13,6 +13,15 @@ export function Deck() {
13
13
  takeThree() {
14
14
  return [deck.takeCard(), deck.takeCard(), deck.takeCard()];
15
15
  },
16
+ pick(card) {
17
+ const idx = deck.cards.findIndex((c) => c === card);
18
+ if (idx > -1) {
19
+ deck.cards.splice(idx, 1);
20
+ deck.usedCards.push(card);
21
+ return card;
22
+ }
23
+ return null;
24
+ },
16
25
  shuffle(dealer) {
17
26
  deck.cards = getAllCards();
18
27
  deck.usedCards = [];
@@ -27,12 +36,23 @@ export function Deck() {
27
36
  }
28
37
  export const getAllCards = () => Object.keys(CARDS);
29
38
  export function dealCards(table, deck) {
39
+ const cheat_lots_of_flowers = process.env.APP_CHEAT_LOTS_OF_FLOWERS_FOR_TESTING === "1";
30
40
  const playerHands = [];
41
+ const players = table.getPlayersForehandFirst();
31
42
  for (let i = 0; i < 3; i++) {
32
- for (const player of table.getPlayersForehandFirst()) {
43
+ for (const player of players) {
33
44
  playerHands[player.idx] = [...(playerHands[player.idx] || []), deck.takeCard()];
34
45
  }
35
46
  }
47
+ if (cheat_lots_of_flowers && table.forehandIdx % 2 === 0) {
48
+ deck.shuffle(players[0].idx);
49
+ for (const player of players) {
50
+ const first = deck.takeCard();
51
+ const second = deck.pick(deck.cards.find((c) => c.charAt(1) === first.charAt(1)));
52
+ const third = deck.pick(deck.cards.find((c) => c.charAt(1) === first.charAt(1)));
53
+ playerHands[player.idx] = [first, second, third];
54
+ }
55
+ }
36
56
  for (const [key, player] of table.players.entries()) {
37
57
  player.setHand(playerHands[key]);
38
58
  }
@@ -27,7 +27,7 @@ function Rng() {
27
27
  * @param {number} nonce - the nonce
28
28
  * @returns {string} combined string
29
29
  */
30
- combine: (client, server, nonce) => client + server + nonce,
30
+ combine: (clientSeed, serverSeed, nonce) => clientSeed + serverSeed + nonce,
31
31
  /**
32
32
  * Generates a sha512 hash from a string
33
33
  *
@@ -1,5 +1,7 @@
1
1
  import { IRound } from "../truco";
2
- import { ICard } from "../types";
2
+ import { ICard, IPlayer } from "../types";
3
+ export declare function calculateFlorPoints(player: IPlayer): number;
3
4
  export declare function getMaxNumberIndex<T = number>(array: Array<T>): number;
5
+ export declare function getMinNumberIndex<T = number>(array: Array<T>): number;
4
6
  export declare function getCardValue(card: ICard): number;
5
7
  export declare function checkHandWinner(rounds: Array<IRound>, forehandTeamIdx: 0 | 1): null | 0 | 1;
package/dist/lib/utils.js CHANGED
@@ -1,9 +1,31 @@
1
+ import { splitCardvalues } from "../truco";
1
2
  import { CARDS } from "./constants";
3
+ // Calculates the Flor points for a player's hand.
4
+ // Returns the sum of the envidoValue of three cards of the same suit plus 20, or 0 if no Flor exists.
5
+ export function calculateFlorPoints(player) {
6
+ if (!player.hasFlor) {
7
+ return 0;
8
+ }
9
+ const hand = [...player.hand, ...player.usedHand].map(splitCardvalues);
10
+ // Verify that all cards share the same suit (should be true if player.hasFlor is set)
11
+ const sameSuit = hand.every((card) => card.palo === hand[0].palo);
12
+ if (!sameSuit) {
13
+ return 0;
14
+ }
15
+ // Sum the envidoValue of all cards (figures are 0)
16
+ const points = hand.reduce((sum, card) => sum + card.value, 20);
17
+ return points;
18
+ }
2
19
  export function getMaxNumberIndex(array) {
3
20
  return array.reduce((accumulator, current, index) => {
4
21
  return current > array[accumulator] ? index : accumulator;
5
22
  }, 0);
6
23
  }
24
+ export function getMinNumberIndex(array) {
25
+ return array.reduce((accumulator, current, index) => {
26
+ return current < array[accumulator] ? index : accumulator;
27
+ }, 0);
28
+ }
7
29
  export function getCardValue(card) {
8
30
  return CARDS[card] !== undefined ? CARDS[card] : -2;
9
31
  }
package/dist/types.d.ts CHANGED
@@ -47,6 +47,13 @@ export interface IMatchPreviousHand {
47
47
  cards: ICard[];
48
48
  };
49
49
  } | null;
50
+ flor: {
51
+ winner: IPublicPlayer;
52
+ data?: {
53
+ value: number;
54
+ cards: ICard[];
55
+ };
56
+ } | null;
50
57
  rounds: IPlayedCard[][];
51
58
  points: IHandPoints;
52
59
  matchSessionId: string;
@@ -137,7 +144,6 @@ export declare enum EHandState {
137
144
  WAITING_ENVIDO_ANSWER = "WAITING_ENVIDO_ANSWER",
138
145
  WAITING_ENVIDO_POINTS_ANSWER = "WAITING_ENVIDO_POINTS_ANSWER",
139
146
  WAITING_FLOR_ANSWER = "WAITING_FLOR_ANSWER",
140
- WAITING_FLOR_POINTS_ANSWER = "WAITING_FLOR_POINTS_ANSWER",
141
147
  BEFORE_FINISHED = "BEFORE_FINISHED",
142
148
  FINISHED = "FINISHED"
143
149
  }
@@ -168,7 +174,8 @@ export declare enum GAME_ERROR {
168
174
  ENVIDO_NOT_ACCEPTED = "ENVIDO_NOT_ACCEPTED",
169
175
  INVALID_COMAND = "INVALID_COMAND",
170
176
  INSUFFICIENT_BALANCE = "INSUFFICIENT_BALANCE",
171
- GAME_REQUIRES_ACCOUNT = "GAME_REQUIRES_ACCOUNT"
177
+ GAME_REQUIRES_ACCOUNT = "GAME_REQUIRES_ACCOUNT",
178
+ NO_FLOR = "NO_FLOR"
172
179
  }
173
180
  export interface EnvidoState {
174
181
  accept: number;
@@ -196,6 +203,7 @@ export interface IDeck {
196
203
  random: IRandom;
197
204
  cards: Array<ICard>;
198
205
  usedCards: Array<ICard>;
206
+ pick(card: ICard): ICard | null;
199
207
  takeCard(): ICard;
200
208
  takeThree(): [ICard, ICard, ICard];
201
209
  shuffle(dealerIdx: number): IDeck;
@@ -259,16 +267,18 @@ export interface IPlayer {
259
267
  _commands: Set<ECommand>;
260
268
  get commands(): Array<ECommand>;
261
269
  isTurn: boolean;
262
- hasSaidEnvidoPoints: boolean;
263
270
  turnExpiresAt: number | null;
264
271
  turnExtensionExpiresAt: number | null;
265
272
  hasFlor: boolean;
273
+ hasSaidFlorPoints: boolean;
274
+ hasSaidEnvidoPoints: boolean;
266
275
  isEnvidoTurn: boolean;
267
276
  isOwner: boolean;
268
277
  disabled: boolean;
269
278
  abandoned: boolean;
270
279
  ready: boolean;
271
280
  saidEnvidoPoints(): void;
281
+ saidFlorPoints(): void;
272
282
  resetCommands(): void;
273
283
  calculateEnvido(): Array<{
274
284
  value: number;
package/dist/types.js CHANGED
@@ -52,7 +52,6 @@ export var EHandState;
52
52
  EHandState["WAITING_ENVIDO_ANSWER"] = "WAITING_ENVIDO_ANSWER";
53
53
  EHandState["WAITING_ENVIDO_POINTS_ANSWER"] = "WAITING_ENVIDO_POINTS_ANSWER";
54
54
  EHandState["WAITING_FLOR_ANSWER"] = "WAITING_FLOR_ANSWER";
55
- EHandState["WAITING_FLOR_POINTS_ANSWER"] = "WAITING_FLOR_POINTS_ANSWER";
56
55
  EHandState["BEFORE_FINISHED"] = "BEFORE_FINISHED";
57
56
  EHandState["FINISHED"] = "FINISHED";
58
57
  })(EHandState || (EHandState = {}));
@@ -72,4 +71,5 @@ export var GAME_ERROR;
72
71
  GAME_ERROR["INVALID_COMAND"] = "INVALID_COMAND";
73
72
  GAME_ERROR["INSUFFICIENT_BALANCE"] = "INSUFFICIENT_BALANCE";
74
73
  GAME_ERROR["GAME_REQUIRES_ACCOUNT"] = "GAME_REQUIRES_ACCOUNT";
74
+ GAME_ERROR["NO_FLOR"] = "NO_FLOR";
75
75
  })(GAME_ERROR || (GAME_ERROR = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "trucoshi",
3
- "version": "6.0.0",
3
+ "version": "7.0.0-alpha",
4
4
  "description": "Lightning Truco Server",
5
5
  "main": "dist/types.js",
6
6
  "license": "GPL-3.0",
@@ -243,7 +243,7 @@ const PrismaClient = getPrismaClient(config)
243
243
  exports.PrismaClient = PrismaClient
244
244
  Object.assign(exports, Prisma)
245
245
 
246
- path.join(__dirname, "libquery_engine-debian-openssl-3.0.x.so.node");
247
- path.join(process.cwd(), "prisma/client/libquery_engine-debian-openssl-3.0.x.so.node")
246
+ path.join(__dirname, "libquery_engine-debian-openssl-1.1.x.so.node");
247
+ path.join(process.cwd(), "prisma/client/libquery_engine-debian-openssl-1.1.x.so.node")
248
248
  path.join(__dirname, "schema.prisma");
249
249
  path.join(process.cwd(), "prisma/client/schema.prisma")