Skip to main content

This is ultimate library to create your own chess simulator!

Project description

OOPChess

A Python chess library built with object-oriented programming principles. Provides a board representation, piece classes, and movement logic as a reusable package.

Project Structure

OOPChess/
в”њв”Ђв”Ђ main.py              # Entry point / usage example
в”њв”Ђв”Ђ setup.py             # Package setup
в”њв”Ђв”Ђ setup.cfg
в””в”Ђв”Ђ ChessLib/
    в”њв”Ђв”Ђ __init__.py      # Public package exports
    в”њв”Ђв”Ђ chess_unit.py    # Base class for all pieces
    в”њв”Ђв”Ђ chess_table.py   # Chess board logic
    в”њв”Ђв”Ђ rock.py          # Rook piece
    в”њв”Ђв”Ђ bishop.py        # Bishop piece
    в”њв”Ђв”Ђ knight.py        # Knight piece
    в”њв”Ђв”Ђ king.py          # King piece
    в”њв”Ђв”Ђ queen.py         # Queen piece
    в””в”Ђв”Ђ pawn.py          # Pawn piece

Requirements

  • Python 3.10+ (uses match/case syntax)

No external dependencies.

Installation

Clone the repository and install the package locally:

git clone https://github.com/Salmon-bit/OOPChess
cd OOPChess
pip install -e .

Or just use ChessLib directly by placing it next to your script.

Quick Start

from ChessLib.chess_table import ChessTable

# Create a new board with pieces in starting positions
board = ChessTable()
print(board)

# Get a piece at a position (row, col) — 0-indexed, top-left is (0, 0)
piece = board.get_unit((7, 1))  # White Knight
print(piece)  # White Knight at b-1.

# Move a piece
board.move_unit((7, 1), (5, 2))
print(board)

Board output example

+---+---+---+---+---+---+---+---+---+
| 8 | R | K | B | Q | + | B | K | R |
| 7 | P | P | P | P | P | P | P | P |
| 6 | в€™ | в€™ | в€™ | в€™ | в€™ | в€™ | в€™ | в€™ |
| 5 | в€™ | в€™ | в€™ | в€™ | в€™ | в€™ | в€™ | в€™ |
| 4 | в€™ | в€™ | в€™ | в€™ | в€™ | в€™ | в€™ | в€™ |
| 3 | в€™ | в€™ | в€™ | в€™ | в€™ | в€™ | в€™ | в€™ |
| 2 | P | P | P | P | P | P | P | P |
| 1 | R | K | B | Q | + | B | K | R |
+---+---+---+---+---+---+---+---+---+
| x | a | b | c | d | e | f | g | h |
+---+---+---+---+---+---+---+---+---+

Piece symbols: R = Rook, K = Knight, B = Bishop, Q = Queen, + = King, P = Pawn

API Reference

ChessTable

The main board class.

Method Description
__init__() Creates a new board with pieces in standard starting positions
get_unit(position) Returns the piece at (row, col), or None if empty
set_unit(position, piece) Places a piece (or None) at a position
move_unit(position, destination) Moves a piece from one square to another
get_list() Returns the full board as a list[list]

ChessUnit (base class for all pieces)

All piece classes (Rock, Bishop, Knight, King, Queen, Pawn) inherit from ChessUnit.

Method Description
__init__(pos, side) pos is (row, col), side is 'white' or 'black'
get_pos() Returns current position as (row, col)
convert_pos() Converts position to chess notation, e.g. ('b', 1)
check_available(dest, map) Returns True if the destination square is empty
goto(dest, map) Moves the piece to dest if available
map_view() Returns the single-character board symbol for the piece

Coordinate system

Positions use (row, col) tuples, 0-indexed from the top-left:

  • (0, 0) = top-left = a8 (black's back rank)
  • (7, 7) = bottom-right = h1 (white's back rank)

Extending with a new piece

Subclass ChessUnit and implement map_view():

from .chess_unit import ChessUnit

class MyPiece(ChessUnit):
    def __init__(self, pos, side):
        super().__init__(pos, side)

    def map_view(self) -> str:
        return 'M'  # Symbol shown on the board

Then add it to chess_table.py imports and __init__.py exports.

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

ultimate_chesslib-0.0.1.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

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

ultimate_chesslib-0.0.1-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file ultimate_chesslib-0.0.1.tar.gz.

File metadata

  • Download URL: ultimate_chesslib-0.0.1.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for ultimate_chesslib-0.0.1.tar.gz
Algorithm Hash digest
SHA256 4bbc1c4beb5805feebfde61daa3d26e1282bb0f717aa58e336b2819783a8af02
MD5 c3c91cab8272c1135e106786d9618f97
BLAKE2b-256 1d79e45289cc169c7bcd29580fb5e3806ad715bf045286b94f835c0c57c30d5e

See more details on using hashes here.

File details

Details for the file ultimate_chesslib-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for ultimate_chesslib-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d7fd9e8e88b8a2de9754ff9b8ed25965f8fcf07f205b57222d548d01d87554a2
MD5 afc085a5833288ce7ecf76950cd571e4
BLAKE2b-256 7af47b937a64ffdaf0df9f30d36474b81d9f8945d817361a89896010806536d4

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