Four in a row - AI
It uses EaselJs for drawing the board, as support for working with the HTML5 Canvas element.
You can find here a live demo!
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:
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.
Licensed under the MIT license.