diff --git a/core/development/logic/actions/AttackPieceAction.test.ts b/core/development/logic/actions/AttackPieceAction.test.ts new file mode 100644 index 0000000..ec90b36 --- /dev/null +++ b/core/development/logic/actions/AttackPieceAction.test.ts @@ -0,0 +1,95 @@ +import { OVERWORLD_BOARD_ID } from '../../Constants'; +import { game } from '../../Game'; +import { PlayerInventory } from '../inventory/PlayerInventory'; +import { Queen } from '../pieces/Queen'; +import { Position } from '../pieces/types/Position'; +import { Player } from '../players/Player'; +import { PlayerColor } from '../players/types/PlayerColor'; +import { AttackPieceAction } from './AttackPieceAction'; +import { ActionResult } from './types/ActionResult'; + +const whitePlayer = new Player(PlayerColor.WHITE, new PlayerInventory()); + +jest.mock('../../ui/BoardManager.ts', () => ({ + destroyElementOnBoard: jest.fn(), + moveElementOnBoard: jest.fn(), + getSquareElementById: jest.fn(), + spawnPieceElementOnBoard: jest.fn(), + getAllSquareElements: jest.fn(), + highlightLastMove: jest.fn(), +})); +jest.mock('../../ui/Screen.ts', () => ({ + renderGameInformation: jest.fn(), + hideUnicornAttackButton: jest.fn(), +})); +jest.mock('../../ui/logs/Logger.ts'); +jest.mock('../../ui/Events.ts', () => ({})); +jest.mock('../../ui/InventoriesUI.ts', () => ({ + initializeInventoryUI: jest.fn(), + switchShownInventory: jest.fn(), + showItemOnInventory: jest.fn(), +})); +jest.mock('../../ui/ShopUI.ts'); + +game.getPlayersTurnSwitcher = jest.fn().mockReturnValue({ + getCurrentPlayer: jest.fn().mockReturnValue(whitePlayer), + getTurnsCount: jest.fn().mockReturnValue(1), +}); + +describe('AttackPieceAction', () => { + afterEach(() => { + jest.clearAllMocks(); + }); + + test('Invalid - Piece Undefined Position', () => { + // Arrange + const piece = new Queen(whitePlayer, undefined); + + const attackPieceAction = new AttackPieceAction(piece, piece); + + // Act + const actionResult = attackPieceAction.execute(); + + // Assert + expect(actionResult).toEqual(ActionResult.FAILURE); + }); + + test('Valid - Normal Kill', () => { + // Arrange + const initialKillerPiecePosition: Position = { + coordinates: [0, 0], + boardId: OVERWORLD_BOARD_ID, + }; + const killerPiece = new Queen(whitePlayer, initialKillerPiecePosition); + const initialKilledPiecePosition: Position = { + coordinates: [1, 0], + boardId: OVERWORLD_BOARD_ID, + }; + const killedPiece = new Queen(whitePlayer, initialKilledPiecePosition); + + const attackPieceAction = new AttackPieceAction(killerPiece, killedPiece); + + // Act + const actionResult = attackPieceAction.execute(); + + // Assert + expect(actionResult).toEqual(ActionResult.SUCCESS); + }); + + test('Valid - Attack Self', () => { + // Arrange + const initialPiecePosition: Position = { + coordinates: [3, 4], + boardId: OVERWORLD_BOARD_ID, + }; + const piece = new Queen(whitePlayer, initialPiecePosition); + + const attackPieceAction = new AttackPieceAction(piece, piece); + + // Act + const actionResult = attackPieceAction.execute(); + + // Assert + expect(actionResult).toEqual(ActionResult.SUCCESS); + }); +}); diff --git a/core/development/logic/actions/AttackPieceAction.ts b/core/development/logic/actions/AttackPieceAction.ts index 02c5cd1..5254a1f 100644 --- a/core/development/logic/actions/AttackPieceAction.ts +++ b/core/development/logic/actions/AttackPieceAction.ts @@ -25,8 +25,10 @@ export class AttackPieceAction implements GameAction { this.target, this.piece, ).execute(); - if (killPieceByPieceResult === ActionResult.FAILURE) + + if (killPieceByPieceResult === ActionResult.FAILURE) { return ActionResult.FAILURE; + } const targetSquare: Square = { position: targetPosition }; move(this.piece, targetSquare.position); diff --git a/core/development/logic/actions/CastleAction.test.ts b/core/development/logic/actions/CastleAction.test.ts new file mode 100644 index 0000000..0e326f8 --- /dev/null +++ b/core/development/logic/actions/CastleAction.test.ts @@ -0,0 +1,123 @@ +import { OVERWORLD_BOARD_ID } from '../../Constants'; +import { game } from '../../Game'; +import { PlayerInventory } from '../inventory/PlayerInventory'; +import { King } from '../pieces/King'; +import { Position } from '../pieces/types/Position'; +import { Player } from '../players/Player'; +import { PlayerColor } from '../players/types/PlayerColor'; +import { CastleAction } from './CastleAction'; +import { ActionResult } from './types/ActionResult'; + +const whitePlayer = new Player(PlayerColor.WHITE, new PlayerInventory()); + +jest.mock('../../ui/BoardManager.ts', () => ({ + destroyElementOnBoard: jest.fn(), + moveElementOnBoard: jest.fn(), + getSquareElementById: jest.fn(), + spawnPieceElementOnBoard: jest.fn(), + getAllSquareElements: jest.fn(), + highlightLastMove: jest.fn(), +})); +jest.mock('../../ui/Screen.ts', () => ({ + renderGameInformation: jest.fn(), + hideUnicornAttackButton: jest.fn(), +})); +jest.mock('../../ui/logs/Logger.ts'); +jest.mock('../../ui/Events.ts', () => ({})); +jest.mock('../../ui/InventoriesUI.ts', () => ({ + initializeInventoryUI: jest.fn(), + switchShownInventory: jest.fn(), + showItemOnInventory: jest.fn(), +})); +jest.mock('../../ui/ShopUI.ts'); + +game.getPlayersTurnSwitcher = jest.fn().mockReturnValue({ + getCurrentPlayer: jest.fn().mockReturnValue(whitePlayer), + getTurnsCount: jest.fn().mockReturnValue(1), +}); + +describe('CastleAction', () => { + afterEach(() => { + jest.clearAllMocks(); + }); + + test('Invalid - Piece Undefined Position', () => { + // Arrange + const kingPiece = new King(whitePlayer, undefined); + const targetPosition: Position = { + coordinates: [6, 0], + boardId: OVERWORLD_BOARD_ID, + }; + + const castleAction = new CastleAction(kingPiece, targetPosition); + + // Act + const actionResult = castleAction.execute(); + + // Assert + expect(actionResult).toEqual(ActionResult.FAILURE); + }); + + test('Invalid - Piece Invalid Position', () => { + // Arrange + const initialPosition: Position = { + coordinates: [4, 0], + boardId: OVERWORLD_BOARD_ID, + }; + const kingPiece = new King(whitePlayer, initialPosition); + const targetPosition: Position = { + coordinates: [5, 0], + boardId: OVERWORLD_BOARD_ID, + }; + + const castleAction = new CastleAction(kingPiece, targetPosition); + + // Act + const actionResult = castleAction.execute(); + + // Assert + expect(actionResult).toEqual(ActionResult.FAILURE); + }); + + test('Valid - Kingside Castling', () => { + // Arrange + const initialPosition: Position = { + coordinates: [4, 0], + boardId: OVERWORLD_BOARD_ID, + }; + const kingPiece = new King(whitePlayer, initialPosition); + const targetPosition: Position = { + coordinates: [6, 0], + boardId: OVERWORLD_BOARD_ID, + }; + + const castleAction = new CastleAction(kingPiece, targetPosition); + + // Act + const actionResult = castleAction.execute(); + + // Assert + expect(actionResult).toEqual(ActionResult.SUCCESS); + }); + + test('Valid - Queenside Castling', () => { + // Arrange + const initialPosition: Position = { + coordinates: [4, 0], + boardId: OVERWORLD_BOARD_ID, + }; + const kingPiece = new King(whitePlayer, initialPosition); + const targetPosition: Position = { + coordinates: [2, 0], + boardId: OVERWORLD_BOARD_ID, + }; + + const castleAction = new CastleAction(kingPiece, targetPosition); + + // Act + const actionResult = castleAction.execute(); + + // Assert + expect(actionResult).toEqual(ActionResult.SUCCESS); + }); +}); diff --git a/core/development/logic/actions/CastleAction.ts b/core/development/logic/actions/CastleAction.ts index 1f32d94..9a22e00 100644 --- a/core/development/logic/actions/CastleAction.ts +++ b/core/development/logic/actions/CastleAction.ts @@ -17,12 +17,16 @@ export class CastleAction implements GameAction { execute(): ActionResult { if (!this.piece.position) return ActionResult.FAILURE; + const targetXPosition = this.targetPosition.coordinates[0]; const kingXPosition = this.piece.position.coordinates[0]; const deltaX = targetXPosition - kingXPosition; const isKingsideCastling = deltaX > 0; - const rookPiece = (this.piece as King).getRookForCastling( + const isValidCastling = Math.abs(deltaX) == 2; + if (!isValidCastling) return ActionResult.FAILURE; + + const rookPiece = this.piece.getRookForCastling( this.piece.player, isKingsideCastling, ); diff --git a/core/development/logic/actions/KillPieceAction.test.ts b/core/development/logic/actions/KillPieceAction.test.ts new file mode 100644 index 0000000..e79ef36 --- /dev/null +++ b/core/development/logic/actions/KillPieceAction.test.ts @@ -0,0 +1,176 @@ +import { + HEAVEN_BOARD_ID, + HELL_BOARD_ID, + OVERWORLD_BOARD_ID, +} from '../../Constants'; +import { game } from '../../Game'; +import { PlayerInventory } from '../inventory/PlayerInventory'; +import { King } from '../pieces/King'; +import { Pawn } from '../pieces/Pawn'; +import { Position } from '../pieces/types/Position'; +import { Player } from '../players/Player'; +import { PlayerColor } from '../players/types/PlayerColor'; +import { KillPieceAction } from './KillPieceAction'; +import { PermanentlyKillPieceAction } from './PermanentlyKillPieceAction'; +import { SpawnPieceInHeavenAction } from './SpawnPieceInHeavenAction'; +import { SpawnPieceInHellAction } from './SpawnPieceInHellAction'; +import { ActionResult } from './types/ActionResult'; + +const whitePlayer = new Player(PlayerColor.WHITE, new PlayerInventory()); + +jest.mock('../../ui/BoardManager.ts', () => ({ + destroyElementOnBoard: jest.fn(), + moveElementOnBoard: jest.fn(), + getSquareElementById: jest.fn(), + spawnPieceElementOnBoard: jest.fn(), + getAllSquareElements: jest.fn(), + highlightLastMove: jest.fn(), +})); +jest.mock('../../ui/Screen.ts', () => ({ + renderGameInformation: jest.fn(), + hideUnicornAttackButton: jest.fn(), +})); +jest.mock('../../ui/logs/Logger.ts'); +jest.mock('../../ui/Events.ts', () => ({})); +jest.mock('../../ui/InventoriesUI.ts', () => ({ + initializeInventoryUI: jest.fn(), + switchShownInventory: jest.fn(), + showItemOnInventory: jest.fn(), +})); +jest.mock('../../ui/ShopUI.ts'); + +game.getPlayersTurnSwitcher = jest.fn().mockReturnValue({ + getCurrentPlayer: jest.fn().mockReturnValue(whitePlayer), + getTurnsCount: jest.fn().mockReturnValue(1), +}); + +jest.mock('./SpawnPieceInHellAction', () => ({ + __esModule: true, + SpawnPieceInHellAction: jest.fn().mockImplementation(() => ({ + execute: jest.fn().mockReturnValue(1), + })), +})); +jest.mock('./SpawnPieceInHeavenAction', () => ({ + __esModule: true, + SpawnPieceInHeavenAction: jest.fn().mockImplementation(() => ({ + execute: jest.fn().mockReturnValue(1), + })), +})); +jest.mock('./PermanentlyKillPieceAction', () => ({ + __esModule: true, + PermanentlyKillPieceAction: jest.fn().mockImplementation(() => ({ + execute: jest.fn().mockReturnValue(1), + })), +})); + +describe('KillPieceAction', () => { + afterEach(() => { + jest.clearAllMocks(); + }); + + test('should spawn piece in hell if killedPiece is on overworld board and is king', () => { + // Arrange + const initialPosition: Position = { + coordinates: [4, 0], + boardId: OVERWORLD_BOARD_ID, + }; + const killedPiece = new King(whitePlayer, initialPosition); + const killPieceAction = new KillPieceAction( + killedPiece, + OVERWORLD_BOARD_ID, + ); + + // Act + const actionResult = killPieceAction.execute(); + + // Assert + expect(actionResult).toEqual(ActionResult.SUCCESS); + expect(SpawnPieceInHellAction).toHaveBeenCalledWith(killedPiece); + expect(SpawnPieceInHellAction).toHaveBeenCalledTimes(1); + }); + + test('should spawn piece in hell if killedPiece is on overworld board and has killed another piece', () => { + // Arrange + const initialPosition: Position = { + coordinates: [4, 0], + boardId: OVERWORLD_BOARD_ID, + }; + const killedPiece = new Pawn(whitePlayer, initialPosition); + killedPiece.killCount = 1; + const killPieceAction = new KillPieceAction( + killedPiece, + OVERWORLD_BOARD_ID, + ); + + // Act + const actionResult = killPieceAction.execute(); + + // Assert + expect(actionResult).toEqual(ActionResult.SUCCESS); + expect(SpawnPieceInHellAction).toHaveBeenCalledWith(killedPiece); + expect(SpawnPieceInHellAction).toHaveBeenCalledTimes(1); + }); + + test('should spawn piece in heaven if killedPiece is on overworld board and has not killed another piece', () => { + // Arrange + const initialPosition: Position = { + coordinates: [4, 0], + boardId: OVERWORLD_BOARD_ID, + }; + const killedPiece = new Pawn(whitePlayer, initialPosition); + const killPieceAction = new KillPieceAction( + killedPiece, + OVERWORLD_BOARD_ID, + ); + + // Act + const actionResult = killPieceAction.execute(); + + // Assert + expect(actionResult).toEqual(ActionResult.SUCCESS); + expect(SpawnPieceInHeavenAction).toHaveBeenCalledWith(killedPiece); + expect(SpawnPieceInHeavenAction).toHaveBeenCalledTimes(1); + }); + + test('should permanently kill piece if killedPiece is on heaven board', () => { + // Arrange + const initialPosition: Position = { + coordinates: [4, 0], + boardId: HEAVEN_BOARD_ID, + }; + const killedPiece = new Pawn(whitePlayer, initialPosition); + const killPieceAction = new KillPieceAction( + killedPiece, + OVERWORLD_BOARD_ID, + ); + + // Act + const actionResult = killPieceAction.execute(); + + // Assert + expect(actionResult).toEqual(ActionResult.SUCCESS); + expect(PermanentlyKillPieceAction).toHaveBeenCalledWith(killedPiece); + expect(PermanentlyKillPieceAction).toHaveBeenCalledTimes(1); + }); + + test('should permanently kill piece if killedPiece is on hell board', () => { + // Arrange + const initialPosition: Position = { + coordinates: [4, 0], + boardId: HELL_BOARD_ID, + }; + const killedPiece = new Pawn(whitePlayer, initialPosition); + const killPieceAction = new KillPieceAction( + killedPiece, + OVERWORLD_BOARD_ID, + ); + + // Act + const actionResult = killPieceAction.execute(); + + // Assert + expect(actionResult).toEqual(ActionResult.SUCCESS); + expect(PermanentlyKillPieceAction).toHaveBeenCalledWith(killedPiece); + expect(PermanentlyKillPieceAction).toHaveBeenCalledTimes(1); + }); +}); diff --git a/core/development/logic/actions/KillPieceByEnvironmentAction.test.ts b/core/development/logic/actions/KillPieceByEnvironmentAction.test.ts new file mode 100644 index 0000000..3bae870 --- /dev/null +++ b/core/development/logic/actions/KillPieceByEnvironmentAction.test.ts @@ -0,0 +1,65 @@ +import { game } from '../../Game'; +import { PlayerInventory } from '../inventory/PlayerInventory'; +import { Pawn } from '../pieces/Pawn'; +import { Player } from '../players/Player'; +import { PlayerColor } from '../players/types/PlayerColor'; +import { KillPieceByEnvironmentAction } from './KillPieceByEnvironmentAction'; +import { ActionResult } from './types/ActionResult'; + +const whitePlayer = new Player(PlayerColor.WHITE, new PlayerInventory()); + +jest.mock('../../ui/BoardManager.ts', () => ({ + destroyElementOnBoard: jest.fn(), + moveElementOnBoard: jest.fn(), + getSquareElementById: jest.fn(), + spawnPieceElementOnBoard: jest.fn(), + getAllSquareElements: jest.fn(), + highlightLastMove: jest.fn(), +})); +jest.mock('../../ui/Screen.ts', () => ({ + renderGameInformation: jest.fn(), + hideUnicornAttackButton: jest.fn(), +})); +jest.mock('../../ui/logs/Logger.ts'); +jest.mock('../../ui/Events.ts', () => ({})); +jest.mock('../../ui/InventoriesUI.ts', () => ({ + initializeInventoryUI: jest.fn(), + switchShownInventory: jest.fn(), + showItemOnInventory: jest.fn(), +})); +jest.mock('../../ui/ShopUI.ts'); + +game.getPlayersTurnSwitcher = jest.fn().mockReturnValue({ + getCurrentPlayer: jest.fn().mockReturnValue(whitePlayer), + getTurnsCount: jest.fn().mockReturnValue(1), +}); +game.endMove = jest.fn(); + +jest.mock('./KillPieceAction', () => ({ + __esModule: true, + KillPieceAction: jest.fn().mockImplementation(() => ({ + execute: jest.fn().mockReturnValue(1), + })), +})); + +describe('KillPieceByEnvironmentAction', () => { + afterEach(() => { + jest.clearAllMocks(); + }); + + test('should return SUCCESS', () => { + // Arrange + const killedPiece = new Pawn(whitePlayer, undefined); + const killPieceByEnvironmentAction = new KillPieceByEnvironmentAction( + killedPiece, + 'cause', + killedPiece.position?.boardId, + ); + + // Act + const actionResult = killPieceByEnvironmentAction.execute(); + + // Assert + expect(actionResult).toEqual(ActionResult.SUCCESS); + }); +}); diff --git a/core/development/logic/actions/KillPieceByEnvironmentAction.ts b/core/development/logic/actions/KillPieceByEnvironmentAction.ts index 1a8d180..f4e192a 100644 --- a/core/development/logic/actions/KillPieceByEnvironmentAction.ts +++ b/core/development/logic/actions/KillPieceByEnvironmentAction.ts @@ -4,7 +4,7 @@ import { KillPieceAction } from './KillPieceAction'; import { KillLog } from '../../ui/logs/Log'; import { game } from '../../Game'; -export class KillPieceByEnvironment extends KillPieceAction { +export class KillPieceByEnvironmentAction extends KillPieceAction { private killingSource: string; constructor( diff --git a/core/development/logic/actions/KillPieceByFallingOffTheBoardAction.test.ts b/core/development/logic/actions/KillPieceByFallingOffTheBoardAction.test.ts new file mode 100644 index 0000000..ac0c8bf --- /dev/null +++ b/core/development/logic/actions/KillPieceByFallingOffTheBoardAction.test.ts @@ -0,0 +1,89 @@ +import { OVERWORLD_BOARD_ID, VOID_BOARD_ID } from '../../Constants'; +import { game } from '../../Game'; +import { PlayerInventory } from '../inventory/PlayerInventory'; +import { Pawn } from '../pieces/Pawn'; +import { BasePiece } from '../pieces/abstract/BasePiece'; +import { Position } from '../pieces/types/Position'; +import { Player } from '../players/Player'; +import { PlayerColor } from '../players/types/PlayerColor'; +import { KillPieceByEnvironmentAction } from './KillPieceByEnvironmentAction'; +import { KillPieceByFallingOffTheBoardAction } from './KillPieceByFallingOffTheBoardAction'; +import { ActionResult } from './types/ActionResult'; + +const whitePlayer = new Player(PlayerColor.WHITE, new PlayerInventory()); + +jest.mock('../../ui/BoardManager.ts', () => ({ + destroyElementOnBoard: jest.fn(), + moveElementOnBoard: jest.fn(), + getSquareElementById: jest.fn(), + spawnPieceElementOnBoard: jest.fn(), + getAllSquareElements: jest.fn(), + highlightLastMove: jest.fn(), +})); +jest.mock('../../ui/Screen.ts', () => ({ + renderGameInformation: jest.fn(), + hideUnicornAttackButton: jest.fn(), +})); +jest.mock('../../ui/logs/Logger.ts'); +jest.mock('../../ui/Events.ts', () => ({})); +jest.mock('../../ui/InventoriesUI.ts', () => ({ + initializeInventoryUI: jest.fn(), + switchShownInventory: jest.fn(), + showItemOnInventory: jest.fn(), +})); +jest.mock('../../ui/ShopUI.ts'); + +game.getPlayersTurnSwitcher = jest.fn().mockReturnValue({ + getCurrentPlayer: jest.fn().mockReturnValue(whitePlayer), + getTurnsCount: jest.fn().mockReturnValue(1), +}); + +jest.mock('./KillPieceByEnvironmentAction', () => ({ + __esModule: true, + KillPieceByEnvironmentAction: jest + .fn() + .mockImplementation((killedPiece: BasePiece) => ({ + execute: jest + .fn() + .mockReturnValueOnce( + killedPiece.position ? ActionResult.SUCCESS : ActionResult.FAILURE, + ), + })), +})); + +describe('KillPieceByFallingOffTheBoardAction', () => { + afterEach(() => { + jest.clearAllMocks(); + }); + + test('should return FAILURE if killedPiece.position is undefined', () => { + // Arrange + const killedPiece = new Pawn(whitePlayer, undefined); + const killPieceByFallingOffTheBoardAction = + new KillPieceByFallingOffTheBoardAction(killedPiece); + + // Act + const actionResult = killPieceByFallingOffTheBoardAction.execute(); + + // Assert + expect(actionResult).toEqual(ActionResult.FAILURE); + }); + + test('should call super.execute() if killedPiece.position exists', () => { + // Arrange + const initialPosition: Position = { + coordinates: [4, 0], + boardId: OVERWORLD_BOARD_ID, + }; + const killedPiece = new Pawn(whitePlayer, initialPosition); + const killPieceByFallingOffTheBoardAction = + new KillPieceByFallingOffTheBoardAction(killedPiece); + + // Act + const actionResult = killPieceByFallingOffTheBoardAction.execute(); + + // Assert + expect(actionResult).toEqual(ActionResult.SUCCESS); + expect(KillPieceByEnvironmentAction).toHaveBeenCalledTimes(1); + }); +}); diff --git a/core/development/logic/actions/KillPieceByFallingOffTheBoardAction.ts b/core/development/logic/actions/KillPieceByFallingOffTheBoardAction.ts index 9dc3ea0..0fb6565 100644 --- a/core/development/logic/actions/KillPieceByFallingOffTheBoardAction.ts +++ b/core/development/logic/actions/KillPieceByFallingOffTheBoardAction.ts @@ -1,8 +1,8 @@ import { VOID_BOARD_ID } from '../../Constants'; import { BasePiece } from '../pieces/abstract/BasePiece'; -import { KillPieceByEnvironment } from './KillPieceByEnvironmentAction'; +import { KillPieceByEnvironmentAction } from './KillPieceByEnvironmentAction'; import { ActionResult } from './types/ActionResult'; -export class KillPieceByFallingOffTheBoardAction extends KillPieceByEnvironment { +export class KillPieceByFallingOffTheBoardAction extends KillPieceByEnvironmentAction { constructor(killedPiece: BasePiece) { super(killedPiece, 'the void', killedPiece.position?.boardId); } diff --git a/core/development/logic/actions/TriggerPieceOnTrapAction.ts b/core/development/logic/actions/TriggerPieceOnTrapAction.ts index 95b1c8e..ce5e2b0 100644 --- a/core/development/logic/actions/TriggerPieceOnTrapAction.ts +++ b/core/development/logic/actions/TriggerPieceOnTrapAction.ts @@ -3,7 +3,7 @@ import { destroyItemOnBoard } from '../../LogicAdapter'; import { move } from '../PieceLogic'; import { BaseItem } from '../items/abstract/Item'; import { BasePiece } from '../pieces/abstract/BasePiece'; -import { KillPieceByEnvironment as KillPieceByEnvironmentAction } from './KillPieceByEnvironmentAction'; +import { KillPieceByEnvironmentAction as KillPieceByEnvironmentAction } from './KillPieceByEnvironmentAction'; import { GameAction } from './abstract/GameAction'; import { ActionResult } from './types/ActionResult'; diff --git a/core/development/logic/pieces/King.ts b/core/development/logic/pieces/King.ts index 21786eb..ebfb712 100644 --- a/core/development/logic/pieces/King.ts +++ b/core/development/logic/pieces/King.ts @@ -15,21 +15,23 @@ export class King extends BasePiece { } getRookForCastling(player: Player, kingside: boolean): Rook | undefined { - const rank = player.color === PlayerColor.WHITE ? 0 : 7; + const rank = player.color === PlayerColor.WHITE ? 7 : 0; if (!this.position) return; if (kingside) { // Kingside castling + const kingsideCastlingRookXCoordinate = 7; const kingsideRookPosition: Position = { - coordinates: [7, rank], + coordinates: [kingsideCastlingRookXCoordinate, rank], boardId: this.position.boardId, }; return getPieceByPosition(kingsideRookPosition) as Rook | undefined; } else { // Queenside castling + const queensideCastlingRookXCoordinate = 0; const queensideRookPosition: Position = { - coordinates: [0, rank], + coordinates: [queensideCastlingRookXCoordinate, rank], boardId: this.position.boardId, }; diff --git a/jest.config.ts b/jest.config.ts index 86e6596..b2853e5 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -2,7 +2,6 @@ export default { displayName: 'chess-but-better', coverageDirectory: 'test-coverage', - coverageReporters: ['lcov'], preset: 'ts-jest', testEnvironment: 'node', testMatch: ['/core/**/*.test.ts'],