E2e4.SlidingBlock.Logic 1.0.0

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package E2e4.SlidingBlock.Logic --version 1.0.0
                    
NuGet\Install-Package E2e4.SlidingBlock.Logic -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="E2e4.SlidingBlock.Logic" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="E2e4.SlidingBlock.Logic" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="E2e4.SlidingBlock.Logic" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add E2e4.SlidingBlock.Logic --version 1.0.0
                    
#r "nuget: E2e4.SlidingBlock.Logic, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package E2e4.SlidingBlock.Logic@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=E2e4.SlidingBlock.Logic&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=E2e4.SlidingBlock.Logic&version=1.0.0
                    
Install as a Cake Tool

E2e4.SlidingBlock.Logic

E2e4.SlidingBlock.Logic icon

A small sliding block puzzle engine for .NET: bitboard-driven state structs with allocation-free move generation, and generic solvers, for the N-puzzle, Klotski, Rush Hour, Soko-style pushing and general polyominoes. It targets net10.0, net8.0 and netstandard2.0, so it runs on every current .NET on Windows, Linux and macOS, and through the netstandard2.0 build on .NET Framework 4.6.1 and later, Mono and Unity. The net10.0 and net8.0 builds have no dependencies; netstandard2.0 depends on System.Memory for Span<T>. Install from NuGet: E2e4.SlidingBlock.Logic.

Every puzzle is an ISlidingBlockDomain<TState, TMove> (initial state, goal test, move generation, move application and a 64-bit state hash), and PuzzleSolver solves any of them with BFS, A* or IDA*.

// The engine does not know where the blank belongs: the puzzle supplies its goal position.
var goal = new NPuzzle4x4State(0xFEDCBA9876543210UL);
var domain = new NPuzzle4x4Domain(goal, goal);
var start = PuzzleWalk.RandomWalk(domain, goal, 25, new Random(3));

SolveResult<NPuzzle4x4Move> result = new PuzzleSolver().SolveIdaStar(domain, start, domain.ManhattanDistance);
Console.WriteLine(result.IsSolved ? result.Moves.Count : -1);

// Rush Hour: the vehicles are read off a diagram (using E2e4.SlidingBlock.Logic.Text), the red car X is vehicle 0 and has to reach
// the far end of its row (offset 4 for a car two cells long); a move slides a vehicle one cell.
string[] diagram = ["CCH..F", "..HB.F", ".XXB..", "D..B..", "DGG...", "..EEE."];
var vehicles = LaneDiagram.Parse(diagram, LaneDiagram.SymbolsOf(diagram, leadingLabels: "X"));
var rushHour = new LaneSlideDomain<LaneState16, Bitboard64>(vehicles, columns: 6, rows: 6, goalVehicle: 0, goalOffset: 4, maxStep: 1);
Console.WriteLine(new PuzzleSolver().SolveBfs(rushHour, rushHour.InitialState).Moves.Count);

What is in it

  • NPuzzle4x4State: the 4x4 sliding tile puzzle packed into 16 nibbles of a ulong, with a branchless XOR tile swap. The goal position is a constructor argument, and the Manhattan distance is measured against it.
  • KlotskiState and KlotskiDomain: Klotski with a canonical shape key, so interchangeable pieces are the same position.
  • LaneState16, LaneState64 and LaneSlideDomain<TState, TBitboard>: vehicles as lane offsets packed 4 bits each (up to 64 vehicles on 128 cells); Rush Hour moves one cell, garage puzzles slide any distance.
  • PushState and PushDomain: Soko warehouse pushing, where the storeman's walking is free, with dead squares and a heuristic.
  • ShuntingTrack and ShuntingDomain<TBitboard>: railway shunting (Hordern chapter J), with engines that push and pull wagons over switches, wyes and turntables, solved with SolveDijkstra; ShuntingMap reads one from text.
  • PolyominoState and PolyominoDomain: non-rectangular pieces (L, T, J, S, Z, U) on a bitboard, with multi-step corner-hook slides and a permutation-invariant Zobrist hash.
  • PuzzleTopology and PuzzleTopologyBuilder: build a board from relative cell lists, with LSB normalisation and precomputed valid-anchor masks.
  • E2e4.SlidingBlock.Logic.Text: TopologyMap, LaneDiagram and PushMap read boards, vehicles and warehouses from diagrams (one string per row, with the symbols you choose). The domains themselves take plain data, so a layout can come from anywhere.
  • PuzzleSolver: generic BFS, A*, IDA*, Dijkstra and weighted A*, with a node limit, a stored-state limit and cancellation; SolveResult.Status says whether a search found nothing because the puzzle is unsolvable or because it hit a limit.
  • PuzzleWalk and PlaySession<TState, TMove>: a generic random walk (for solvable shuffles) and the undo, redo and reset bookkeeping every interactive puzzle needs.

The engine contains no puzzle: no layouts, no goal positions, no colours. The application that uses it defines its layouts and goals and hands them to the domains as data (LabPuzzles in the Labs is an example).

E2e4.SlidingBlock.Logic.Labs.Wpf in the repository is a WPF application with three laboratories that show the bitboards and the solvers working. It is not part of the package.

Documentation

The research and design notes behind the object model (representations, LSB normalisation, valid anchors and hook moves, Zobrist hashing, with diagrams) are in docs.

Build and test

dotnet test E2e4.SlidingBlock.Logic.slnx

See CONTRIBUTING.md to help, CHANGELOG.md for what changed, and SECURITY.md to report a vulnerability.

Licence

MIT, see LICENSE. No dependencies on net10.0 and net8.0; netstandard2.0 needs only System.Memory.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

  • net10.0

    • No dependencies.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.0 87 11/19/2026
1.0.0 114 11/3/2026

See https://github.com/th3snark/E2e4.SlidingBlock.Logic/releases for what changed in each version.