This is a chess AI and chess game built using python.
The end goal is to have a trained convolutional net be used as an evaluation function to evaluate future states from the tree search. Then, the optimal move will be determined using the minimax algorithm (with alpha beta pruning).
Use python virtual machine to run this:
brew install [email protected]
virtualenv -p /usr/local/bin/python2 venv
virtualenv venv
source venv/bin/activate
pip install -r requirements.txt
To play the ai:
python2 play.py
You will be prompted to enter a starting and ending coordinate for your move. I.e a2
-> a4
You can find more details in my blog: luweilikesdata.blogspot.com
The tree generator component of the chess AI generates the possible future board positions based on the possible moves that the pieces can make. At any given position, there are on average 20 possible moves that can be made in chess.
The above illustrates a chess tree. Possible moves are generated from the current position to create hypothetical future states.
This is the "intuition" of the chess AI. Given an 8x8 chess position, the evaluation function will determine whether a move is good or not by assigning it a numerical score. A negative score means that black is winning, a positive score means that white is winning.
The evaluation function can take many forms depending on what approach you want to take. You can use hard coded heuristic features. You could take a model based approach (ie. train a neural network), etc etc.
The minimax algorithm tries to find the optimal move from a tree of moves. Starting from the leaves of the tree which represent future states, you want to propogate back to the present root node by alternating between min() and max() (hence the name, minimax).
When it is your turn, you want to optimize for your outcome, therefore you want to calculate the max() position score.
When it is your opponents turn, he wants to minimize your outcome, therefore it calculates the min() position score.
The guide below explains minimax very well: http://web.cs.ucla.edu/~rosen/161/notes/minimax.html
Alpha-beta pruning is a process that can be used to greatly reduce the space of the tree search. It works by pruning the search tree as you generate it by ruling out paths that neither you nor your opponent will never take.
This is done by keeping track of two values called alpha and beta as you are searching through the tree.
Alpha is the maximum lower bound (the lowest score you are willing to accept)
Beta is the minimum upper bound (the highest score your opponent is willing to accept)
The guide below explains alphabeta pruning very well: http://web.cs.ucla.edu/~rosen/161/notes/alphabeta.html
pip install ipython notebook
python2 -m pip install ipykernel #install python2 jupyter kernel
python2 -m ipykernel install --user
Bumps ipython from 7.16.3 to 8.10.0.
Sourced from ipython's releases.
See https://pypi.org/project/ipython/
We do not use GitHub release anymore. Please see PyPI https://pypi.org/project/ipython/
15ea1ed
release 8.10.0560ad10
DOC: Update what's new for 8.10 (#13939)7557ade
DOC: Update what's new for 8.10385d693
Merge pull request from GHSA-29gw-9793-fvw7e548ee2
Swallow potential exceptions from showtraceback() (#13934)0694b08
MAINT: mock slowest test. (#13885)8655912
MAINT: mock slowest test.a011765
Isolate the attack tests with setUp and tearDown methodsc7a9470
Add some regression tests for this changefd34cf5
Swallow potential exceptions from showtraceback()Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase
.
Hey @luweizhang , Great work man !
I have a quick question, Can you please walk me through?