Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/devluxor/sapphire-chess
Sapphire Chess is a Chess engine, entirely written from scratch. It has complete game rules, an algebraic input systen, and a functional AI. It provides three game modes: Human vs. Human, Human vs. AI, and AI vs. AI. It also comes with an optional UI.
https://github.com/devluxor/sapphire-chess
ai chess chess-board chess-engine minimax-algorithm minimax-alpha-beta-pruning ruby
Last synced: about 1 month ago
JSON representation
Sapphire Chess is a Chess engine, entirely written from scratch. It has complete game rules, an algebraic input systen, and a functional AI. It provides three game modes: Human vs. Human, Human vs. AI, and AI vs. AI. It also comes with an optional UI.
- Host: GitHub
- URL: https://github.com/devluxor/sapphire-chess
- Owner: devluxor
- License: mit
- Created: 2022-10-15T13:37:51.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-10-03T10:25:13.000Z (3 months ago)
- Last Synced: 2024-11-18T12:38:48.239Z (about 2 months ago)
- Topics: ai, chess, chess-board, chess-engine, minimax-algorithm, minimax-alpha-beta-pruning, ruby
- Language: Ruby
- Homepage:
- Size: 348 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Sapphire Chess
[![Gem Version](https://badge.fury.io/rb/sapphire-chess.svg)](https://badge.fury.io/rb/sapphire-chess)
Sapphire Chess is a command line-based chess game with an algebraic notation input system,
complete chess rules, a beautiful interface and a functional AI. It provides three game modes:
Human vs. Human, Human vs. AI, and AI vs. AI.Please, visit for a very detailed account of how I wrote this game.
Supported Rubies: 3.1, 3.0, 2.7.
The game has not been tested on older versions, but it might still work.
Playing within the VS Code terminal is highly recommended because it renders the icons better.
---
## Current Features
* A beautiful board with easy-to-distinguish colors for white and black pieces.
* Fully functional AI
* Three levels of difficulty.
* Three game modes: human vs. computer, human vs. human.
* Full chess movement rules implementation, including castling and *en passant*, for both the human and the computer player.
* Accepts algebraic notation for movements, with human input validation.
* Material score display.
* Player's last move display.## Easy Setup (run containerized version; with Docker)
Simply, build the image (it's very lightweight) with:
```sh
docker build -t sapphire-chess .
```And run it with:
```sh
docker run -it sapphire-chess
```## Setup
Install with:
```ruby
gem install 'saphhire-chess'
```And execute from the command prompt with:
```sh
sapphire-chess
```Currently, the icons are only loaded properly from within VS Code terminals, so, for the moment, I highly recommend executing this command from there.
You can also create a new `.rb` file with this content and execute it:
```ruby
require 'sapphire-chess'Engine.new.play
```## Difficulty Mode
The difficulty mode is based on how many turns the computer can think ahead (the depth of the tree generated by `AI#minimax`, max. 3), the aggressiveness of the pieces, and the enemy's carelessness.
My recommendation is to play the game on the *hard* mode, as this was the original intention when I designed it. I introduced the other difficulties based on the suggestions from those who weren't able to beat the machine. However, the hard mode, due to the current Minimax implementation, is a little slow; I'm working on ways to improve the performance of this method.
## Screenshot
![Game screenshot](https://live.staticflickr.com/65535/52630422741_bc858d0096_z.jpg)
## The AI
The AI is based on a Minimax algorithm with Alpha-Beta pruning. This algorithm generates possible outcomes (*children*) for a provisional move: Each branch represents the enemy's possible move in the next turn as an answer to the provisional move; (i.e.: if current player is white [the maximizing player], it generates every possible movement for the next player, black [the minimizing player], who will choose the best possible move, and so on.
The best (relative to each player) possible outcome for each move will determine what move is chosen) The Alpha-Beta 'prunes' the tree: it makes the search more efficient, removing unnecessary branches, resulting in a faster process.
Lucas Sorribes, released under the MIT license.