473,670 Members | 2,527 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2695
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*******@gmai l.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.l earn.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*******@gmai l.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

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

Similar topics

4
2269
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 ... We have to have the notions of colors, squares and pieces represented. Ideally, we want to be able to do things like initializing the board: void initial() {
7
2622
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 hashtable is to store HashEntry objects, which contain information about chess positions. A BitBoard is just an __int64, and this is used to determine the hash key. I have not shown the definition of class ChessPosition, but all you need to know is...
1
2486
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 as in any other chess clients. Now i want to interface my program with the already available gnuchess program. Basically i want to feed the user input to the gnuchess and get the output and then display in my GUI. I have read about Popen but i...
6
3096
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 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:
63
15227
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 http://www.mailcom.com/ioccc/toledo/hint.htmBut this post is because I have discovered (asurprise for me) that it is also the worldsmallest chess program written in C language.It has a size of 3004 bytes, or 2261 bytes simplydeleting all the spacing that makes the knightfigure, cutting...
0
8810
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8659
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7410
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5683
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4208
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4387
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2798
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2035
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1790
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.