# Making a chess board in the console

finchie_88
Hello everyone. I have now finished my tetris program, and was planning on starting on a chess game in the console (it will be 2 player, playing at the same terminal - no winsock at the moment). Anyway, I have already set up the basics, however, I need a little help in programming the board. I was thinking about using a few for loops, although, I'm a bit unsure how to implement them. Each square of the chess board will be 9 console units across, and 5 console units down (although, these are just estimates - I might change them, so the board looks better). Any help, regardless of what it may be would be greatly appreciated.

Edit: Also, because of the sides will be white and red, otherwise, the black pieces would not stand out against the black background.

Last edited by a moderator:

Related Programming and Computer Science News on Phys.org
I'm not sure i understand what your problem is....

are you having difficulties in drawing the squares?
you only need two for loops to draw everything, one that goes over the width, and one that goes over the height.

for drawing the vertical frame you'll need x%9 to be zero and for the horrizontal y%5... (to draw them every 9 steps or every 5 steps respectively).

you need to draw the chess peices in this loop too, make an array which represent the board, and check if the spot you draw contains a piece, make an array that contains each shape (3x7 i guess), and copy it over as you draw with these two for statements...

Last edited:
finchie_88
I can't quite get the loops right, so that it gives me a nice board. btw, I'm only drawing the board at the moment. There is another function that will draw the pieces on over the top.

The board I want is like this:
wwwwwwwwwbbbbbbbbbwwwwwwwww etc.
w .
w .
w .
w .
b
b
b
b
b
etc.

where b and w are black and white respectively.

Last edited by a moderator:
I already explained how to draw such a board...

use two for loops, one inside the other, one will be the x value and the second would be the y value, so youre scanning all the possible values on your board, just use if statements inside the loops to determine if you should draw whith or black... if (x/9)%2, if (y/5)%2...

finchie_88
Oh rite, now I understand what you mean. Thank you for the help, I don't think I fully understood the first time round. Thank you.

finchie_88
I'm still having a few problems with it, even with those suggestions. I understand the method, it's a question of implementing it.

This is the loop I have at the moment:
Code:
int i,j;
for(j=0;j<40;j++)
{
for(i=0;i<72;i++)
{
Position.X = i;
Position.Y = j;
SetConsoleCursorPosition(hOut, Position);
if( (((i/9)%2) < 1)&&(((j/5)%2) < 1) ) {
cout << (unsigned char)219;
}
}
hOut, refers to the handle to the window.
This if statement gives half of the squares, the problem is, what if would give the other half?
Edit: Sorry, just figured it out.

Last edited by a moderator: