Giter Club home page Giter Club logo

sliding-puzzle-react's Introduction

Description

A little web app to play/solve sliding puzzles. It is written in TypeScript and uses React for the UI components and Phaser for the graphics. The algorithm to solve the puzzle is based on Iterative deepening A* and runs in a web worker.

Screenshots

TODO

Web Worker

Initially, I implemented the web worker by following this blog post:

Use Web Workers in Create React App without ejecting and TypeScript

It all worked fine in development (npm run start) but failed in a production build deployed to gh-pages (npm run build).

comlink.ts:265 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'apply')
    at e (d76e50226ea8f7d4a973.worker.js:1)

I noticed that there was a missing peer dependency:

$ npm ls --depth 0
...
npm ERR! peer dep missing: webpack@^3.0.0 || ^4.0.0-alpha.0 || ^4.0.0, required by [email protected]

It seems that my project, created using Create React App, was using a more recent version of webpack:

$ npm ls webpack                 
[email protected] /Users/jontaylor/Documents/HomeProjects/sliding-puzzle-react
└─┬ [email protected]
  └── [email protected] 

I then stumbled across https://webpack.js.org/guides/web-workers/ which says:

As of webpack 5, you can use Web Workers without worker-loader.

So I removed comlink-loader and changed my implementation to something more basic (using postMessage and onmessage) and it all works fine now. I then created a custom hook to wrap the mechanics of communicating with the web worker.

TODO

  • Add an overlay/animation over the board whilst the web worker is trying to find a solution
  • Implement cancellation of the web worker
  • Add sound effects

Links

sliding-puzzle-react's People

Contributors

taylorjg avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.