Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++
Hello
I want to program for ship game : according to below text
For example we have 4 ship and we have a table 4*4 and we want put ship in this table according to capacity of column and row.
Therefore I used backtracking and for this shape is true answer .
 
http://upload.ugm.ac.id/434shape.docx

It is true answer when we have ships enter with this order : ship 1-ship2- ship3-ship4
But if ships had this order : ship 2-ship1- ship3-ship4 the answer will be wrong.
Actually if input shape was according to below shape , my answer is wrong.
 
http://upload.ugm.ac.id/434shape.docx[^]

Can any body help me?
My code is :
 
void General::Ship(int count,int k,int n)  //  count <= k  
{
	 int lenght;
 
	lenght=L[count];    // L contan ships length means for example 2:is 3-2-2-2

	for (int x=1;x<=n;x++)
	{
		for(int y=1;y<=n;y++)
		{
			if (IsOkhorizontal(x,y,lenght,n)==1 )
			{
				Horizontally(x,y,lenght,count,n);
				if(count==k)
				{
					Print();
				}
				else
					Ship(count+1,k,n);
			}
		    if (IsOkvertical(x,y,lenght,n)==1)
			{
			    Vertically(x,y,lenght,count,n);
				if(count==k)
				{
					Print();
				}
				else
					Ship(count+1,k,n);
			}
			
		}	
	}
}
 
For this example we should calling ship(1,4,4)
thanks
Posted 20-Jan-13 22:12pm
homa sh274
Edited 20-Jan-13 23:10pm
v7
Comments
CHill60 at 21-Jan-13 4:29am
   
It's not clear what your question is and I can't use your hyperlinks
homa sh at 21-Jan-13 5:04am
   
I change my link ..
is this OK?
CHill60 at 21-Jan-13 8:33am
   
Sorry - when I said I can't use your hyperlinks it's because I'm at work and that site is blocked by our firewall. We're still not sure what your question is though
homa sh at 21-Jan-13 9:41am
   
actually we have a table n*n and some ships . we should put ships in table so that sum numbers row and column not larger than number of top of table.
 
i think shape is clear .
Quirkafleeg at 24-Jan-13 12:31pm
   
The problem with this is hard to diagnose. Your variable names remind me of horror stories that I've been told about 30 year old code; you are allowed - and recommended - to give your variables meaningful names, rather single letters.
 
For example, the parameters "k" and "n" do not help anyone here scan your code for immediate issues. What it does instead is force us to spend more time than we should examining (and decrypting) the code.
Most of us are either too busy or too lazy to do that.
 
I am probably similar to a number of users by a being averse to having to download things (which is what your hyperlink asks me to do!) - it adds to the "we are having to spend far more time on this than we should" argument.
 
What also makes it difficult is the other functions that this code calls - there is no code snippets of these functions. As such, when you say "It not worky!", there is no evidence to show what the expected output and the actual output is.
From what I can see, the code snippet seemingly has no problems - the real problem may lie in the code you have not posted, e.g. "Horizontally" or "Vertically" (do these change the value of count?)
 
So I am sorry to sound harsh, but I cannot help you without at least more code logic - and I'm guessing other people would post a similar request.
Sergey Alexandrovich Kryukov at 30-Jun-13 17:06pm
   
Please don't post non-answers as "solution". It can give you abuse reports which eventually may lead to cancellation of your CodeProject membership.
Comment on any posts, reply to available comments, or use "Improve question" (above).
Also, keep in mind that members only get notifications on the post sent in reply to there posts.
—SA

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

thanks anyone
I understand ....
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web02 | 2.8.140709.1 | Last Updated 24 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid