Add rules-engine tests: check, mate, stalemate, castling, en passant, undo

Đang mở
#41 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
48/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
javascript
Lĩnh vực
testing-qa

Hướng nghiên cứu

Read tests/unit/game-moves.test.js and tests/integration/game-flow.test.js, then inspect the named move and piece logic in js/game.js and js/pieces.js. Start with the helper from issue #40 and run npm test; the issue lists the expected rule cases and outcomes. Done means every listed case has a test and forcing isCheckmate to return false makes the suite fail.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

severity: medium testing

Summary

The suite has four tests, and the only two that touch game logic both play e2 to e4. Check, checkmate, stalemate, castling, en passant, promotion, pins, notation and undo are untested.

Where

  • tests/unit/game-moves.test.js:111-116, tests/integration/game-flow.test.js:118-126
  • Untested: js/game.js:281-300, js/game.js:334-461, js/game.js:497-520, js/game.js:582-650, js/game.js:845-906, js/pieces.js:41-96

Impact

js/game.js is about a third of the code base and is the product. Regressions in move legality or game-end detection ship with CI green, which has already happened (#22, #24, #25).

Suggested fix

Using the helper from #40, add:

  • Perft from the start position: White has 20 legal moves; after 1.e4, Black has 20
  • isPseudoLegalMove table tests per piece: knight L-shapes, bishop off-diagonal rejected, pawn backward rejected, double push only from the start rank, same square rejected
  • Sliders are blocked by own and enemy pieces
  • A pinned piece has no moves that expose the king (white Ke1, Re2, black Re8)
  • In check, only moves that resolve it are legal
  • Fool's mate (f3 e5 g4 Qh4): status "Checkmate! Black wins.", notation Qh4#
  • Stalemate (white Kf7, Qg6, black Kh8, Black to move): status "Stalemate! Game is a draw."
  • Castling: allowed both sides when clear; refused in check, through an attacked square, after the king or rook moved, with a piece between; notation O-O and O-O-O
  • Queenside castling with only the b-file square attacked is allowed
  • En passant: offered only right after the double push, removes the captured pawn, not offered when it exposes the king
  • Promotion: h7 to h8 becomes a queen, notation h8=Q
  • SAN disambiguation: Nbd2 for two knights, R1a3 for two rooks on one file
  • Undo after a plain move, a capture, castling, en passant, a double push and a promotion restores the exact prior state
  • handleBoardClick ignores the opponent's pieces and all clicks after game over

Some of these should fail until the linked bugs are fixed; write them to the chess rule.

Acceptance criteria

  • Each item above has a test
  • Making isCheckmate return false unconditionally fails the suite

Getting started

  • Relevant files: js/game.js, js/pieces.js, tests/unit/
  • How to run tests: npm install, then npm test and npm run lint
  • Related docs: docs/ARCHITECTURE.md, .github/CONTRIBUTING.md

Filed by repo-audit/full-audit at 8a2c86c. Severity: medium. Effort: M. audit-key: testing|js/game.js|generateLegalMovesForPiece

Ngôn ngữ chính
JavaScript
Star
4
Fork
2
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của TMHSDigital/Static_Chess

Tất cả issue của TMHSDigital/Static_Chess

Issue tương tự

Thêm issue về JavaScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.