Skip to main content

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 has a client which supports multiplayer, singleplayer and bot chess matches!

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

plazma_chess-1.2.0.tar.gz (9.2 kB view hashes)

Uploaded Source

Built Distribution

plazma_chess-1.2.0-py3-none-any.whl (10.8 kB view hashes)

Uploaded Python 3

Supported by

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