473,324 Members | 2,541 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Need help with the simple chess program in C

I have been trying to create this chess program from many hours and
still couldn't figure out how to complete it. After consume all these
efforts i come to this google groups for the first time for help. i
would appreciate if somebody help me out of this to debug the program
below. The chess board suppose to be printed with "*" and space " " as
you can see below as an example. Again I would appreciate for your help
in advance.

sample print or output:

***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
#include <iostream>

using namespace std;

int main()
{
for (int row = 1; row < 9; row++)// Draw big row 8 times
{
for (int row1 = 1; row1 < 4; row1++) //Draw a little row 3 times
{
for (int col = 1; col < 9; col++) //Draw a big column 8 times
{
for (int col1 = 1; col1 < 6; col1++) //Draw a character 5
times
{
if (col % 2 == 0 && row % 2 == 0)
{
cout <<' ';
}
else
{
cout << '*';
}
if(col1%2 == 0 && row1 % 2 ==0)
{
cout <<' ';
}
else
{
cout << '*';
}
}

}
}
}

return 0;
} // function main

Nov 17 '06 #1
13 2669
as*****@hotmail.com wrote:
I have been trying to create this chess program from many hours and
still couldn't figure out how to complete it. After consume all these
efforts i come to this google groups for the first time for help.
This is not google groups. It's NNTP. Google offers an interface
to NNTP newsgroups along with the interface to Google Groups. I
think they actually tell you that this is not Google Groups.

This is also comp.lang.c, if you don't have questions related to
the C language try a different group. So, the code you provide
should be standard ISO C.
i
would appreciate if somebody help me out of this to debug the program
below. The chess board suppose to be printed with "*" and space " " as
you can see below as an example. Again I would appreciate for your help
in advance.

sample print or output:

***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
#include <iostream>
This is not a standard header in C.
>
using namespace std;
This fails to compile.
>
int main()
int main(void) in C.
{
for (int row = 1; row < 9; row++)// Draw big row 8 times
You can't declare row like this in C. There are some compilers
that would allow you to do this as an extension (gcc does, I
think) but it's not standard C.
{
for (int row1 = 1; row1 < 4; row1++) //Draw a little row 3 times
{
for (int col = 1; col < 9; col++) //Draw a big column 8 times
{
for (int col1 = 1; col1 < 6; col1++) //Draw a character 5
times
{
if (col % 2 == 0 && row % 2 == 0)
{
cout <<' ';
}
else
{
cout << '*';
}
if(col1%2 == 0 && row1 % 2 ==0)
{
cout <<' ';
}
else
{
cout << '*';
}
}

}
}
}

return 0;
} // function main
I think there's a mistake every two lines but I'll stop before I
get to be too annoying :-). Your code is not C, it's C++. For C++
code try comp.lang.c++, or, if you want to solve that problem in
C, write C code and come back here for help.

