I program battleship c++ but it has problem
Revision 4
Hello
I want to program for ship game : according to blew 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 blew shape , my answer is wrong.
http://www.uploadbaz.com/msp4kd8a18ul[
^]
Can any body help me?
My is :
void General::Ship(int count,int k,int n) {
int lenght;
lenght=L[count];
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
by
homa sh.