Click here to Skip to main content
13,404,713 members (36,410 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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 .

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.[^]

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 )
		    if (IsOkvertical(x,y,lenght,n)==1)

For this example we should calling ship(1,4,4)
Posted 20-Jan-13 23:12pm
Updated 21-Jan-13 0:10am
CHill60 21-Jan-13 4:29am
It's not clear what your question is and I can't use your hyperlinks
homa sh 21-Jan-13 5:04am
I change my link ..
is this OK?
CHill60 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 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 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 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.

1 solution

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

Solution 1

thanks anyone
I understand ....

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.1802120.2 | Last Updated 24 Jan 2013
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100