Skip to main content
gamedev.net
🔒 Locked

Chess programming

Started by jaytee81 Sep 25, 2006 at 8:18 AM 6 replies 1.4k views
Original Post
jaytee81
jaytee81
Hi all I'm interested in programming a Chess game. At this stage it is not intended to have AI, it will be Human Vs Human on one PC or networked. I also plan to have a tutor section where beginners learn about the pieces and their respective moves and perhaps tactics. I was just wondering if anybody knew of any good links to tutorials or the like regarding programming a chess game. Thanks
MrSparkle
MrSparkle
There are some articles about chess programming on GameDev.net:
Part I

You can find the other parts here.

Christian
CzarKirk
CzarKirk
I found this page very useful:

http://www.cis.uab.edu/hyatt/boardrep.html

Create your array as one continuous one, eg 64 big, rather than 8x8. Decide wether to use a border to prevent wrapping or use 0x88 board representation. The latter is a bit harder to understand, but that's what I am using.

Create an array to store the location of all your pieces, and don't forget to record the number of pieces you have. Eg if a king is on square 32, then pieces[white][whatever] = 32. Then board[32] = whiteking (use enumeration or some constant for the pieces). Each turn cycle through all of the pieces you have in that list, and record their possible moves in an array. (This method is MUCH faster than looping through the entire board looking for pieces).

Personally I have two seperate arrays for capture and non-capture moves, in this format. moveslist[2][250][2]. The first one is for black and white (having player at the start of the array makes debugging easier, trust me). The second is the list of moves. I think the max possible moves you can have in a standard game of chess per turn is less than 250, so that's ok. Then we have a starting board coordinate and an ending one.

Then when the player enters in a move, you simply cycle through your two lists and see if the move is contained in the lists or not. Do NOT have wether a move is allowed or not generated on the fly!

The other BIG BONUS of this method is the AI. Google for minimax. Even though you don't want AI at the moment, if you setup your move system like this it is easier than you think to implement. To put it in very simple terms, the AI simply cycles and tests each move in your list and evaluates the board. A simple evaluate is add 1 point for each pawn, 2 points for knight etc... and see which one gives the most points. But more on AI once you've gotten your basic engine completed.

Well I think I've given you enough to get started. If you need more help just ask. Look at that link I gave it.

One more thing, if you're new to programming I would HIGHLY suggest you try to make a few simpler games such as connect 4 etc before starting Chess. Or it will just get too complicated and you'll get fed up. Trust me.

Good luck.
CzarKirk
CzarKirk
LOL, you weren't asking the question :P
jaytee81
jaytee81
The anonymous poster was me.
Diirewolf
Diirewolf
I whipped together a simple 2d chess game using C# and Managed DirectX. Its actually really simple. One class for piece, one for tile and one for the game.
Make an 8x8 array of tiles and each tile contains reference to a piece that it contains, if no piece then the reference will be null. Also each piece contains its location and locationInPixels. you will use location in pixels to draw the piece. So now what you do is when the mouse is clicked, you check the tile that was clicked using a simple Rectangle.Contains(Rectangle). Then if there is a piece owned by the current player in that tile, then make that piece selected. Also when the piece is selected, calculate the possible move locations and possible 'kill' locations. thats about it, when the king dies, Message box, game over, player n has won! :D Im currently trying to convert my chess game into 3d so ill get bak to that. Good luck on making the game! lemme see it once its done: prism_15@hotmail.com
CzarKirk
CzarKirk
Although that might seem the easiest, having the moves generated "on the go" will make the AI almost impossible. How did you accomodate for checks, stopping a user from going into check?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.