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

tic-tac-nano

v1.0.0

Published

20bit CRDT Tic-Tac-Toe

Downloads

1

Readme

pure | 📦 code style | standard

tic-tac-nano

20bit CRDT Tic-Tac-Toe

This is a Conflict-free Replicated Data Type that is capable of storing the full history of a Tic-tac-toe game session occupying only 20bits of binary space.

Example: Number 799002 contains 8 moves and ends in a draw that looks like this when unpacked:

|o|x|o|
|o|x|x|
| |o|x|

I want to use it as an functional dummy for P2P simulations, if you find any other use-cases please share! (Essentially it is a tiny finite append-only feed that in a test environment should adhere to similar constraints as the real deal)

Use

$ npm install tic-tac-nano
const {
  /**
    * Unpacks the feed bits into an array
    *
    * unpackBoard(feed) // => ['x','o',undefined, ...]
    */
  unpackBoard,
  /**
    * Packs a new move by index into argument feed
    * optional 3rd argument causes packMove to log a
    * visualization using console.info()

    * packMove(feed, index, print = false) // => new version
    */
  packMove,
  /**
    * Return longest feed of the two or throws an error
    * if there is no overlap between the two histories.
    *
    * merge(a, b) // => a <=> b || UnrelatedGameError
    */
  merge,
  /**
    * Just as it sounds
    *
    * printFullGame(Number)
    */
  printFullGame,
  nMoves,
  printBoard
} = require('tic-tac-nano')

// Alice puts an `x` in the center and sends the feed to bob
let alice = packMove(0, 2) // => 2

// Bob places an `o` in top-left corner and sends the feed
// back to alice
let bob = packMove(alice, 0) // => 48

// They continue to send the feed back and forth
// until the game ends in a draw.
alice = packMove(bob, 6) // => 390
bob = packMove(alice, 1) // => 3121
alice = packMove(bob, 0) // => ...
bob = packMove(alice, 3) // => ...
alice = packMove(bob, 1) // => ...
bob = packMove(alice, 0) // => 79902

Now we can print the entire history

> printFullGame(79902)

Move #1
| | | |
| |x| |
| | | |

Move #2
|o| | |
| |x| |
| | | |

Move #3
|o| | |
| |x| |
| | |x|

Move #4
|o| |o|
| |x| |
| | |x|

Move #5
|o|x|o|
| |x| |
| | |x|

Move #6
|o|x|o|
| |x| |
| |o|x|

Move #7
|o|x|o|
| |x|x|
| |o|x|

Move #8
|o|x|o|
|o|x|x|
| |o|x|

Move Indices

First move only has 3 choices:

| 0 | 1 |   |    0: Corner
|---+---+---|    1: Edge
|   | 2 |   |    2: Center
|---+---+---|
|   |   |   |

Subsequent moves use index numbers from left-to-right, up-to-down, skipping over any occupied slots.

Ex1.

| 0 | x | 1 |
|---+---+---|
| 2 | 3 | 4 |
|---+---+---|
| o | 5 | 6 |

Ex2.

| 0 | x | 1 |
|---+---+---|
| 2 | x | 3 |
|---+---+---|
| o | 4 | 5 |

Donations

 _____                      _   _           _
|  __ \   Help Wanted!     | | | |         | |
| |  | | ___  ___ ___ _ __ | |_| |     __ _| |__  ___   ___  ___
| |  | |/ _ \/ __/ _ \ '_ \| __| |    / _` | '_ \/ __| / __|/ _ \
| |__| |  __/ (_|  __/ | | | |_| |___| (_| | |_) \__ \_\__ \  __/
|_____/ \___|\___\___|_| |_|\__|______\__,_|_.__/|___(_)___/\___|

If you're reading this it means that the docs are missing or in a bad state.

Writing and maintaining friendly and useful documentation takes
effort and time. In order to do faster releases
I will from now on provide documentation relational to project activity.

  __How_to_Help____________________________________.
 |                                                 |
 |  - Open an issue if you have ANY questions! :)  |
 |  - Star this repo if you found it interesting   |
 |  - Fork off & help document <3                  |
 |.________________________/________________________|

I publish all of my work as Libre software and will continue to do so,
drop me a penny at Patreon to help fund experiments like these.

Patreon: https://www.patreon.com/decentlabs
Discord: https://discord.gg/K5XjmZx
Telegram: https://t.me/decentlabs_se

Changelog

1.0.0

  • added methods packMove, nMoves, printFullGame
  • added tests
  • populated README.md

0.1.0

  • first release

Contributing

By making a pull request, you agree to release your modifications under the license stated in the next section.

Only changesets by human contributors will be accepted.

License

AGPL-3.0-or-later

2020  Tony Ivanov