Making a chess board in the console

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

The discussion focuses on creating a chess board in the console using C++. The user is implementing a two-player game that displays the board using for loops to manage the dimensions of each square, estimated at 9 console units wide and 5 units tall. Key techniques include using nested for loops to iterate through the board's dimensions and conditionally drawing squares based on their position. The user also addresses color contrast by utilizing white and red backgrounds to enhance visibility for black pieces.

PREREQUISITES
  • Basic understanding of C++ programming
  • Familiarity with console output manipulation
  • Knowledge of nested loops and conditional statements
  • Experience with console cursor positioning in C++
NEXT STEPS
  • Implement and refine nested for loops for console graphics in C++
  • Explore the use of arrays to represent game pieces and their positions
  • Learn about console color manipulation in C++ for better visual contrast
  • Research techniques for handling user input in console applications
USEFUL FOR

Game developers, C++ programmers, and anyone interested in creating console-based applications or games.

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:
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...

Similar threads

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