Silkroad Online Forums

A community forum for the free online game Silkroad Online. Discuss Silkroad Online, read up on guides, and build your character and skills.

Faq Search Members Chat  Register Profile Login

All times are UTC




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Re: Simple C question *shape* (Diamond with an empty box inside)
PostPosted: Thu Nov 10, 2011 10:38 pm 
Ex-Staff
User avatar
Offline

Joined: Jan 2008
Posts: 2761
Location: /wave
Since you're not allowed to have jump conditions, the easiest way to do it with the code you already have is to break it into 4 different for loops rather than the 2 that you have.

First thing you'd have to do is have a variable that tells you how many holes you need Max(N-2,0) or just n-2 if you can assume N has min 3.

Then you can do a bit of trickery to know when you need holes. Implement a counter variable that starts at zero and increments every time you print a *. Wrap your first loop in a while statement that runs until the counter variable is equal to N (i.e. the number of starts you printed is equal to N which starts the empty box).

The second/third part of the code is simple, it's basically what you have but with empty boxes, since you have a variable with the box height/width (n-2) modify your code so that you draw n-2 spaces after stars starting with 2 stars until you get to one above the center. Then draw the bottom part of the with the n-2 spaces in the middle.

Last part of the code is like the first part, wrap it in a while loop with a counter, exit the while loop when your counter = 1.


Top
 Profile  
 
 Post subject: Re: Simple C question *shape* (Diamond with an empty box inside)
PostPosted: Fri Nov 11, 2011 12:18 am 
Forum God
User avatar
Offline

Joined: Aug 2006
Posts: 8834
Location: Age of Wushu
first analyse:
- n = half size of the box
- center index = [2;2] <=> [(n+1)/2;(n+1)/2]
- this box is symmetric, you can create small task then just do the "mirror"
- it's hard if you print directly the "*"

algorithm (not in C):
- create an array of arrays size n*2-1 x n*2-1 (n=5 => size = 9)
- fill all the arrays with "*"
- fill the top-left corner a blank triangle

for (i=0; i<n-1; i++)
{ --rows
for (i=0; j<n-i-1; i++) --column
fill blank
}

- repeat for all corner
- fill the middle with blank where
index range = 0 -> n-1
start position = [(n+1)/2 ; (n+1)/2
end position = [(n-1) - (n+1)/2 ; (n-1) - (n+1)/2]

_________________
Playing Age of Wushu, dota IMBA


Top
 Profile  
 
 Post subject: Re: Simple C question *shape* (Diamond with an empty box inside)
PostPosted: Fri Nov 11, 2011 2:02 am 
Forum God
User avatar
Offline

Joined: Aug 2006
Posts: 8834
Location: Age of Wushu
nevermind about what I said.

check if the current point is inside the zone [(n+1)/2 ; 2(n-1) - (n+1)/2], if yes then do not print it

_________________
Playing Age of Wushu, dota IMBA


Top
 Profile  
 
 Post subject: Re: Simple C question *shape* (Diamond with an empty box inside)
PostPosted: Fri Nov 11, 2011 3:27 am 
Ex-Staff
User avatar
Offline

Joined: Jan 2008
Posts: 2761
Location: /wave
I'm at school, I'll edit this post when I get home in 1.5 hrs with some concrete code, hopefully that'll help.


Top
 Profile  
 
 Post subject: Re: Simple C question *shape* (Diamond with an empty box inside)
PostPosted: Fri Nov 11, 2011 5:13 am 
Ex-Staff
User avatar
Offline

Joined: Jan 2008
Posts: 2761
Location: /wave
http://codepad.org/e0L2crAN

Here you go, it's a shell for what you should be thinking of. Obviously it's more verbose than you need so you can change the var names to i/j/z/whatever but it should be pretty clear, if it's not you can im me or something, just shoot me a pm. I've obviously commented out the part you should be trying to do, but just follow my first code block example. You'll have to draw the bottom of the diamond as well.


Top
 Profile  
 
 Post subject: Re: Simple C question *shape* (Diamond with an empty box inside)
PostPosted: Fri Nov 11, 2011 11:57 am 
Forum God
User avatar
Offline

Joined: Aug 2006
Posts: 8834
Location: Age of Wushu
http://codepad.org/vUSSC2TY

Spoiler!


Replace fabs for optimization, but it's less understandable than the first
http://codepad.org/N4I72K7C

_________________
Playing Age of Wushu, dota IMBA


Top
 Profile  
 
 Post subject: Re: Simple C question *shape* (Diamond with an empty box inside)
PostPosted: Fri Nov 11, 2011 12:48 pm 
Ex-Staff
User avatar
Offline

Joined: Jan 2008
Posts: 2761
Location: /wave
He can't use if statements nuke :/ That's why my code looks retarded lol.


Top
 Profile  
 
 Post subject: Re: Simple C question *shape* (Diamond with an empty box inside)
PostPosted: Fri Nov 11, 2011 1:04 pm 
Ex-Staff
User avatar
Offline

Joined: Jan 2008
Posts: 2761
Location: /wave
Oh, if you can use if statements use nuke's code, my code is downright retarded because I had to do a workaround for no ifs. fabs is just absolute value, just say you googled it.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 43 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group