Skip to content

Commit

Permalink
Formatted PokerTable model
Browse files Browse the repository at this point in the history
`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:
  • Loading branch information
astitvsingh committed Nov 8, 2024
1 parent 70947c1 commit 9efb476
Showing 1 changed file with 32 additions and 32 deletions.
64 changes: 32 additions & 32 deletions src/models/pokerTable/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//@collapse

// Import Enums
import { PokerSeatEvents , LogLevel } from "../../enums";
import { PokerSeatEvents, LogLevel } from "../../enums";

// Import Interfaces
import {
Expand All @@ -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";

/**
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) => {
Expand All @@ -305,9 +305,8 @@ class PokerTable extends BaseEventEmitter implements PokerTableInterface {
this.__checkOccupancyCount(event, next);
},
],
})
});
}

}
}

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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`.
Expand All @@ -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(
Expand All @@ -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,
Expand All @@ -744,7 +744,7 @@ class PokerTable extends BaseEventEmitter implements PokerTableInterface {
);
return false;
}

event.lastModifiedAt = new Date();
next();
}
Expand All @@ -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);
}
}
Expand Down

0 comments on commit 9efb476

Please sign in to comment.