Skip to content

edemaine/sliding-squares-puzzle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

n2 − 1 Sliding Squares Puzzle

This is a video-game implementation of the 15-puzzle, 8-puzzle, or more generally, any n2 − 1 puzzle, a sliding-block puzzle featuring an n×n grid of squares, where all but one square has a unique block. The goal is to put the squares in increasing "reading" order: 1 in the top-left, 2 to the right of that, and so on.

Half of the possible starting positions are solvable, and half are not. There's a button to generate either type of starting position, depending on what you'd like to illustrate.

You can tell whether a puzzle is solvable in linear time. But finding the shortest solution (fewest moves) is NP-hard.

Technology

This implementation is written in the Civet programming language using the Solid web framework, Vite bundler, and Vitest testing framework.

Most notably, it uses CSS transitions to achieve smooth animations of piece slides.

Local Development

$ pnpm install # or npm install or yarn install

Then you can use the following scripts:

pnpm dev or pnpm start

Runs the app in the development mode.
Open http://localhost:3000 to view it in the browser.
The page will reload if you make edits.

pnpm run build

Builds the app for production to the dist folder.
Bundles Solid in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.
Your app is ready to be deployed!

pnpm test

Runs some built-in tests in Vitest.

Releases

No releases published

Sponsor this project

 

Packages

No packages published