Important alert: (current site time 4/17/2014 8:13:04 AM EDT)

winzip icon

BrewChess - Chess with a brain (Neural Network)

Submitted on: 4/6/2001 7:50:46 PM
By: BrewGuru99  
Level: Advanced
User Rating: By 6 Users
Compatibility: VB 3.0, VB 4.0 (16-bit), VB 4.0 (32-bit), VB 5.0, VB 6.0
Views: 9976
(About the author)
     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.
winzip iconDownload code

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:
  1. Re-scan downloaded files using your personal virus checker before using it.
  2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.
  3. 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...   
  1. 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.
  2. 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.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.

Other 3 submission(s) by this author


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Advanced category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)

Other User Comments

4/7/2001 12:15:07 AMbrewguru99

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.)

4/7/2001 12:18:19 AMBrewGuru99

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.)

4/7/2001 4:04:25 AMUlli

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.)

4/7/2001 4:22:46 AMUlli

To train the net how to make legal moves you must have a teacher who KNOWS how to make legal moves.

If I was you I would just hire the teacher to supervise the game and not the pupil.
(If this comment was disrespectful, please report it.)

4/7/2001 11:22:28 AMopello

Would you be kind enough to explain this 'new' neural net concept and how it works? What it is for? And other general info about it?

I have searched the internet to no avail ...

(If this comment was disrespectful, please report it.)

4/7/2001 4:11:56 PMUlli


There is a concise description of NNs at
(If this comment was disrespectful, please report it.)

4/9/2001 11:09:51 AMBrewGuru99

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.)

4/9/2001 11:11:58 AMBrewGuru99


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.)

9/2/2001 6:51:30 PMZack Knall 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.)

9/4/2001 3:10:48 AMBrewguru99

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.)

9/4/2001 3:11:13 AMBrewGuru99


* 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.)

11/10/2001 11:29:40 PMGavin

Cool Code im new to NN so i will not pretend i understand it all but thanks for sharing it i hope you will continue to develop it.
(If this comment was disrespectful, please report it.)

1/14/2004 9:08:54 PMPaul Guerra

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 & "\"' 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.)

5/8/2005 1:25:42 AMJan Christensen

Have is it training going whit these??

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.)

To post feedback, first please login.