feat: generate moves based on turn
This commit is contained in:
@@ -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);
|
||||
});
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user