Chess boards are two dimensional items - they have a length and a width. You can call that a height and a width if you want.
They have no "thickness" whatsoever.
This is not a perfect console board, as you'll notice that the pieces (represented by their values here), are not quite in their correct row, inside the square.
The board is basically good though, allowing the piece to be centered (the piece should be either one or three columns wide).
If your compiler can't handle conio.h, you'll be stuck with the gotoxy(), let me know and I'll set it up for Windows SetConsoleCursorPosition() for you.
Code:
//this program just displays an 8 x 8 board
#include <stdio.h>
#include <conio.h>
int left; //left edge of board
int right; //right edge of board
int width; //width of square in cols
int top; //top row
int bottom; //bottom row
int row;
int col;
int board[8][10]; //the current playing board-it is 10 columns wide to allow the
//use of pairs of digits for representing the board in this array see page 159 in
//How Computers Play Chess
int number;
int main(void) {
void Newboard();
int i;
left=2; //left edge of board
right=left+40; //right edge of board
width=5; //width of square in cols
top=2; //top row
bottom=top+16; //bottom row
Newboard();
i = getchar(); ++i;
return 0;
}
void Newboard() {
void Drawsq(char sqr, int col, int row);
void Putpieces();
const unsigned char bsqr = '\xB0'; //black square
const unsigned char wsqr = '\xB2'; //white square
unsigned char sqr= wsqr;
int j, color = 0;
for(row=0;row<8;row++) {
for(col=0;col<10;col++)
board[row][col] = 0;
if(row==0) {
board[row][0]=4;board[row][1]=2;board[row][2]=3;
board[row][3]=5;board[row][4]=6;board[row][5]=3;
board[row][6]=2;board[row][7]=4;board[row][8]=99;
board[row][9]=99;
}
if(row==1) {
board[row][0]=1;board[row][1]=1;board[row][2]=1;
board[row][3]=1;board[row][4]=1;board[row][5]=1;
board[row][6]=1;board[row][7]=1;board[row][8]=99;
board[row][9]=99;
}
if(row==6) {
board[row][0]=-1;board[row][1]=-1;board[row][2]=-1;
board[row][3]=-1;board[row][4]=-1;board[row][5]=-1;
board[row][6]=-1;board[row][7]=-1;board[row][8]=99;
board[row][9]=99;
}
if(row==7) {
board[row][0]=-4;board[row][1]=-2;board[row][2]=-3;
board[row][3]=-5;board[row][4]=-6;board[row][5]=-3;
board[row][6]=-2;board[row][7]=-4;board[row][8]=99;
board[row][9]=99;
}
} //end of for row (for col is not braced)
clrscr();
for(row=top;row<bottom;row+=2) {
if (color>0) { //swap color of sqr every row
color=0;
if(sqr==wsqr)
sqr=bsqr;
else
sqr=wsqr;
}
for(col=left;col<right;col+=5) {
gotoxy(col,row);
Drawsq(sqr, col, row);
color ++;
if (color>0) {
color=0;
if(sqr==wsqr) //swap color of sqr every col too
sqr=bsqr;
else
sqr=wsqr;
}//end of if
} //end of for col
color ++;
} //end of for row
Putpieces();
}
void Drawsq(char sqr, int col, int row) {
int j;
gotoxy(col, row); //top half of sqr
for(j=0; j<5; j++)
putch(sqr); //each square is 5 cols X 2 rows
gotoxy(col,row+1);
for(j=0; j<5; j++) //lower half of sqr
putch(sqr);
number++;
gotoxy(30,20);
printf("Been Here %d Times", number);
}
void Putpieces() {
int j, k, midrow, midcol;
midrow=bottom-2;
midcol=left+2;
for(k=0;k<8;k++) {
for(j=0;j<8;j++) {
gotoxy(midcol,midrow);
if(board[k][j]!=0)
printf("%d",board[k][j]);
midcol+=width;
}
midcol=midcol-(8*width);
midrow-=2;
}
}
If you want a much more basic type of chessboard, let me know.
You'll notice that the board isn't "square" any more. And the height of each square is just two char's.
Change that to 3 char's, and adjust your font until it is square. This board is perfectly square with a much smaller font size, but that's impractical with modern monitors. To change your font size on the console window, put the mouse pointer on the top bar of the console window, and right click on it. Then choose "properties" and "fonts". Save it when you get it right, as the default for the console window.
You can also change your console window by using the Windows API.
This is what it looks like: