By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,375 Members | 1,116 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,375 IT Pros & Developers. It's quick & easy.

Similar to n-queens problem

P: 2
hi guys m new out here and need help with an assignment due next week.The assignmnet is some what related to eight queens problem but not fully, you can say the basic is taken from that problem.
Herez the question,
I have 4 male pieces and 4 female pieces, and a 8x8 board (like a chess board). I would like to place one piece per row such that:

there is one piece per column
no two male pieces are in adjacent rows or columns; and similarly with female pieces.
no two male pieces are in the same diagonal, and no two female pieces are in the same diagonal.
it is ok to have a male and female in the same diagonal.

the solution i tried using visual c++ is this,
Expand|Select|Wrap|Line Numbers
  1.  #include<stdio.h>
  2. #include<conio.h>
  3. #include<graphics.h>
  4. #include<dos.h>
  5.  
  6. void rook(int f,int m);
  7. void main()
  8. {
  9.  
  10. int m,f ,k=0,poly[8],i,m=0;
  11.  
  12. clrscr();
  13.  
  14. initgraph(&a,&b,"\\tc\\bgi");
  15. x=getmaxx()/8;
  16. y=getmaxy()/8;
  17. for(F=1,k+=y;m<8;i+=F,m++)
  18. for(M=1,l=0;l<8;M+=F,i++)
  19. {
  20. / IN BLACK CHEKS/
  21. setfillstyle(1,0);
  22. poly[0]=M;
  23. poly[1]=F;
  24. poly[2]=M+x;
  25. poly[3]=F;
  26. poly[4]=M+x;
  27. poly[5]=k+F;
  28. poly[6]=F;
  29. poly[7]=M+i;
  30. fillpoly(4,poly);
  31. }
  32. {
  33. ellipse((j+getmaxx()/16),(k+M)-(getmaxy()/16),0,360,17,17);
  34. fillellipse((j+getmaxx()/16),(k+M)-(getmaxy()/16),17,17); 
  35.  
  36. ellipse((F+getmaxx()/16),(k+i)-(getmaxy()/16),0,60,14,14);
  37. ellipse((F+getmaxx()/16),(k+i)-(getmaxy()/16),90,150,14,14);
  38. ellipse((F+getmaxx()/16),(k+i)-(getmaxy()/16),180,240,14,14);
  39. ellipse((F+getmaxx()/16),(k+i)-(getmaxy()/16),270,330,14,14);
  40. }
  41.  
  42. for(i=1,k+=y;m<8;i+=y,m++)
  43. for(F=1,l=0;l<8;M+=x,l++)
  44. if((l%2==1 && m%2==0) || (l%2==0 && m%2==1))
  45. if((Row==2,4,6 or 8 && Col==1,3,5 or 7) || (Row==1,3,5 or 7 && Col==2,4,6 or 8))
  46. {
  47. setfillstyle(1,0);
  48. poly[0]=j;
  49. poly[1]=i;
  50. poly[2]=j+x;
  51. poly[3]=i;
  52. poly[4]=j+x;
  53. poly[5]=k+i;
  54. poly[6]=j;
  55. poly[7]=k+i;
  56. fillpoly(4,poly);
  57. }
  58. return 0;
  59. }
  60.  
i want to know if its right or wrong and i don't know much of C++ programming and i have to convert it into that.Can some one help me n that.
thanks and regards,
Idea...
Jul 31 '07 #1
Share this Question
Share on Google+
4 Replies


weaknessforcats
Expert Mod 5K+
P: 9,197
Does it work for you?

That is, it produces the desried results. Yes?

I can only help where you are stuck but I cannot do your debugging.
Aug 1 '07 #2

P: 2
hi..
yah it does work in visual basic and outputs da desired result,but am unable 2 figure out,how 2 write in c language as da codes are in visual c,m confused as i dono much of c,i tried bt gt confused thts y asked..if anyone could help me as whch code have to be change 2 wht..
thnkx..n regards
idea
Aug 2 '07 #3

weaknessforcats
Expert Mod 5K+
P: 9,197
i dono much of c,i tried bt gt confused thts y
I'm sorry but your are kind of breaking up. Must be a bad connection.

Could you repeat that in English?
Aug 2 '07 #4

10K+
P: 13,264
hi..
yah it does work in visual basic and outputs da desired result,but am unable 2 figure out,how 2 write in c language as da codes are in visual c,m confused as i dono much of c,i tried bt gt confused thts y asked..if anyone could help me as whch code have to be change 2 wht..
thnkx..n regards
idea
See the guidelines. You will need to be able to communicate to get help.
Aug 2 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.