Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sapphire-chess

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sapphire-chess

  • 1.1.7
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Sapphire Chess

Gem Version

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 https://medium.com/@lucas.sorribes/nostromo-my-ruby-chess-journey-part-i-7ef544b547a5 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 for older versions, but it might still work.


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.

Setup

Install with:

gem install 'saphhire-chess'

And execute from the command prompt with:

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:

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

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.

Copyright © 2023 Lucas Sorribes, released under the MIT license.

FAQs

Package last updated on 03 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc