A chess AI, with with different algorithms of increasing intelligence.
Play live version here: https://bay-chess-ai.herokuapp.com/
See my blog post about implementation here: https://byanofsky.com/2017/07/06/building-a-simple-chess-ai/
Based on Lauri Hartikka's tutorial
These instructions will get you a copy of the project up and running on your local machine for development. See Deployment for notes on how to deploy the project on a live system.
You will need to have Node.js and npm installed. For instructions on installing Node, please visit NPM's documentation on installing Node.js.
You can run npm's initialization to install dependencies from package.json
.
npm init
When playing, I recommend having your browser's console open to issue commands and view the computer player's 'thinking' through each move.
To play against the computer, simply make a move. You will play as the white side. The computer will then make a move.
The computer is currently set to look 3 moves ahead using minimax with alpha beta pruning.
If you'd like to have the computer play the computer, you can do so with this command in your browser's console, setting the algorithm you'd like to use, and each computer player's 'skill' level.
playGame(algo=4, skillW=2, skillB=2)
// algo=
// 1 - random
// 2 - Best move, one move ahead
// 3 - Best move, n moves ahead, minimax
// 4 - Best move, n moves ahead, minimax with alpha beta pruning (Faster)
// skillW and skillB are how many moves ahead to look
skillW
and skillB
only work with alogs 3 & 4. The skill level is what sets how many moves ahead each player will look.
Algo 3 does not use alpha beta pruning, so setting skill levels greater than 2 will make move times very long.
Algo 4 uses alpha beta pruning, so you can set skill level up to 3, maybe even 4. But beyond that, move times will be very long.
You can run this locally with Node.js, and visiting http://localhost:5000.
node app.js
You can also easily deploy this to a server. It is ready to be deployed to Heroku, with a Procfile included. Instructions from Heroku
- Express - The web framework used
- chess.js - Chess library
- chessboard.js - Chess board visualization
- Brandon Yanofsky - Initial work - byanofsky
- Inspired by Lauri Hartikka's tutorial
This project is licensed under the Apache-2.0 License - see the LICENSE file for details. Some files have their own licenses, as described in 3rd Party Software below.
See LICENSE-3RD-PARTY file for full licenses
- chess.js Copyright (c) 2017, Jeff Hlywa (jhlywa@gmail.com)
- chessboard.js Copyright 2013 Chris Oakman
- jQuery Copyright JS Foundation and other contributors, https://js.foundation/
- Implement Negamax
- Implement sorting function for possible moves to optimize alpha beta pruning
- Better implementation of Express
- Add an element of machine learning
- Improve interface
- Refactor code