All Projects → RuolinZheng08 → renpy-chess

RuolinZheng08 / renpy-chess

Licence: MIT license
A chess GUI built with Ren'Py, python-chess, and Stockfish. Version 2.0 of https://github.com/RuolinZheng08/renpy-chess-engine

Programming Languages

python
139335 projects - #7 most used programming language
Ren'Py
26 projects

Projects that are alternatives of or similar to renpy-chess

OpenChess
A cross-platform chess game.
Stars: ✭ 18 (-50%)
Mutual labels:  chess-engine, chess, chess-game
stockfish-chess-web-gui
Responsive chess web GUI to play against the Stockfish 10 chess engine. Multiple web GUI implementations have also been included.
Stars: ✭ 21 (-41.67%)
Mutual labels:  chess-engine, chess, chess-game
uci
A thin wrapper on a uci chess engine
Stars: ✭ 33 (-8.33%)
Mutual labels:  chess-engine, chess
zahak
A UCI compatible chess AI in Go
Stars: ✭ 20 (-44.44%)
Mutual labels:  chess-engine, chess
rustic
Rustic is a chess engine. It is written from scratch, in the Rust programming language.
Stars: ✭ 68 (+88.89%)
Mutual labels:  chess-engine, chess
liground
A free, open-source and modern Chess Variant Analysis GUI for the 21st century
Stars: ✭ 41 (+13.89%)
Mutual labels:  chess-engine, chess
bot-o-tron
Try out lichess' bot interface
Stars: ✭ 36 (+0%)
Mutual labels:  chess-engine, chess
ConvChess
Convolutional Neural Networks learns to play chess moves
Stars: ✭ 14 (-61.11%)
Mutual labels:  chess-engine, chess
Realtime-OpenCV-Chess
♔ Chess-playing with Open-CV [Human vs AI (Stockfish engine)]
Stars: ✭ 18 (-50%)
Mutual labels:  chess-engine, chess
Zerofish
An implementation of the AlphaZero algorithm for chess
Stars: ✭ 34 (-5.56%)
Mutual labels:  chess-engine, chess
Sunfish
Sunfish: a Python Chess Engine in 111 lines of code
Stars: ✭ 2,254 (+6161.11%)
Mutual labels:  chess-engine, chess
elephantfish
elephantfish: 一个只有124行的中国象棋引擎
Stars: ✭ 129 (+258.33%)
Mutual labels:  chess-engine, chess
littlewing
Chess engine written in Rust ♛
Stars: ✭ 27 (-25%)
Mutual labels:  chess-engine, chess
Demolito
UCI Chess Engine
Stars: ✭ 41 (+13.89%)
Mutual labels:  chess-engine, chess
magic-bits
A C++ header-only library for efficient move generation in Chess using "magic bitboards" technique
Stars: ✭ 26 (-27.78%)
Mutual labels:  chess-engine, chess
Bit-Genie
UCI chess engine in C++
Stars: ✭ 19 (-47.22%)
Mutual labels:  chess-engine, chess
blitz-tactics
Fast-paced chess tactics trainer
Stars: ✭ 137 (+280.56%)
Mutual labels:  chess, chess-game
leanchess
The world's smallest chess program
Stars: ✭ 71 (+97.22%)
Mutual labels:  chess, chess-game
Walleye
A chess engine written from scratch in Rust ♞
Stars: ✭ 82 (+127.78%)
Mutual labels:  chess-engine, chess
fastchess
Predicts the best chess move with 27.5% accuracy by a single matrix multiplication
Stars: ✭ 75 (+108.33%)
Mutual labels:  chess-engine, chess

Ren'Py Chess Engine 2.0

Play it now on itch.io or watch a YouTube demo

About

This is a chess GUI built with the Ren'Py Visual Novel Engine, python-chess, and Stockfish (for chess AI). You can use it as a standalone playable or integrate it as a minigame into a Ren'Py visual novel project. Read the guide for integration below.

Compatibility

This chess engine supports Ren'Py SDK >= 7.4.0. It is not backward compatible with Ren'Py SDK <= 7.3.5 due to reasons described in this GitHub issue. See the renpy-7.3.5 branch for an old version that is compatible with Ren'Py SDK 7.3.5.

Gameplay Example: Fool's Mate

Gameplay Example

Differences between Ren'Py Chess 1.0 and Ren'Py Chess 2.0

Pros Cons
Ren'Py Chess 1.0
  • Has no Python package dependency hence supports any OS: Windows, Mac, Linux, Android, iOS, and even Web browser-play
  • Does not support en passant, castling, or promotion
  • Does not support claiming a draw for the threefold repetition or the fifty-move rule
  • Player can only play as White in Player vs. Computer
  • Uses a chess AI of minimal implementation with no support for customizing the strength of the AI
Ren'Py Chess 2.0 (This project)
  • Has full support for en passant and castling, plus a special UI for promotion
  • Has full support and a special UI for claiming a draw for the threefold repetition or the fifty-move rule
  • Supports flipping board view
  • Uses Stockfish and supports customization of the strength (thinking time, depth) of the chess AI
  • Only tested on Mac and Windows. Does not support iOS or Web. If you are on other OS (Linux, Android) and encounter a problem, please submit a GitHub issue

Gameplay

The game supports Player vs. Player and Player vs. Computer. In PvC, player can choose to play as either Black or White.

Click on a piece and all of its available moves will be highlighted. Click on any of the legal destination squares to make a move. Press Flip board view to flip the view, with White on the bottom by default.

