From 77c58eae1eb372ea9105776c91d91bbef3598bd6 Mon Sep 17 00:00:00 2001 From: Cozma Rares Date: Mon, 1 May 2023 01:41:33 +0300 Subject: [PATCH] feat: generate moves based on turn --- server/src/__test__/isSquareAttacked.test.ts | 11 ++++------- server/src/chess/engine.ts | 2 +- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/server/src/__test__/isSquareAttacked.test.ts b/server/src/__test__/isSquareAttacked.test.ts index 6a19c23..85c629a 100644 --- a/server/src/__test__/isSquareAttacked.test.ts +++ b/server/src/__test__/isSquareAttacked.test.ts @@ -1,15 +1,12 @@ -import { test, expect } from "vitest"; +import { expect, test } from "vitest"; import Chess from "../chess/engine"; -const chess = Chess.load(); +test("", () => { + const chess = Chess.load(); -test("e4 attacked", () => { expect(chess.isSquareAttacked("e4", "w")).toBe(true); expect(chess.isSquareAttacked("e4", "b")).toBe(false); -}); -test("e5 attacked", () => { expect(chess.isSquareAttacked("e5", "w")).toBe(false); - expect(chess.isSquareAttacked("e5", "b")).toBe(true); + expect(chess.isSquareAttacked("e5", "b")).toBe(false); }); - diff --git a/server/src/chess/engine.ts b/server/src/chess/engine.ts index ee360b1..91af395 100644 --- a/server/src/chess/engine.ts +++ b/server/src/chess/engine.ts @@ -672,7 +672,7 @@ export default class Chess { const piece = this.getPiece(square); - if (piece == null) return []; + if (piece == null || piece.color != this._turn) return []; const moves = generatePieceMoves(this._board, square, piece);