E2e4.SlidingBlock.Logic
1.0.0
Prefix Reserved
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
<PackageReference Include="E2e4.SlidingBlock.Logic" Version="1.0.0" />
<PackageVersion Include="E2e4.SlidingBlock.Logic" Version="1.0.0" />
<PackageReference Include="E2e4.SlidingBlock.Logic" />
paket add E2e4.SlidingBlock.Logic --version 1.0.0
#r "nuget: E2e4.SlidingBlock.Logic, 1.0.0"
#:package E2e4.SlidingBlock.Logic@1.0.0
#addin nuget:?package=E2e4.SlidingBlock.Logic&version=1.0.0
#tool nuget:?package=E2e4.SlidingBlock.Logic&version=1.0.0
E2e4.SlidingBlock.Logic
![]()
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 aulong, with a branchless XOR tile swap. The goal position is a constructor argument, and the Manhattan distance is measured against it.KlotskiStateandKlotskiDomain: Klotski with a canonical shape key, so interchangeable pieces are the same position.LaneState16,LaneState64andLaneSlideDomain<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.PushStateandPushDomain: Soko warehouse pushing, where the storeman's walking is free, with dead squares and a heuristic.ShuntingTrackandShuntingDomain<TBitboard>: railway shunting (Hordern chapter J), with engines that push and pull wagons over switches, wyes and turntables, solved withSolveDijkstra;ShuntingMapreads one from text.PolyominoStateandPolyominoDomain: non-rectangular pieces (L, T, J, S, Z, U) on a bitboard, with multi-step corner-hook slides and a permutation-invariant Zobrist hash.PuzzleTopologyandPuzzleTopologyBuilder: build a board from relative cell lists, with LSB normalisation and precomputed valid-anchor masks.E2e4.SlidingBlock.Logic.Text:TopologyMap,LaneDiagramandPushMapread 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.Statussays whether a search found nothing because the puzzle is unsolvable or because it hit a limit.PuzzleWalkandPlaySession<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 | Versions 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. |
-
.NETStandard 2.0
- System.Memory (>= 4.6.3)
-
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.
See https://github.com/th3snark/E2e4.SlidingBlock.Logic/releases for what changed in each version.