Skip to content
Chess with an F# domain engine and a simple WPF UI.
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.nuget Added Chess.FabUI and Chess.FabUI.WPF projects. Updated all FSCore to… Apr 8, 2019
.vscode
Chess.ConsoleUI Capitalized the record labels. Jul 23, 2018
Chess.Domain Added a comment. Apr 8, 2019
Chess.FabUI.Android Added Chess.FabUI and Chess.FabUI.WPF projects. Updated all FSCore to… Apr 8, 2019
Chess.FabUI.WPF Tweaks to UI Apr 8, 2019
Chess.FabUI.iOS Added Chess.FabUI and Chess.FabUI.WPF projects. Updated all FSCore to… Apr 8, 2019
Chess.FabUI Added "Fabulous.SimpleElements" nuget package and reworked most of th… Apr 12, 2019
Chess.WebUI Created Chess.WebUI project using Fable.Template.Elmish.React template. Aug 8, 2018
Chess.WpfUI Added Chess.FabUI and Chess.FabUI.WPF projects. Updated all FSCore to… Apr 8, 2019
.gitignore Initial upload of chess sln into github repo. Dec 16, 2017
Chess.sln Added Chess.FabUI and Chess.FabUI.WPF projects. Updated all FSCore to… Apr 8, 2019
README.md Update README.md Jan 11, 2018

README.md

FsharpChess

Chess with an F# domain engine and a simple WPF UI.

I created this project as part of my ongoing effort to understand F#. I am a full time C# developer, so I am currently trying to rethink my imperative approach to designing software of doing everything with mutable state.

I would really love it if anyone has any ideas on how to make this better, more "functional", or anything, really.

F# Domain

Chess.fs

This contains the domain entities (nouns), use cases (actions or methods), and the implementation methods (moving, validation, etc).

Api.fs

This provides a "ChessApi" class that allows the C# code to interface with the F# backend. The ChessApi class contains a mutable copy of the game state (the board, which is just a dictionary/map of cells and optional pieces, whose turn it is, etc). This is currently the only mutable state in the F# library. The idea is that I didn't want to make the C# calling code responsible for receiving the state and passing in back in for each move, as that seems like a very functional way of doing things. Instead, I wanted to "encapsulate" mutable state management within the F# ChessApi class.

C# WPF UI

The WPF UI is a very simple code-behind design (no MVVM here), because my purpose was to focus on the F# bits. It creates an instance of the F# ChessApi class and it refreshes the UI after each move based on the newly generated game state.

TODO

  • Implement "interposition" (or "blocking") - all pieces that capture linearly (all except the knight) should not be able to skip past enemy pieces. They should only be allowed the capture the first piece in their movement path.
  • Implement GameProgress to handle "check" and "checkmate" (game over + victor) and "stalement" status
  • Create checkmate detection - engine needs to be able to detect when a move results in the other color's king having no valid escape moves
  • Implement "legal" move detection - a player cannot move their own king into danger
  • Implement stalemate detection - when a player is not in check, but has no legal moves
  • If a player's king is in check, their next move MUST remove them from check state
You can’t perform that action at this time.