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

@rbxts/tic-tac-toe

v0.0.3

Published

Modular tic-tac-toe without dependencies, because why not.

Downloads

7

Readme

Tic Tac Toe

This is a simple module to run games of tic-tac-toe. You can create your own players and outputs to match what your game needs and then let all the logic be handled by this module, simple as that.

For example, if you want this game to be played by two different Roblox players, you could create a NetworkPlayer, which when asked for a move, waits for a RemoteEvent from a player specified in the constructor. Alongside that, to update participants of a game, you could create a NetworkOutput which sends the game information to each participating player whenever something about the game changes.

Example

// The "ManualPlayer" is a built in player type which
// automatically returns a move when addressed.
const playerX = new TicTacToeManualPlayer('X');
const playerO = new TicTacToeManualPlayer('O');

// Create a game with two players
const ttt = new TicTacToeGame(playerX, playerO);

// Keep getting the next move until the game is over
while (!ttt.isOver()) {
	ttt.nextMove();
}

// Usually you would handle the result and playing
// of a game in an `Output` reactively, but here for
// clarity we do it declaratively.

const state = ttt.getState();

switch (state) {
	case TicTacToeState.X_WON:
		print('X WON!');
		break;

	case TicTacToeState.O_WON:
		print('O WON');
		break;

	case TicTacToeState.DRAW:
		print('DRAW');
		break;

	// Players can decide to return nothing
	// from their makeMove function to cancel the game.
	case TicTacToeState.CANCELLED:
		print('A player did not make a move');
		break;
}

Benchmark

I am just including this section because I was curious myself, performance really isn't a concern though. Basically, I transformed the example above into a benchmark which runs 50,000 times, and accumulates each state instead of printing it. Each game took about 130μs.

Here is the output, this uses my benchmark utility from @rbxts/zycore by the way.

Benchmark(TicTacToe): 128.93 μs (6.45 s for 50000 runs)
X: 16084
O: 16295
Draw: 17621
Total: 50000