No project description provided
Project description
Plazma Chess Engine
In development!
This is a basic chess engine based off of the python-chess library
The engine comes with a client which supports multiplayer, singleplayer and bot chess matches!
Try running python example.py
to test the engine or just play with friends
Documentation
Setting up the board
import engine # Import the plazma-chess module
chessEngine = engine.Engine() # Create instance of the Engine class
This will initialize the engine class which contains all of the information of the board. All pieces will be set to normal chess starting positions.
Acessing the board
import engine # Import the plazma-chess module
chessEngine = engine.Engine() # Create instance of the Engine class
print(chessEngine.board.board) # Access the board class stored in the engine class and get the board list
# Example output of starting positions
"""[[10, 8, 9, 11, 12, 9, 8, 10],
[7, 7, 7, 7, 7, 7, 7, 7],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[1, 1, 1, 1, 1, 1, 1, 1],
[4, 2, 3, 5, 6, 3, 2, 4]]"""
To Access the board class, and the board list within that you need to use the engine class. This is because when the engine class is initialized it also initializes the board.
Generating moves
import engine # Import the plazma-chess module
chessEngine = engine.Engine() # Create instance of the Engine class
legalMoves = chessEngine.generateMoves((4, 6)) # Get the legal moves for the kings pawn
To get the legal moves for a piece you just need to specify the coordinates of the piece and call the generateMoves
function in the engine class, passing in those coordinates.
Finding pieces
import engine # Import the plazma-chess module
chessEngine = engine.Engine() # Create instance of the Engine class
pos = any_pieces_position
print(chessEngine.board.pieceAt(pos)) # Call the 'pieceAt' function in the board
# Prints:
# bool -> Found a piece
# int -> Piece value (0 if no piece)
To check if a piece is on a specific part of the board you can either access the board list manually or use the pieceAt
function in the board class.
Moving pieces
import engine # Import the plazma-chess module
chessEngine = engine.Engine() # Create instance of the Engine class
pos = current_piece_position
newPos = new_piece_position
status = chessEngine.move(pos, newPos) # Call the move function in the engine
# If status = 0 the move was successfull.
# If status = 1 the move ended in checkmate.
# If an Illegal Move error surfaces the move was unsuccessfull.
To move pieces simply call the move function in the engine class. It will not allow illegal moves to be played and it uses the same generateMoves
function to validate moves.
Neither the generateMoves
function or the move
function will return moves that may result in a check.
Bots
Bot support is not fully implemented yet so creating bots requires a little more work than expected.
Generating moves is a little easier thanks to the individual move generation functions.
These include:
generatePawnMoves
generateKnightMoves
generateSlidingMoves
generateDiagonalMoves
generateKingMoves
This allows you to generate moves with more speciallity and presicion.
These functions all take the same argument, pos
which defines the piece position.
These functions do not take checks into account so illegal move errors are a risk.
You can remedy this by using the inCheck
function which takes a turn
argument and and optional square
argument which is used to check for a specific piece. It returns True
or False
if the king is in check.
To bypass the check detection there is a function called __moveWithoutCheck
. This function is dangerous as it defies the rules of chess. It should only be used for move generation in bots which will garrentee faster move generation.
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
Built Distribution
Hashes for plazma_chess-1.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dfe20f32a9a29a97758800ac19dc1b033b6d77593ebc138b0dd33d52f116995d |
|
MD5 | 66d5b189dc81a69a6e8d4161ae2e6621 |
|
BLAKE2b-256 | 509a1fd1e74966710c112404e6710ca93530395f5164611117ed62ae72598f61 |