C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old February 8th, 2008, 10:35 PM
ashuaki's Avatar
ashuaki ashuaki is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2008
Posts: 57 ashuaki User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 9 m 10 sec
Reputation Power: 11
"Go" Game board display error

I'm having a problem with some code; It compiles fine, but it returns everything that could concievably be wrong: The purpose of the following code is to print the character interpretation of a 19x19 go board, and I can't move forward with my development until this is complete; most of my other post-it code is done. It should print:

Code:
. . . . . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . . . . 

but it prints:

Code:
    m   |  	  |              
         F   	  |      N   
      F  |   |   F  P  F  $ 
                              4  F  
P  F  D  F   5   a p   
 4  F 
 P  F          C : \ D o c u m e n 
t s   a n d   S e t t i n g s \ T h o 
m a s \ M y   D o c u m e n t s \ C + 
+ _ D e v \ g o V S \ d i s p l a y B 
o a r d 0 1 . e x e         F  9  
 a    a ,       P  F  ,       P 
 F            F            F  
4 1  | ( W  a                F 
          F     |   F    
 a    a         ,       P  F  ^ 
 F    F     a         ,       
8  F   <   a         ,       P  F 
         $       8  F  <  F   q 
 a P  F  P  F  @  F   c   a | 


And i noticed the C:\Documents and settings\ ... \goVS\displayBoard01.exe; Odd, no?

But i'm beating around the bush; the source code is:

Code:
// Test for go board display

#include <iostream.h> //For i/o reads

// Board display function declaration
void displayBoard(char aboard[19][19]);

int main()
{
char board[19][19];
int j = 0;
int i = 0;
int x = 0;

// assign one-dimensional identifiers to the mult-dimensional array (board[][]).

for (x = 0; x < 361; x++)
{
     // 361 is 19*19
     // i is board columns
     // j is board rows

	board[i][j] = {"."};
	if (i == 18) {j++; i=0;}
	i++;	
}

// call the displayBoard function to print the board to the screen

displayBoard(board);

}

void displayBoard (char aboard[19][19])
{
	int its_i;
	int its_j;
		for (its_i=0; its_i<19; its_i++)
		{
			for (its_j=0; its_j<19; its_j++)
			{
				cout << aboard[its_i][its_j] << " ";
			}
		cout << "\n";
		}
}
	


I think my problem might be with my multidimensional array; but I'm not sufficiently experienced to see it, apparantly. So, once again, my noobie cry goes out: Help!

P.S.: May I please say that I am somewhat pleased with the roughly 19x19 shape of the erroneous output

Reply With Quote
  #2  
Old February 10th, 2008, 12:09 PM
Hypnotik Hypnotik is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2007
Posts: 128 Hypnotik User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 10 h 30 m 28 sec
Reputation Power: 12
Hello. I compiled the code you had posted and there were all kinds of errors. The first was in the

Code:

board [i][j] = {"."}


You have braces around the period, not parenthesis. It was also drilled into my head to initialize arrays, so when you declare it you know what is in the array. You could end up with "garbage" in your array. Try initializing everything to zero. The other issue is that you don't have loops around the code that I posted above. You are in essence setting board [0][0] = ".", and not the entire board. You need some nested for loops.


If you need more assistance please post, but that should be enough to get you started.

Good luck,
Jeff

Reply With Quote
  #3  
Old February 10th, 2008, 02:00 PM
ashuaki's Avatar
ashuaki ashuaki is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2008
Posts: 57 ashuaki User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 9 m 10 sec
Reputation Power: 11
Code redone:

I fixed what you said, and I'll compile it when I get a chance, but until then, this is what i have:

Code:
// Test for go board display

#include <iostream.h> //For i/o reads

// Board display function declaration
void displayBoard(char aboard[19][19]);

int main()
{
char board[19][19];
int j = 0;
int i = 0;
int x = 0;

// assign one-dimensional identifiers to the mult-dimensional array (board[][]).

for (i = 0; i < 19; i++)
{
	for (j = 0; j < 19; j++)
	{
		board[i][j] = (".");
	}
}

// call the displayBoard function to print the board to the screen

displayBoard(board);

}

void displayBoard (char aboard[19][19])
{
	int its_i;
	int its_j;
		for (its_i=0; its_i<19; its_i++)
		{
			for (its_j=0; its_j<19; its_j++)
			{
				cout << aboard[its_i][its_j] << " ";
			}
		cout << "\n";
		}
}


Are you saying that I should also do another for() loop to set everything to 0 before I assign . to everything? It seems like a full flush that 0 would do would be mirrored by an array-wide assignment to any single character (and remember that it's a character array, I'm not sure that it'll hold integers)

Reply With Quote
  #4  
Old February 10th, 2008, 02:03 PM
ashuaki's Avatar
ashuaki ashuaki is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2008
Posts: 57 ashuaki User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 9 m 10 sec
Reputation Power: 11
P.s.

Btw, If you thought the first code I posted was ugly, you should have seen the heinous crap that was the original code written by me at 1:30 in the morning awake on coffee. I actually think that I attempted to initialize board[donkey][hyena] to frittercake. Go figure.

Reply With Quote
  #5  
Old February 11th, 2008, 12:29 AM
Hypnotik Hypnotik is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2007
Posts: 128 Hypnotik User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 10 h 30 m 28 sec
Reputation Power: 12
No you're 2 for loops are good. When I was saying to initialize everything to zero, you can do it when you declare your board array.

board [19][19]={0}

Will get rid of any garbage in there.

Also...I actually made a mistake when I told you about the braces. I had to change your statement to this to get it to compile

board[i][j]= '.'

We may be compiling on different progs so do which ever works.

Jeff

Reply With Quote
  #6  
Old February 11th, 2008, 09:42 AM
ashuaki's Avatar
ashuaki ashuaki is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2008
Posts: 57 ashuaki User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 9 m 10 sec
Reputation Power: 11
just for reference, i'm using G++ under WinXP sp2

Reply With Quote
  #7  
Old February 11th, 2008, 01:26 PM
MaHuJa's Avatar
MaHuJa MaHuJa is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Dec 2007
Posts: 1,177 MaHuJa User rank is Private First Class (20 - 50 Reputation Level)MaHuJa User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 1 Day 21 h 27 m 36 sec
Reputation Power: 13
Send a message via Skype to MaHuJa Send a message via XFire to MaHuJa
Code:
for (i = 0; i < 19; i++)
{
	for (j = 0; j < 19; j++)
	{
		board[i][j] = (".");
	}
}


That part doesn't compile for me, using '.' instead works; and it also gives the desired output.

It was probably a problem of the assignment not working as you wanted.

Reply With Quote
  #8  
Old February 11th, 2008, 03:10 PM
ashuaki's Avatar
ashuaki ashuaki is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2008
Posts: 57 ashuaki User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 9 m 10 sec
Reputation Power: 11
Thanks everyone, it's running now!

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > "Go" Game board display error


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap