Skip to content

marcomelilli/four-in-a-row-js-minimax

master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
img
 
 
lib
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Four in a row - AI

This project is an implementation in javascript of the algorithm minimax with Alpha-Beta pruning applied to the game Connect Four.

It uses EaselJs for drawing the board, as support for working with the HTML5 Canvas element.

Example

You can find here a live demo!

game screenshot

Running Locally

The AI is runned in background in another thread thanks to WebWorkers. For this reason, if you are using Chrome to run the project, be sure to close all the tabs and run it as: "C:\path\Chrome.exe" --allow-file-access-from-files

Or alternatively you should run an http server locally.

How it works

The AI searches the best move through algorithm minimax:

It is a recursive algorithm for choosing the next move in an n-player game. A value is associated with each position or state of the game. This value is computed... and it indicates how good it would be for a player to reach that position. The player then makes the move that maximizes the minimum value of the position resulting from the opponent's possible following moves"

In this game I assumed a number of arbitrary points for each position of checkers on the board, and so I was able to calculate the state of the game in each iteration. The AI searches all the possible moves try to minimize the score of the board, and at the same time it tries to prevent the opponent maximizing his score.

Above the board you can see the live score of the board and you can set the depth of the algorithm.

Copyright

Licensed under the MIT license.

About

Connect Four AI - Minimax with Alpha-Beta Pruning in javascript

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published