Skip to content

stonedchess/engine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

56 Commits
 
 
 
 
 
 
 
 

Repository files navigation

stonedchess - engine

Usage

Must be used as a python module. We recommend git submodules to do such.

Example usage

from stonedchess.board import Board
from stonedchess.piece import std
from stonedchess.position import Position
from stonedchess.render import render

board = Board(Position(20, 5)).add(
    (2, 2, std.Knight()),
)

moves = board.moves(Position(2, 2))
print(render(board, moves))

# +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
# |   |.  |   |.  |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |
# +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
# |.  |   |   |   |.  |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |
# +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
# |   |   |  |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |
# +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
# |.  |   |   |   |.  |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |
# +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
# |   |.  |   |.  |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |
# +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+

Make custom pieces

# Let's make a Knight

from stonedchess.movement import Direction, Movement
from stonedchess.piece import Piece

class Knight(Piece):
    """My really custom knight"""

    # Defining piece movement
    movement = Movement().split(
        Movement(jumps=True)
        .walk(Direction.N, amount=2)
        .split(
            Movement().walk(Direction.E),
            Movement().walk(Direction.W),
        ),
        Movement(jumps=True)
        .walk(Direction.S, amount=2)
        .split(
            Movement().walk(Direction.E),
            Movement().walk(Direction.W),
        ),
        Movement(jumps=True)
        .walk(Direction.W, amount=2)
        .split(
            Movement().walk(Direction.N),
            Movement().walk(Direction.S),
        ),
        Movement(jumps=True)
        .walk(Direction.E, amount=2)
        .split(
            Movement().walk(Direction.N),
            Movement().walk(Direction.S),
        ),
    )

Movement directives

# Walk stright for n cells
Movement().walk(direction: Direction, amount: int, extend: bool)

# Split path
Movement().split(*branches: Movement)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages