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

connectfourai

v1.3.1

Published

A customizable, powerful, and efficient connect four AI.

Downloads

11

Readme

An NPM package for human vs human or human vs computer play for the game Connect 4 aka Four in a row.

Install

Install this package with npm i connectfourai or npm install connectfourai.

Setup

// Load the module and store it in a variable.
const AI = require("connectfourai");

Usage

const AI = require("connectfourai");

// To start a new game.
AI.new_game();

// To see the board.
AI.display_board();

// Makes a move for the player. Note that columns are 0-indexed, so if you want the first column then use 0, and if you want the last column use 6.
AI.play_human(4);

// Makes a move for the AI.
AI.play_ai();
AI.play_ai(2); /* You can also specify a column for the AI to play in. */
// You can also specify a depth to play against. The higher the number, the longer the bot will take to calculate. A depth of 9 is suggested.
AI.play_ai(null, 4);

// To check if a column can be played.
AI.can_play(3);

// To see which columns can be played in.
AI.get_valid_locations();

// To see which column is the best for a human to play. Can be used as a hint.
AI.get_best_move();
AI.get_best_move(5); /* You can specify a depth as well */

Built-in variables

For information on the state of the game.

COLORS                          // A collection of unicode colors to choose from.
COLORS.blue                     // One example.
GAME.full                       // If the board is full.
GAME.history                    // A history of moves played so far. Format is { column: 3, piece: "🟡" }
GAME.over                       // If the game is over (full or someone won).
GAME.victor or GAME.winner      // Who won the game.
GAME.won                        // If someone won the game.

Customization

const AI = require("connectfourai");

// If desired, customize the pieces. They can be anything you want!
AI.set_ai_piece("⚪");          // Default: ⚫
AI.set_player_piece("🔵");      // Default: 🔴
AI.set_empty_piece("🟢");       // Default: 🟡

// You can also use the provided color object.
AI.set_ai_piece(COLORS.white);
AI.set_player_piece(COLORS.blue);
AI.set_empty_piece(COLORS.green);

// You can change the rows, columns, and even the connect length.
AI.set("columns", 10);          // Minimum 3
AI.set("rows", 9);              // Minimum 3
AI.set("depth", 5);             // Minimum 1, default 9. Change here to not have to specify as an argument later.

// You can setup a specific position. The board is setup by placing a piece in each column, from left-to-right.
AI.set_pos("4,4,4,4,4,3,3,3,6");

// Get the current position.
AI.get_pos();