Skip to main content

A 4x4 Chess library (King + Rook vs King) with move validation and win/draw detection

Project description

Here’s your updated documentation in Markdown, including the intro you provided at the top:

# Chess4x4

A **4x4 Chess Library** written in Python.  
Currently supports the classic endgame scenario **White King + Rook vs Black King** on a 4x4 chessboard.  

---

## ✨ Features
- 4x4 chessboard
- Custom starting positions
- Supports **King** and **Rook**
- Generate all possible moves
- Make legal moves
- Detect **win** (capturing opponent King)
- Detect **draw** (only two Kings left)
- Turn-based play (White starts)

---

## 📦 Installation

```bash
pip install chess4x4

🚀 Quick Start

from chess4x4 import Chess4x4, King, Rook

# Initialize game
game = Chess4x4()

# Print the board
print(game.board)

# Generate moves for White King
moves = game.board.get_piece_moves((0, 0))
print("White King moves:", moves)

# Make a move
game.make_move((0, 0), (1, 0))

# Check status
print("Game over:", game.is_game_over())

📖 API Documentation

Classes

Chess4x4

  • make_move(start: tuple[int, int], end: tuple[int, int]) -> bool Make a move if legal. Returns True if successful.
  • is_game_over() -> bool Returns True if the game has ended.
  • winner() -> str | None Returns "White", "Black", or None.

Board

  • get_piece_moves(position: tuple[int, int]) -> list[tuple[int, int]] Generate all legal moves for a piece.
  • move_piece(start, end) -> bool Move a piece if valid.

Pieces

  • King(color: str, position: tuple[int, int])
  • Rook(color: str, position: tuple[int, int])

🧪 Testing

Run tests with:

pytest tests/

🤝 Contributing

We welcome contributions!

  1. Fork the repo

  2. Create a new branch

    git checkout -b feature-name
    
  3. Commit your changes

    git commit -m "Added feature X"
    
  4. Push to your branch

    git push origin feature-name
    
  5. Create a Pull Request 🎉

Please make sure:

  • Code is well-documented
  • All tests pass
  • Follow the existing coding style

📜 License

This project is licensed under the MIT License.


Do you want me to also create a **separate `CONTRIBUTING.md` file** with contribution guidelines, or keep it inside the main documentation only?

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

chess4x4-0.1.2.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

chess4x4-0.1.2-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file chess4x4-0.1.2.tar.gz.

File metadata

  • Download URL: chess4x4-0.1.2.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for chess4x4-0.1.2.tar.gz
Algorithm Hash digest
SHA256 de3b423e4c0afdea985ef88332d35a6c5193e138b14358e4854b4f298092afdd
MD5 b812f5327be2de08143f6269a498ed0d
BLAKE2b-256 f59457f33ff7a3ccefd9c958ed9e5b768bc3c87c3eb85011b26ffda192c15187

See more details on using hashes here.

File details

Details for the file chess4x4-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: chess4x4-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 6.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for chess4x4-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 16b41d572831b7928a7d893c37e0959b9dda61c5bce236714665aee6e3662f78
MD5 849800c78dd4168330d8b6cb62efebd7
BLAKE2b-256 ff7333830e56e7f11c1e0c6a88a50c516f98e0c463478bd6c2e1b4f4b71a5175

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page