From 9efb47618ec5633d35dde3dabfb7b2a9f353c0e9 Mon Sep 17 00:00:00 2001 From: Astitv Singh Date: Fri, 8 Nov 2024 20:44:38 +0530 Subject: [PATCH] `Formatted PokerTable model` `Summary` A brief one-line summary of the changes made in this commit. `Description` A detailed description of the changes introduced by this commit. Include information about why the changes were made, how they address specific issues or requirements, and any relevant context or considerations. `Type` Specify the type of change represented by this commit. Choose only one of the following options: - Feature: A new feature or enhancement added to the project. - Fix: A bug fix or resolution to an issue. - Refactor: Code refactoring or restructuring without changing behavior. - Documentation: Updates or additions to documentation files. - Test: Additions or modifications to tests. - Chore: Routine maintenance tasks, such as dependency updates or code cleanup. `Impact` Describe the impact of this change on the project. Consider factors such as functionality, performance, compatibility, and user experience. `Related Issues` List any related issues or tickets addressed by this commit. Use GitHub issue numbers or links to reference specific issues. `Dependencies` Specify any dependencies or requirements associated with this commit. Include information about libraries, frameworks, or other components affected by the changes. `Testing` Describe the testing approach or strategy used to validate this change. Include details about test cases, scenarios, or environments used for testing. `Notes` Add any additional notes, comments, or considerations relevant to this commit. This may include warnings, caveats, or follow-up tasks for future work. `Commit Checklist`: - [ ] The commit message follows the established format and guidelines. - [ ] The changes introduced by the commit have been thoroughly reviewed and tested. - [ ] Any related issues or tickets have been appropriately linked or referenced. - [ ] Documentation has been updated to reflect the changes introduced by the commit. - [ ] The commit does not introduce any new linting errors, warnings, or regressions. `Branch` On branch `Changes` Changes to be committed: --- src/models/pokerTable/index.ts | 64 +++++++++++++++++----------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/src/models/pokerTable/index.ts b/src/models/pokerTable/index.ts index 5040aa7..6215361 100644 --- a/src/models/pokerTable/index.ts +++ b/src/models/pokerTable/index.ts @@ -1,7 +1,7 @@ //@collapse // Import Enums -import { PokerSeatEvents , LogLevel } from "../../enums"; +import { PokerSeatEvents, LogLevel } from "../../enums"; // Import Interfaces import { @@ -21,7 +21,7 @@ import { PokerPlayer } from "../pokerPlayer"; import { PokerSeat } from "../pokerSeat"; // Import Utils -import { generateUniqueId , logger} from "../../utils"; +import { generateUniqueId, logger } from "../../utils"; import { PokerGame } from "../pokerGame"; /** @@ -196,7 +196,7 @@ class PokerTable extends BaseEventEmitter implements PokerTableInterface { */ private __gameInProgress: boolean = false; - private __game:PokerGameInterface|undefined = undefined; + private __game: PokerGameInterface | undefined = undefined; /************************************************************************************************************** * CONSTRUCTOR & INITIALIZERS @@ -293,9 +293,9 @@ class PokerTable extends BaseEventEmitter implements PokerTableInterface { this.__seats?.push(seat); // seat.on(PokerSeatEvents.OCCUPIED,(event)=>{}) - seat.listenToEvent(PokerSeatEvents.OCCUPIED,{ - handler:(event:BaseEventInterface) => { - this.__startGame() + seat.listenToEvent(PokerSeatEvents.OCCUPIED, { + handler: (event: BaseEventInterface) => { + this.__startGame(); }, middlewares: [ (event, next) => { @@ -305,9 +305,8 @@ class PokerTable extends BaseEventEmitter implements PokerTableInterface { this.__checkOccupancyCount(event, next); }, ], - }) + }); } - } } @@ -464,16 +463,16 @@ class PokerTable extends BaseEventEmitter implements PokerTableInterface { return this.__seats; } - /** + /** * `getSeats` * Starts a new PokerGame if there are at least two active players at the PokerTable. * This method initiates the game flow, including assigning blinds and starting the rounds. * @returns {number} */ - public getGame(): PokerGameInterface|undefined { + public getGame(): PokerGameInterface | undefined { return this.__game; } - + /** * `getSeats` * Starts a new PokerGame if there are at least two active players at the PokerTable. @@ -678,19 +677,18 @@ class PokerTable extends BaseEventEmitter implements PokerTableInterface { return true; } - /** * `getSeats` * Starts a new PokerGame if there are at least two active players at the PokerTable. * This method initiates the game flow, including assigning blinds and starting the rounds. * @returns {number} */ - private __setGameInProgress(bool:boolean): boolean { - this.__gameInProgress = bool ; + private __setGameInProgress(bool: boolean): boolean { + this.__gameInProgress = bool; return this.__gameInProgress; } - /** + /** * `setSeats` * @public * Returns the poker table's `id`. @@ -700,9 +698,11 @@ class PokerTable extends BaseEventEmitter implements PokerTableInterface { * const rank = card.getRank(); * console.log(rank); // "A" */ - private __setGame(game: PokerGameInterface|undefined): PokerGameInterface|undefined { - this.__game = game; - return this.__game; + private __setGame( + game: PokerGameInterface | undefined + ): PokerGameInterface | undefined { + this.__game = game; + return this.__game; } private __occupySeat( @@ -723,17 +723,17 @@ class PokerTable extends BaseEventEmitter implements PokerTableInterface { return false; } - /** + /** * #### Description * Checks seat availability to determine if it can be occupied by a player. * * @param {BaseEventInterface} event - The event object containing event data. * @param {() => void} next - The next middleware function to call if seat is available. */ - private __checkIsGameInProgress( + private __checkIsGameInProgress( event: BaseEventInterface, next: () => void - ): void|false { + ): void | false { if (this.isGameInProgress()) { logger.log( LogLevel.WARN, @@ -744,7 +744,7 @@ class PokerTable extends BaseEventEmitter implements PokerTableInterface { ); return false; } - + event.lastModifiedAt = new Date(); next(); } @@ -754,32 +754,32 @@ class PokerTable extends BaseEventEmitter implements PokerTableInterface { next: () => void ): void | false { let occupiedSeats = 0; - + for (let i = 0; i < this.getSeats().length; i++) { let seat = this.getSeats()[i]; if (seat.getPlayer()) { occupiedSeats += 1; } } - + // Check if all seats are occupied if (occupiedSeats === this.getSeats().length) { - logger.log( - LogLevel.WARN, - "All seats are occupied", - event - ) + logger.log(LogLevel.WARN, "All seats are occupied", event); return false; } - + // Update the event timestamp and call the next middleware function event.lastModifiedAt = new Date(); next(); } private __startGame() { - let config:PokerGameConfig= {smallBlind:this.getSmallBlind(),bigBlind:this.getBigBlind(),players:[]} - let newGame = new PokerGame(config) + let config: PokerGameConfig = { + smallBlind: this.getSmallBlind(), + bigBlind: this.getBigBlind(), + players: [], + }; + let newGame = new PokerGame(config); this.__setGame(newGame); } }