npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

voltrevo-2048

v1.0.1

Published

A deterministic version of 2048.

Downloads

2

Readme

2048

This is a fork of Gabriele Cirulli's 2048 project with some changes around deterministic play and unlimited undos.

Live here: https://andrewmorris.io/2048.

The Challenge

As you start playing, you'll notice that your moves are displayed in the url hash. This makes your game state and its history shareable (usually). Your mission is to produce a url with the highest score you can find.

Headless Version

Since you are a developer, you will likely desire to separate your algorithmic number crunching domination from the fancy schmancy graphical frontend I have provided. Fear not my friend, simply add "voltrevo-2048": "voltrevo/2048" to your package.json and access the Board factory via:

'use strict';

const Board = require('voltrevo-2048/src/Board.js');

const b = Board();

b.up();
b.down();
b.left();
b.right();

console.log(b.prettyString()); /*
  +------------+
  | 0  0  0  4 |
  | 0  0  2  0 |
  | 0  0  0  0 |
  | 0  0  4  2 |
  +------------+
*/

You can also experiment with this in the developer console as window.Board. Boards also provide .getCells() and .clone(), and you can specify the game seed and starting state like this:

Board({
  gameSeed: 'foobar',
  cells: [
    [0, 0, 0, 4],
    [0, 0, 2, 0],
    [0, 0, 0, 0],
    [0, 0, 4, 2],
  ],
})

The Suggestion Engine

Speaking of the headless version, you may have noticed that the game displays move suggestions for you. These suggestions are generated by trivialGetSuggestion.js which looks like this:

module.exports = (board) => {
  const movePriority = ['right', 'down', 'up', 'left'];

  for (let i = 0; i !== movePriority.length; i++) {
    const move = movePriority[i];

    if (board[move]()) {
      return move;
    }
  }

  // Nowhere to go, but still need to return something
  return 'right';
};

These suggestions are very weak, as they simply attempt right, down, up, left, in that order. If you create a headless AI, you might want to fork this project and incorporate it here to interact with and see what your AI moves look like. You might even use this to team up with your AI to produce a better outcome together.

This is also accessible to you in the console of the official version by overwriting window.gameManager.getSuggestion.

URL Hash Format

If your move sequence becomes very long, it may become abbreviated using a fake url that is not shareable. The format looks like this:

https://andrewmorris.io/2048/#<game-seed>;<move-sequence-url>;<undo-count-after-url>;<raw-moves>

So if your move-sequence-url is something like 2048://wwxzcbyyzo, that url will only work inside the page that generated it. To fix this, you can print your raw moves in the developer console with this command:

gameManager.moveStore.resolve().then(moves => console.log(moves));

Then, I suggest creating a url for those moves using a github gist (use the raw button), and then shortening it using goo.gl, and then you can create a shareable url like this:

https://andrewmorris.io/2048/#<game-seed>,<url-you-created>

Note: <game-seed> might be an empty string. That's ok.

Run Your Own Instance

git clone [email protected]:voltrevo/2048
cd 2048
npm install
npm start
# see localhost:8080

Note: You will need git and node.

License

2048 is licensed under the MIT license.