Feature List

  • PvP and PvC
  • Flip board view
  • Resign
  • Undo moves

Player vs. Computer (Stockfish)

Play vs Computer

Flip Board View, Undo Moves, Resign

Flip Board

Promotion UI

Promotion

Threefold Repetition: UI for Claiming a Draw

(Also shows a similar UI choice screen if the fifty-move rule is in effect) Threefold Repetition

Guide for Integrating into a Ren'Py Project

All of the files essential to the chess engine are in game/00-chess-engine. Therefore, you only need to copy the entire 00-chess-engine into your Ren'Py game directory.

The chess game is full-screen when the screen resolution is 1280x720, but is customizable to fit any screen sizes, as described in subsequent sections.

Structure of 00-chess-engine

00-chess-engine/
    - audio                         # chess game sound effects
    - bin                           # chess AI Stockfish binaries
    - images                        # chess board and piece images
    - python-packages               # Python libraries
    - chess_displayable.rpy         # core GUI class
    - chess_subprocess.py           # core logic class

The core GUI class is a Ren'Py Creator-Defined Displayable named ChessDisplayable inside 00-chess-engine/chess_displayable.rpy. You can customize anything stylistic in chess_displayable.rpy, as described below in more details.

00-chess-engine/chess_subprocess.py is the underlying chess engine. Creating an instance of ChessDisplayable will launch chess_subprocess.py as a subprocess. You can make logical changes in chess_subprocess.py for your specific use cases if you are comfortable with subprocess programming.

In your Ren'Py script, for example, script.rpy, pass the following configuration variables for the chess engine to the chess screen defined as screen chess(fen, player_color, movetime, depth):

  • fen: the Forsyth–Edwards Notation of the board
  • player_color: None for PvP. For PvC, chess.WHITE or chess.BLACK.
  • movetime: None for PvP. For PvC, between 0 and MAX_MOVETIME = 3000 milliseconds.
  • depth: None for PvP. For PvC, between 0 and MAX_DEPTH = 20.

To call the chess displayable screen: (Also see the game/script.rpy file in this repo.)

define e = Character("Eileen")

window hide
$ quick_menu = False
# avoid rolling back and losing chess game state
$ renpy.block_rollback()

# launches an easy-level PvC where player plays as white
$ fen = 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1'
call screen chess(fen=fen, player_color=WHITE, movetime=2000, depth=2)

# avoid rolling back and entering the chess game again
$ renpy.block_rollback()
# restore rollback from this point on
$ renpy.checkpoint()
$ quick_menu = True
window show

if _return == DRAW:
    e "The game ended in a draw."
else: # RESIGN or CHECKMATE
    $ winner = "White" if _return == WHITE else "Black"
    e "The winner is [winner]."
    if player_color is not None: # PvC
        if _return == player_color:
            e "Congratulations, player!"
        else:
            e "Better luck next time, player."

Customizations for Different Difficulty Levels

The strength of the compuer player can be customized by setting the depth parameter between the range of 1 and 20, with a larger number indicating more strength. See Stockfish depth to ELO conversion.

Customizations for Different Screen Sizes, Colors, Styles, and Audios

Override the defaults in chess_displayable.rpy and replace the default chess piece and chess board images, or, audio files in 00-chess-engine/images and 00-chess-engine/audio.

# directory paths
# the path of the current directory within game/
define THIS_PATH = '00-chess-engine/'
define IMAGE_PATH = 'images/'
define AUDIO_PATH = 'audio/'
define BIN_PATH = 'bin/' # stockfish binaries
define CHESSPIECES_PATH = THIS_PATH + IMAGE_PATH + 'chesspieces/'

# file paths
define IMG_CHESSBOARD = THIS_PATH + IMAGE_PATH + 'chessboard.png'
define AUDIO_MOVE = THIS_PATH + AUDIO_PATH + 'move.wav'
define AUDIO_CAPTURE = THIS_PATH + AUDIO_PATH + 'capture.wav'
define AUDIO_PROMOTION = THIS_PATH + AUDIO_PATH + 'promotion.wav'
define AUDIO_CHECK = THIS_PATH + AUDIO_PATH + 'check.wav'
define AUDIO_CHECKMATE = THIS_PATH + AUDIO_PATH + 'checkmate.wav'
define AUDIO_DRAW = THIS_PATH + AUDIO_PATH + 'draw.wav' # used for resign, stalemate, threefold, fifty-move
define AUDIO_FLIP_BOARD = THIS_PATH + AUDIO_PATH + 'flip_board.wav'

# this chess game is full-screen when the game resolution is 1280x720
define CHESS_SCREEN_WIDTH = 1280
define CHESS_SCREEN_HEIGHT = 720

# use loc to mean UI square and distinguish from logical square
define LOC_LEN = 90 # length of one side of a loc

define COLOR_HOVER = '#90ee90aa' # HTML LightGreen
define COLOR_SELECTED = '#40e0d0aa' # Turquoise
define COLOR_LEGAL_DST = '#afeeeeaa' # PaleTurquoise
define COLOR_PREV_MOVE = '#6a5acdaa' # SlateBlue
define COLOR_WHITE = '#fff'

Continuous Development

The project is under active maintenance and you can view its development status on this public Trello board. Please feel free to submit a GitHub issue for bugs and feature requests. I have helped to integrate this chess engine into an in-development kinetic novel, The Wind at Dawn.

Contribution

Please feel free to submit GitHub issues and PRs. You are also more than welcome to join the Trello board if you are interested.

Asset Credits

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].