🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

How to create a simple chess board?

Started by
6 comments, last by krad 22 years, 9 months ago
I just want to know how to create a simple chess board, where I can move peices around. I have searched on the web and read a couple books but still couldn''t figure out how to do it. Can someone please point me into the right direction.. like what books and topics I need to read in order to acheive something like this?
Advertisement
It all depends on how much of a chess board you want.

First off, what language.

Lets take C as our language.

Is it going to be text based? Graphics?

If it has graphics, what OS, DOS, Windows, UNIX, etc.

Also, what graphics API are you using?

You first need to plan exactly what you want in your chess board before you should create it.
Read up on tile based games. You''ll need an understanding of arrays to code the board up.
Read up on tile based games. You''ll need an understanding of arrays to code the board up.
I thought someone else would mention this:

In terms of the underlying data structure, a chess board is a two-dimensional array of "squares." How you choose to represent the squares is dependent on what you wish to do with them. If you just want to know if there's a piece there, then each square could be a boolean variable, making your chessboard a 2D array of booleans.

If you want to know which piece exactly is there (which is a good idea), then each square could be a "piece descriptor" or - more efficiently - a numerical index. The total number of pieces on a chess board is 32; you can choose to use 1-16 to represent white pieces (with either 1-8 or 9-16 as the pawn; I'll explain why in a second) and 17-32 for black pieces. A value of 0 would indicate an empty square.

If you choose to have the low 8 values represent pawns, then testing whether the piece on a square is a pawn - or finding all pawns - becomes an integer greater-than or less-than comparison. ie

  // C/C++ code follows:// assume 1-8 are white pawns, 17-24 are black pawns// assume chessboard is int[8][8]// find all pawns:int num_pawns = 0;for( int i = 0; i < 8; i++ ){  for( int j = 0; j < 8; j++ )  {    if( chessboard[i][j] < 9 ) ||       (chessboard[i][j] > 16 && chessboard[i][j] < 25) )      num_pawns++;  }}  

Hope that helped.

EDIT: optimization, formatting.

Edited by - Oluseyi on October 4, 2001 11:16:13 PM
Well I want to create a graphic chessboard for Windows. I''m learning to code in C and C++.
OK, I wouldn''t suggest Windows programming just yet. Or graphics. Try creating a console based chess program before you try windows graphical chess programs.

In windows, it would consist of:

Creating the window
Creating the AI
Drawing the board and pieces
Flipping the images
Capturing the mouse
That''s all well and good, but to move the pieces meaningfully you need to be able to programmatically examine the chessboard in terms of data .

Anyway, draw the chessboard as one bitmap and put it on the screen. If you need more help than that, start here.

This topic is closed to new replies.

Advertisement