UNPKG

belote

Version:

A TypeScript library for playing Belote card game with bot support.

164 lines (163 loc) 4.86 kB
export declare const cardColors: readonly ["hearts", "diamonds", "clubs", "spades"]; export type CardColor = typeof cardColors[number]; export declare const cardTypes: readonly ["ace", "king", "queen", "jack", "ten", "nine", "eight", "seven"]; export type CardType = typeof cardTypes[number]; export declare const cardTypeOrder: CardType[]; export declare const cardColorsLocal: readonly ["herc", "karo", "tref", "pik"]; export type CardColorLocal = typeof cardColorsLocal[number]; export declare const cardTypesLocal: readonly ["as", "kralj", "baba", "decko", "deset", "devet", "osam", "sedam"]; export type CardTypeLocal = typeof cardTypesLocal[number]; export declare const cardTypeOrderLocal: CardTypeLocal[]; export declare enum CardPoints { Ace = 11, King = 4, Queen = 3, Jack = 2, Ten = 10, Nine = 0, Eight = 0, Seven = 0 } export declare enum CardPointsAdut { Ace = 11, King = 4, Queen = 3, Jack = 20, Ten = 10, Nine = 14, Eight = 0, Seven = 0 } export type Card = { color: CardColor; type: CardType; }; export type PlayedCard = Card & { playerId: string; }; export declare enum Callings { None = 0,// No call made. Belot = -1,// 8 cards of same color, instant win. Bela = 20,// King and Queen of adut. Jack4 = 200, Nine4 = 150, Ace4 = 100, King4 = 100, Queen4 = 100, Ten4 = 100, Sequence3 = 20, Sequence4 = 50, Sequence5 = 100, Sequence6 = 100, Sequence7 = 100 } export declare enum GamePhase { Waiting = 0, Dealing = 1, Bidding = 2, Calling = 3, Playing = 4, Finished = 5 } export type EndValue = 501 | 701 | 1001; export type MoveTime = 10 | 20 | 30 | 40 | 50 | 60; export type GameOptions = { endValue: EndValue; moveTimeSec: MoveTime; botDelayMs: number; pauseBetweenRoundsMs: number; }; export type CallingResult = { type: Callings; }; export type AllPossibleCalls = { cards: Card[]; calling: CallingResult; }; export type Trick = { cardsPlayed: PlayedCard[]; winnerPlayerId?: string; winningCard?: Card; }; export type Team = { id: number; name: string; score: number[]; tricksHistory: Trick[]; }; export type AllowedPlayerKeys = 'color' | 'id' | 'teamId'; export type PartialPlayer = Pick<Player, AllowedPlayerKeys | 'name'>; export type Player = { id: string; name: string; teamId: number; color?: string; isReady: boolean; isDealer: boolean; isBot: boolean; cards: Card[]; talon: Card[]; }; export type AdutCall = { playerId: string; call: CardColor | null; }; export type CallingsCall = { playerId: string; call: Callings; cards: Card[]; }; export type GameState = { players: Player[]; team1: Team; team2: Team; deck: Card[]; round: number; adut: CardColor | null; bids: AdutCall[]; calls: CallingsCall[]; gamePhase: GamePhase; currentTrick: Trick | null; currentPlayerIndex: number; currentPlayerTimeLeft: number; isGameOver: boolean; winnerTeam?: Team; }; export type BeloteEvents = { error: (error: Error) => void; playerJoined: (player: Player) => void; playerLeft: (playerId: string) => void; playerSwitchedTeam: (playerId: string, newTeamId: number) => void; playerReadyChanged: (playerId: string, isReady: boolean) => void; allPlayersReady: () => void; notEnoughPlayers: () => void; gameStarted: (gameState: GameState) => void; gameEnded: (winnerTeam: Team, finalScores: Record<'team1' | 'team2', number>, isByBelot?: boolean) => void; roundStarted: (roundNumber: number, dealer: Player) => void; roundCompleted: (roundNumber: number, scores: { team1: number; team2: number; }, winningTeam: Team, failedTeam?: Team) => void; timerUpdate: (timeLeft: number, timerFor: Player | null) => void; initialCardsDealt: (playerCards: { playerId: string; cardCount: number; }[]) => void; talonDealt: (playerTalon: { playerId: string; talon: Card[]; }[]) => void; biddingStarted: (firstPlayer: Player) => void; bidMade: (playerId: string, call: CardColor | 'pass') => void; adutChosen: (adut: CardColor, playerId: string) => void; nextPlayerBid: (player: Player) => void; callingPhaseStarted: () => void; callMade: (playerId: string, cards: Card[], callingResult: CallingResult | null) => void; callingPhaseEnded: (winningCall: CallingsCall | null) => void; belotWin: (playerId: string, belotColor: CardColor) => void; playingPhaseStarted: () => void; cardPlayed: (playerId: string, card: Card) => void; nextPlayerMove: (player: Player) => void; trickCompleted: (trick: Trick, winnerId: string) => void; nextTrickStarted: (leadPlayer: Player) => void; };