GithubHelp home page GithubHelp logo

caleb531 / connect-four Goto Github PK

View Code? Open in Web Editor NEW
27.0 5.0 9.0 2.8 MB

The slickest way to get 4-in-a-row, written using HTML5, JS, and Mithril (like React). Features an AI player, online multiplayer capability, and a smooth user interface

Home Page: https://connectfour.calebevans.me/

License: MIT License

JavaScript 91.30% SCSS 7.44% HTML 0.67% Dockerfile 0.58%
mithril html5 javascript connect-four minimax game

connect-four's Introduction

Connect Four

Copyright 2016-2023, Caleb Evans
Released under the MIT License

tests

This is the slickest Connect Four app around, written using HTML5, JavaScript, and Mithril (a React-like framework). You can play on your phone or computer, with a friend or against the AI. Just be sure to enjoy and have fun. :)

You can play the app online at:
https://connectfour.calebevans.me/

Implementation

User interface

The entire app UI is constructed and managed in JavaScript using Mithril. Chip transitions are handled by CSS to maximize performance and smoothness. The grid layout is styled with CSS Flexbox to enable the stacking of grid elements from the bottom up.

AI Player

Like many traditional board game AIs, my Connect Four AI uses the minimax algorithm. For my particular implementation, I've chosen to use a maximum search depth of three (meaning the AI examines possibilities up to three turns into the future). This is combined with alpha-beta pruning to dramatically reduce the number of possibilities evaluated.

My scoring heuristic works by counting connections of chips that intersect with an empty slot, giving exponentially more weight to larger connections. For example, every single chip touching an empty slot is worth four points, a connect-two is worth nine points, a connect-three is worth sixteen points, and so on. A winning connection of four or more chips is given the maximum/minimum score.

In the app, the AI player is lovingly referred to as "Mr. AI".

Run the project locally

1. Install global dependencies

The project requires Node (>= 18), so make sure you have that installed.

2. Install project dependencies

Install packages

This project uses pnpm (instead of npm) for package installation and management. From the cloned project directory, run:

npm install -g pnpm
pnpm install

3. Serve app locally

To serve the app locally, run:

pnpm dev

You will then be able to view the app at http://localhost:8080. Any app files will be recompiled automatically when you make changes to them (as long as pnpm dev is still running).

connect-four's People

Contributors

caleb531 avatar dependabot[bot] avatar jacksonrayhamilton avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

connect-four's Issues

Cant run on normal webspace

I guess it would be a good idea to make your project ready to run in a zip file.
Its way of overcomplication using scss npm brew gulp etc pp for this some simple html css js files.
In the Readme you do not even mention where and how to get this exotic mithril.
At the current state you are to inviting to study your AI solution but to study how to install
all the tools you use. These tools are ment to develop a solution like yours but not to spread and make a solution available to others.
Just zip your running web solution with the index.html,
scripts and css in the right place and your done ;-))

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.