--
Ioan - Ciprian Tandau
tandau _at_ freeshell _dot_ org (hope it's not too late)
(... and that it still works...)
Nov 17 '06 #2
as*****@hotmail.com wrote:
I have been trying to create this chess program from many hours and
still couldn't figure out how to complete it. After consume all these
efforts i come to this google groups for the first time for help. i
would appreciate if somebody help me out of this to debug the program
below.
<snip C++ code>

This group, as you can see by it's name, deals with the C language.
Your program is in C++. Ergo, post to comp.lang.c++ or some other group
that deals with C++.

Nov 17 '06 #3
On Thu, 16 Nov 2006 22:54:42 -0500, Nelu <sp*******@gmail.comwrote
in comp.lang.c:
as*****@hotmail.com wrote:
[snip]
{
for (int row = 1; row < 9; row++)// Draw big row 8 times

You can't declare row like this in C. There are some compilers
that would allow you to do this as an extension (gcc does, I
think) but it's not standard C.
Actually it is. And has been since October 1999, more than 7 years
now.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Nov 17 '06 #4
as*****@hotmail.com wrote:
>
I have been trying to create this chess program from many hours and
still couldn't figure out how to complete it. After consume all these
efforts i come to this google groups for the first time for help. i
would appreciate if somebody help me out of this to debug the program
below. The chess board suppose to be printed with "*" and space " " as
you can see below as an example. Again I would appreciate for your help
in advance.

sample print or output:

***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****

#include <iostream>
comp.lang.c++ is thataway --->

You have not come to google groups, you have come to the usenet
news system, to which google is only an extremely poor interface.
If you try, you can get some use out of it, but you would be better
advised to get a real newsreader.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>

Nov 17 '06 #5
Jack Klein wrote:
On Thu, 16 Nov 2006 22:54:42 -0500, Nelu <sp*******@gmail.comwrote
in comp.lang.c:
>as*****@hotmail.com wrote:

[snip]
>>{
for (int row = 1; row < 9; row++)// Draw big row 8 times
You can't declare row like this in C. There are some compilers
that would allow you to do this as an extension (gcc does, I
think) but it's not standard C.

Actually it is. And has been since October 1999, more than 7 years
now.
I take that back. You're right. I actually read about it on the
gcc mailing list a while (few years) back, but I forgot.

--
Ioan - Ciprian Tandau
tandau _at_ freeshell _dot_ org (hope it's not too late)
(... and that it still works...)
Nov 17 '06 #6
as*****@hotmail.com said:

[Subject: Need help with the simple chess program in C]
I have been trying to create this chess program from many hours and
still couldn't figure out how to complete it.
That's probably because you were using the wrong language.
After consume all these
efforts i come to this google groups for the first time for help.
No, you came to Usenet. You came /through/ Google Groups. There are plenty
of doors into this place, and Google Groups is just one of them.
i
would appreciate if somebody help me out of this to debug the program
below. The chess board suppose to be printed with "*" and space " " as
you can see below as an example. Again I would appreciate for your help
in advance.

sample print or output:

***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
Okay, your first debugging step is to throw away all your code, because it
is not written in the language you require.

Step 2 is to write a function that displays a row of N characters, all the
same:

#include <stdio.h>

int print_repeated_char(FILE *fp, int c, int n)
{
int i;
for(i = 0; i < n; i++)
{
putc(c, fp);
}
return ferror(fp);
}

Next, you want to be able to print a complete line of the chessboard:

int print_chess_row(FILE *fp,
int sqh, /* how many lines per square (3 in your eg) */
int sqw, /* how many columns per square (5 in eg) */
int black,/* character to use for black */
int white,/* character to use for white */
int rowlen, /* 8 for normal chess! */
int startwithwhite /* 0 = start with black */
)
{
int r = 0; /* row */
int t = 0; /* temp for colour */
int c = 0; /* column */

for(r = 0; r < sqh; r++)
{
t = startwithwhite ? white : black;
for(c = 0; c < rowlen; c++)
{
print_repeated_char(fp, t, sqw);
t = (t == white) ? black : white;
}
putc('\n', fp);
}
return ferror(fp);
}

Now it's time to write a quick test driver.

int main(void)
{
int i;
for(i = 0; i < 8; i++)
{
print_chess_row(stdout, 3, 5, '*', '_', 8, i % 2);
}
return 0;
}

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: normal service will be restored as soon as possible. Please do not
adjust your email clients.
Nov 17 '06 #7
as*****@hotmail.com writes:
I have been trying to create this chess program from many hours and
<snip>
sample print or output:

***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
Another way to look at it is that one is mapping a {0,1} valued
function over a 2D array of pixels:

#include <stdio.h>

int main(void)
{
const int lines_per_row = 3;
const int chars_per_col = 5;
int l, c;

for (l = 0; l < 8 * lines_per_row; l++) {
for (c = 0; c < 8 * chars_per_col; c++)
putchar(((l / lines_per_row) + (c / chars_per_col)) % 2 ? ' ' : '*');
putchar('\n');
}

return 0;
}

I don't think this has any advantages other being open interesting
variations.

--
Ben.
Nov 17 '06 #9
Yes, this is the wrong group but i have a suggestion for you... If you
are going to write a chess program that does anything more than display
a board, you probably want to read up on minmax tree algorithms for the
computer AI. They dont have to be that hard to code and still be
effective. I have been playing chess for a while but my simple chess
program still beats me. Im not sure if thats a good or bad thing. Good
luck with your program.

Regars Patrik

Nov 17 '06 #10
Richard Heathfield <in*****@invalid.invalidwrites:
as*****@hotmail.com said:

[Subject: Need help with the simple chess program in C]
>I have been trying to create this chess program from many hours and
still couldn't figure out how to complete it.

That's probably because you were using the wrong language.
>After consume all these
efforts i come to this google groups for the first time for help.

No, you came to Usenet. You came /through/ Google Groups. There are plenty
of doors into this place, and Google Groups is just one of them.
[...]
Okay, your first debugging step is to throw away all your code, because it
is not written in the language you require.
Either that, or you need to ask about it in a different newsgroup.
Nobody will object if you choose to implement it in C++; we just can't
help you with C++ here.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 17 '06 #11
Keith Thompson said:
Richard Heathfield <in*****@invalid.invalidwrites:
<snip>
>
>Okay, your first debugging step is to throw away all your code, because
it is not written in the language you require.

Either that, or you need to ask about it in a different newsgroup.
Nobody will object if you choose to implement it in C++; we just can't
help you with C++ here.
He specifically wants to write it in C. It says so in the Subject line.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: normal service will be restored as soon as possible. Please do not
adjust your email clients.
Nov 17 '06 #12
Richard Heathfield <in*****@invalid.invalidwrites:
Keith Thompson said:
>Richard Heathfield <in*****@invalid.invalidwrites:
<snip>
>>
>>Okay, your first debugging step is to throw away all your code, because
it is not written in the language you require.

Either that, or you need to ask about it in a different newsgroup.
Nobody will object if you choose to implement it in C++; we just can't
help you with C++ here.

He specifically wants to write it in C. It says so in the Subject line.
He specifically wants to write it in C++. It says so in the code
fragment he posted. We know they can't both be right, but we can't
tell which.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 17 '06 #13
Thanks for your response and for correction that the program is not C.
Its a silly of me for posting the question in a wrong group. But, i
still appreciate for the prompt response.

Nelu wrote:
as*****@hotmail.com wrote:
I have been trying to create this chess program from many hours and
still couldn't figure out how to complete it. After consume all these
efforts i come to this google groups for the first time for help.

This is not google groups. It's NNTP. Google offers an interface
to NNTP newsgroups along with the interface to Google Groups. I
think they actually tell you that this is not Google Groups.

This is also comp.lang.c, if you don't have questions related to
the C language try a different group. So, the code you provide
should be standard ISO C.
i
would appreciate if somebody help me out of this to debug the program
below. The chess board suppose to be printed with "*" and space " " as
you can see below as an example. Again I would appreciate for your help
in advance.

sample print or output:

***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
#include <iostream>

This is not a standard header in C.

using namespace std;

This fails to compile.

int main()

int main(void) in C.
{
for (int row = 1; row < 9; row++)// Draw big row 8 times

You can't declare row like this in C. There are some compilers
that would allow you to do this as an extension (gcc does, I
think) but it's not standard C.
{
for (int row1 = 1; row1 < 4; row1++) //Draw a little row 3 times
{
for (int col = 1; col < 9; col++) //Draw a big column 8 times
{
for (int col1 = 1; col1 < 6; col1++) //Draw a character 5
times
{
if (col % 2 == 0 && row % 2 == 0)
{
cout <<' ';
}
else
{
cout << '*';
}
if(col1%2 == 0 && row1 % 2 ==0)
{
cout <<' ';
}
else
{
cout << '*';
}
}

}
}
}

return 0;
} // function main

I think there's a mistake every two lines but I'll stop before I
get to be too annoying :-). Your code is not C, it's C++. For C++
code try comp.lang.c++, or, if you want to solve that problem in
C, write C code and come back here for help.

--
Ioan - Ciprian Tandau
tandau _at_ freeshell _dot_ org (hope it's not too late)
(... and that it still works...)
Nov 17 '06 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: David Rasmussen | last post by:
The problem comes up in all sorts of contexts. But here is an example: We want to model the basics of chess, maybe for making a chess program, or maybe just to make an interactive board or ... ...
7
by: JN | last post by:
Hello. Sorry about the length of this post. I am trying to implement a hash table for my chess program, and decided to try using the VC++ . NET (Dinkumware) version of hash_map. The role of the...
1
by: Varun Hiremath | last post by:
Hello, I have written a chess client using python which is a graphic interface to play chess. It is at present a two player version, players move their peices by clicking two squares on the board...
6
by: asif929 | last post by:
I have been trying to create this chess program from many hours and still couldn't figure out how to complete it. After consume all these efforts i come here for the first time for help. i would...
63
by: biyubi | last post by:
Hi, a year ago I won the 2005 Best Game categoryof the International Obfuscated C Code Contestwith a chess program. http://www.ioccc.org/whowon2005.html...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.