flow
This commit is contained in:
parent
f67c262b0e
commit
ca0f1466c2
@ -120,7 +120,11 @@ export class LoggingService {
|
||||
}
|
||||
|
||||
_getStringObject(data: any) {
|
||||
return JSON.stringify(data, null, 2);
|
||||
try {
|
||||
return JSON.stringify(data, null, 2);
|
||||
} catch (error) {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -27,6 +27,7 @@ export class DominoesGame {
|
||||
handSize: number = 7;
|
||||
notificationManager: PlayerNotificationService = new PlayerNotificationService();
|
||||
lastMove: PlayerMove | null = null;
|
||||
forcedInitialPlayerIndex: number | null = null;
|
||||
|
||||
constructor(public players: PlayerInterface[], seed: PRNG) {
|
||||
this.id = uuid();
|
||||
@ -43,6 +44,10 @@ export class DominoesGame {
|
||||
this.board.boneyard = this.generateTiles();
|
||||
}
|
||||
|
||||
setForcedInitialPlayerIndex(index: number) {
|
||||
this.forcedInitialPlayerIndex = index;
|
||||
}
|
||||
|
||||
reset() {
|
||||
this.board.reset();
|
||||
this.initializeGame();
|
||||
@ -174,7 +179,7 @@ export class DominoesGame {
|
||||
|
||||
this.tileSelectionPhase = false;
|
||||
this.gameInProgress = true;
|
||||
this.currentPlayerIndex = this.getStartingPlayerIndex();
|
||||
this.currentPlayerIndex = (this.forcedInitialPlayerIndex !== null) ? this.forcedInitialPlayerIndex : this.getStartingPlayerIndex();
|
||||
printLine(`${this.players[this.currentPlayerIndex].name} is the starting player:`);
|
||||
while (!this.gameOver) {
|
||||
await this.playTurn();
|
||||
|
@ -69,15 +69,18 @@ export class MatchSession {
|
||||
let gameNumber: number = 0;
|
||||
this.matchInProgress = true
|
||||
this.playerNotificationManager.notifyMatchState(this);
|
||||
let winnerIndex: number | null = null;
|
||||
while (this.matchInProgress) {
|
||||
|
||||
this.currentGame = new DominoesGame(this.players, this.rng);
|
||||
if (winnerIndex !== null) {
|
||||
this.currentGame.setForcedInitialPlayerIndex(winnerIndex);
|
||||
}
|
||||
gameNumber += 1;
|
||||
this.state = 'started'
|
||||
this.logger.info(`Game #${gameNumber} started`);
|
||||
// this.game.reset()
|
||||
const gameSummary = await this.currentGame.start();
|
||||
this.logger.debug('gameSummary :>> ', gameSummary);
|
||||
winnerIndex = this.players.findIndex(player => player.id === gameSummary.winner?.id);
|
||||
this.setScores();
|
||||
this.checkMatchWinner();
|
||||
this.resetPlayers();
|
||||
|
@ -13,7 +13,8 @@ export class PlayerAI extends AbstractPlayer {
|
||||
}
|
||||
|
||||
async makeMove(board: Board): Promise<PlayerMove | null> {
|
||||
await wait(500); // Simulate thinking time
|
||||
const rndWait = Math.floor(Math.random() * 1000) + 1000;
|
||||
await wait(rndWait); // Simulate thinking time
|
||||
if (board.tiles.length === 0) {
|
||||
printLine('playing the first tile');
|
||||
const highestPair = this.getHighestPair();
|
||||
|
Loading…
x
Reference in New Issue
Block a user