Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. 5Queens/5Knights on 8x8 board

5Queens/5Knights on 8x8 board

Scheduled Pinned Locked Moved C / C++ / MFC
helpjson
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Ramper
    wrote on last edited by
    #1

    I am currently trying to create a program to find all possibilities for placing 5 queens and 5 knights on an 8x8 board in such a way nothing will attack anything else. There are 16 possible solutions. My problem i am encountering, is when placing queens. It is not generating all possibilities. I believe it is just taking the first instance it finds and going with that rather than examining the rest of the row for possible solutions. Here is what I have, if you could possibly help it would be greatly appreciated. #include #include using namespace std; class QueenKnight { public: QueenKnight() { queens = 0; knight = 0; row = 8; column = 8; count = 0; for(int i= 0; i

    L D 2 Replies Last reply
    0
    • R Ramper

      I am currently trying to create a program to find all possibilities for placing 5 queens and 5 knights on an 8x8 board in such a way nothing will attack anything else. There are 16 possible solutions. My problem i am encountering, is when placing queens. It is not generating all possibilities. I believe it is just taking the first instance it finds and going with that rather than examining the rest of the row for possible solutions. Here is what I have, if you could possibly help it would be greatly appreciated. #include #include using namespace std; class QueenKnight { public: QueenKnight() { queens = 0; knight = 0; row = 8; column = 8; count = 0; for(int i= 0; i

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Hi, I did not study your code in detail, but have two remarks. your code would be (more) readable when you: - show it inside PRE tags (they preserve formatting, in particular indentation) - (if possible) put opening brackets on the right of the previous line (which most people don't do, I prefer it since it allows for more useful code lines per screen) your code would be a lot simpler if you would use a one-dimensional board[64] array (i.e. concatenating the eight rows) it would avoid a lot of for loops. For attack checking, you would have to convert the linear index into a row/col pair which is simply a divide/modulo 8 operation (two preprocessor macros can come in handy here). :)

      Luc Pattyn [Forum Guidelines] [My Articles]


      this months tips: - use PRE tags to preserve formatting when showing multi-line code snippets - before you ask a question here, search CodeProject, then Google


      1 Reply Last reply
      0
      • R Ramper

        I am currently trying to create a program to find all possibilities for placing 5 queens and 5 knights on an 8x8 board in such a way nothing will attack anything else. There are 16 possible solutions. My problem i am encountering, is when placing queens. It is not generating all possibilities. I believe it is just taking the first instance it finds and going with that rather than examining the rest of the row for possible solutions. Here is what I have, if you could possibly help it would be greatly appreciated. #include #include using namespace std; class QueenKnight { public: QueenKnight() { queens = 0; knight = 0; row = 8; column = 8; count = 0; for(int i= 0; i

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #3

        See here.


        "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

        "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups