Play it now on itch.io or watch a YouTube demo
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.
This chess engine supports Ren'Py 8. It is not backward compatible with Ren'Py 7. See the other branches (ex. renpy-7.4
, renpy-7.3.5
for older Ren'Py versions)
Pros | Cons | |
---|---|---|
Ren'Py Chess 1.0 |
|
|
Ren'Py Chess 2.0 (This project) |
|
|
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.
- PvP and PvC
- Flip board view
- Resign
- Undo moves
(Also shows a similar UI choice screen if the fifty-move rule is in effect)
All 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 it is customizable to fit any screen size, as described in subsequent sections.
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
The core GUI class is a Ren'Py Creator-Defined Displayable named ChessDisplayable
inside 00-chess-engine/chess_displayable.rpy
.
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 boardplayer_color
:None
for PvP. For PvC,chess.WHITE
orchess.BLACK
.movetime
:None
for PvP. For PvC, between0
andMAX_MOVETIME = 3000
milliseconds.depth
:None
for PvP. For PvC, between0
andMAX_DEPTH = 20
.
See game/script.rpy
for an example that calls the chess displayable screen.
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.
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'
- Chess image: Photo by Jani Kaasinen on Unsplash. Resized and cropped to fit the screen.
- Chess background: Chess - Wikipedia
- Chess pieces