ChessNut/engine/core/game_state.js
2025-10-14 22:06:53 +02:00

56 lines
No EOL
1,000 B
JavaScript

class GameState {
constructor() {
/** @type {Board} */
this.board = new Board();
/** @type {Team} */
this.whiteTeam = new Team("white");
/** @type {Team} */
this.blackTeam = new Team("black");
/** @type {number} */
this.turn = 0;
}
/**
* @returns {Board}
*/
getBoard() {
return this.board;
}
/**
* @returns {Team}
*/
getWhiteTeam() {
return this.whiteTeam;
}
/**
* @returns {Team}
*/
getBlackTeam() {
return this.blackTeam;
}
/**
* @returns {number}
*/
getTurn() {
return this.turn;
}
/**
* @returns {void}
*/
nextTurn() {
this.turn = 1 - this.turn;
}
/**
* @param {PieceColor} color
* @returns {boolean}
*/
hasHisKing(color) {
const team = color === PieceColor.WHITE ? this.whiteTeam : this.blackTeam;
return team.hasKing();
}
}