Skip to content

hokkonsz/chess-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

♟ chess-rs

dependency status

A simple chess system written in Rust. The project is still in work in progress, you can find the missing features below. (See TODO)

Game Controller

The system can be controller through the game controller function. It takes two inputs Position 1 and Position 2. At Position 1 we should find a valid Unit, which we want to move to Position 2 to the Target Position. Then the controller evaluates the Unit's Type and the Target Position and mutates the board based on the results.

Chess Space to Array Space

For user-friendly usability we can produce Positions from Chess Notations.

board_positions

For example, the .to function produces a vector, which contains all the Positions between two Positions excluding the starting and ending Positions.

fn_to

Unit Step

To validate a Step we are using basic math, where we substract the Unit's Position from the Target's Position. Furthermore there are additional conditions to each Step. The whole Step System is build around the Type State Pattern, which in my mind really fits the process. (Or maybe I just really wanted to try my hands on this pattern.)

There are 3 different States to a Step.

ConditionState

  • Where we can add Conditions like Unit is not a King at Position or Unit is an Enemy at Position.
  • We can also add Actions like Move/Remove. This can be usefull for special cases like En passant or Castling, where we want to do more than one thing.

ResultState

  • This state holds information about the evaluation process.
  • In the ResultState we can execute the Actions.

ImageState

  • This State holds information about the former state of the board, so we can reconstruct the old state if necessary.

image

The pictures below show the calculations for each unit.

Pawn

pawn1 pawn2

Bishop/Rook

bishop rook

Knight/Queen

knight queen

King

king1 king2

Examples

Currently there are two examples to test out the system, one of them is using eGUI and the other one is using notan. Right now I'm more focused on notan, which I can gladly recommend to anyone, who wants to quickly implement and test out things in Rust.

cargo run --example app_notan

or

cargo run --example app_egui --features egui

TODO

List of missing features and future plans.

  • CheckMate / StaleMate

Releases

No releases published

Packages

No packages published

Languages