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

@asebexen/tacky

v1.1.3

Published

A simple, functional library for Tic Tac Toe

Downloads

9

Readme

About Tacky

Tacky is a lightweight, functional library built to help you (yes, you!) write Tic-Tac-Toe applications!
Tacky makes it simple to interact with a Tic-Tac-Toe instance without complicated validation logic.

How to Use

To include Tacky in your project, install with npm i @asebexen/tacky
Tacky exposes only a few functions, but they're all mega powerful!

import * as tacky from '@asebexen/tacky';

// Generate a new, empty game board with an optional config object.
const initGame0 = tacky.init();
const initGame1 = tacky.init({startingPlayer: 'o'});

// Make a move in the top right square (2). Valid positions are in the range [0, 8].
const result0 = tacky.makeMove(initGame0, 2);
// Tacky guarantees that a valid game is returned, even if there are errors (in which case, the game will be unmodified). Errors are string enums, so they can be printed and understood.
if (result0.error) console.error(`Tacky error: ${result0.error}`);
const game0 = result0.game;

// Make another move, but this time without error handling!
const {game: game1} = tacky.makeMove(game0, 1);

// This is boring; let's just skip ahead to a game that X wins already.
const winningGame = tacky.fromHistory([2, 1, 4, 0, 6]);

Let's have a look at the winning game object...

{
  "game": {
    "board": [ "o", "o", "x", null, "x", null, "x", null, null ],
    "moveHistory": [ 2, 1, 4, 0, 6 ],
    "startingPlayer": "x",
    "currentPlayer": "o",
    "state": "xwin",
    "winningLine": [ 2, 4, 6 ]
  },
  "error": null
}

The beauty of Tacky is that it's meant to be human-readable and friendly. I don't even think I have to explain the object above!
By gracefully reporting errors in the error field, Tacky is flexible and unopinionated; it can be attached to any kind of frontend, and errors can be ignored or reported as desired!

Features

  • Full TypeScript support. I like types, you like types!
  • Functional design, supporting immutability. Tryna make this crap work nicely with React and stuff.
  • Automatic turn tracking. Why use mutable variables when it could be part of the game state?
  • No-throw error handling for the following:
    • Out-of-bounds positions. While I applaud thinking outside the box, my game (sadly) does not.
    • Placing tiles in occupied cells. Preventing cheating is another way I stop you from having real fun.
    • Continuing to play after the game is over.
  • History tracking. Everyone wants to relive that Play of the Game moment, right?
  • Winning line provided free of charge. I get it, Tic Tac Toe is complex. You probably want a way to figure out how exactly X won instead of O.

Planned Features

  • Minimax tree support. I know you wanna know the optimal way to crush your opponents. (Hint: YOU CAN'T. Unless they're stupid. No offense.)
  • Alternate ruleset support. Because normal Tic Tac Toe is boring. No offense.
  • More robust input validation. Because some ~~JavaScript user~~ human being is gonna try to pass a boolean into my beautifully-typed functions and they're gonna BREAK IT and I'm gonna CRY.

Bonus Features

  • I told Cursor to use Tacky to write a sample Tic Tac Toe game and it did. It's so easy, even an AI can use it. uwu

License

Tacky is licensed under the GNU GPLv3. If this is a royal pain in your arse, write to me and we can work it out. :3

Contact

Email all inquiries to [email protected]
If you used Tacky in a project, feel free to let me know! I'd actually be quite flattered to hear from you lmao.