Demonstrates the capability of a neural net by teaching it to play chess. This is inheritly slow, and will take many many hours to train the neural network properly.
For mor information on neural networks, see my "Neural Network" code post.
Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. Afterdownloading it, you will need a program like Winzip to decompress it.Virus note:All files are scanned once-a-day by Planet Source Code for viruses, but new viruses come
out every day, so no prevention program can catch 100% of them. For your own safety, please:
Re-scan downloaded files using your personal virus checker before using it.
NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.
Scan the source code with Minnow's Project Scanner
If you don't have a virus scanner, you can get one at many places on the net
Terms of Agreement:
By using this code, you agree to the following terms...
You may use
this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.
You may link to this code from another website, but ONLY if it is not wrapped in a frame.
You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
The primary purpose if this program right now is to train the neural network (NN) until it is capable of playing the game according to the rules.
Here's how it works: Imagine trying to play chess with an infant. The infant will pretty much grab any random peice and thrown it somewhere else on the board. As he does this you correct him, show him all the moves he can do. Then you let him move. If he doesn't make a legal one, you show him everything again. Over and over. Eventually as the infant grows older he'll understand what he can and can't do. And then, over the course of the game, even though the layout of the board will change he will understand the use and movement of each peice and be capable of deciding on a good move, not just a legal one. (If this comment was disrespectful, please report it.)
Soon I will be adding a 3D graphics engine to the game, allow for human players :P and include a trained AI player.
Please comment if you do not believe that the NN size I have used is capable of learning the game. I did some calcs (included with the code) and I ain't 100% sure if I covered everything. (If this comment was disrespectful, please report it.)
It might eventually learn how to make legal moves but there is no indication that it will ever learn how to WIN.
There are undefined variables (eg whitepeice) and I did not see how it prevents knights to jump off the board for example. Also there is no castling and no en passant capture. And confidentially between you and me: the puppets are called pIEces, not pEIces. (If this comment was disrespectful, please report it.)
Prevention of moving any peice off of the board is inherit in the interpitation of the AI's output. Only 64 possabilities for each output. Now the human interface will have to be different...
En passant is built into the if then structure for the pawn within the EvalMove function. (Notice, the b variable inculdes one boolean set that checks to make sure that there is no sideways movement if it was moved up two from it's starting position.
Oh, and just like teaching a child, you don't teach them nuclear physics in grade school... You have to build a foundation. Once I develope a NN that can move legally I can make another training regeme that will train it for stratgey. Also, the teacher here is the EvalMove function. The child keeps trying, and the EvalMove keeps slapping the wrists. (If this comment was disrespectful, please report it.)
This is why I released this engine without any gui or human interaction. The primary purpose is to train the AI, and once that is done we can establish a fully functional game. (If this comment was disrespectful, please report it.)
.....wow. I am not entirely sure what is going on in this program, but it looks cool..and complicated. lol, i have been programming for years and this is a little over my head. gj (If this comment was disrespectful, please report it.)
I suppose that if you can't understand it then I didn't do a good enough job with my code comments. :ř
Well, for further clarification (these comments will appear in the next release of the code):
* Class cNN is the entire neural network code (pretty much encapsulated). To understand the NN itself further check out my other submissions.
* The function EvalMove checks whether or not the move being given is valid. It makes use of CheckSquare and EvalSquare. EvalSquare simply determins wether or not the square is occupied by an enemy peice, friendly peice or is open. CheckSquare checks for possible King Checks if the peice is moved to that square (thus preventing moving and putting your king in check, or giving notice is you have put the enemy king in check) (If this comment was disrespectful, please report it.)
* MakeMove actually records the desired move and updates the board. This function will also do the graphic routines in the future.
* AITrain simply uses EvalMove to determine if the output of the NN would be a legal move. If so then it calls MakeMove and call the NN again for the other color's move. The NN is trained on all the possible moves if it tries one that is not legal, then it tries again. Over and over until the NN gets it right. (The longest I've gone is about 1000 trains with no legal moves made...) (If this comment was disrespectful, please report it.)
How long will it take to make a valid movement? (If this comment was disrespectful, please report it.)
6/22/2004 8:31:30 PM:
I figured out a way to make it work many times faster. The code saves the NN every time it trains it with a legal move. Saving takes about 1 second so it slows it down by a large amount. I simply moved the 'AI.ExportNN App.Path & "\AI.net"' command to the end of the AI_Train sub, so it saves at the end of the training. (If this comment was disrespectful, please report it.)
Isnít there a problem in the chess move decision. When check the move, it actually doesent pick a right move. Put if you move the decision around it works.
(If this comment was disrespectful, please report it.)
Add Your Feedback
Your feedback will be posted below and an email sent to
the author. Please remember that the author was kind enough to
share this with you, so any criticisms must be stated politely, or they
will be deleted. (For feedback not related to this particular code, please
click here instead.)