Making a chess board in the console

  • Thread starter Thread starter finchie_88
  • Start date Start date
  • Tags Tags
    Board Chess
Click For Summary

Discussion Overview

The discussion revolves around programming a chess board in a console application, focusing on the implementation of the board's visual representation using loops. Participants are sharing coding strategies and troubleshooting issues related to drawing the board and its squares.

Discussion Character

  • Technical explanation
  • Mathematical reasoning
  • Debate/contested

Main Points Raised

  • One participant outlines the basic structure of the chess board and seeks help with using for loops to draw it, mentioning dimensions for each square.
  • Another participant suggests using two nested for loops to iterate over the width and height of the board, providing conditions for drawing the vertical and horizontal frames based on modulo operations.
  • A participant expresses difficulty in implementing the loops correctly to achieve the desired board layout, providing a visual representation of what they aim to create.
  • Further clarification is offered on using if statements within the loops to determine the color of each square based on their coordinates.
  • One participant acknowledges understanding the method after initial confusion and expresses gratitude for the assistance.
  • A later reply indicates ongoing issues with the implementation, sharing a code snippet and questioning how to draw the remaining squares after successfully drawing half of them.

Areas of Agreement / Disagreement

Participants generally agree on the approach of using nested loops to draw the chess board, but there are unresolved issues regarding the implementation details and achieving the desired output.

Contextual Notes

Participants have not reached a consensus on the specific implementation of the loops, and there are indications of missing assumptions or details in the provided code snippets.

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:
Technology 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:
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...
 
Oh rite, now I understand what you mean. Thank you for the help, I don't think I fully understood the first time round.:approve: Thank you.
 
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:

Similar threads

  • · Replies 42 ·
2
Replies
42
Views
5K
  • · Replies 37 ·
2
Replies
37
Views
5K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 25 ·
Replies
25
Views
5K
  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 25 ·
Replies
25
Views
18K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 10 ·
Replies
10
Views
4K
  • · Replies 33 ·
2
Replies
33
Views
6K
  • · Replies 7 ·
Replies
7
Views
16K