This is my chess program created in visual basic. I have used picture boxes for the squares.
I will explain the algorithm soon.
The code is not complete. Please mail me if you want the whole code. I will finish the code soon.
You can see the code till now here:
Now, for the algorithm. This is the algorithm I have used, if anything is not clear, please do comment.
Final Algorithm For Chess:
1.> Check if the clicked square has BackColor as BlanchedAlmond. If so, then check the variable “PieceToBeMoved” for the piece which has to be moved
2.> According to the variable “PieceToBeMoved”, load that square with the respective image of that piece.
3.> Now, the piece has been moved to the clicked square, but the piece is also occupying its previous square. To get rid of the previous piece: In a variable square, store the location of the piece when it is clicked and when the image is being loaded on the new location, check which square has to be cleared. Also, update the position of the piece.
4.>Now, if the backcolor is not blanchedalmond, then check if there is a piece on that square. If there is one, then highlight all possible squares for it to be moved on.
5.> Also, while getting rid of the previous piece, reset the colors of the various squares which have been highlighted to black or gray as the case may be.
Blanched Almond is the colour which I have used to highlight the possible squares to which a piece can be moved.